sh OSMC日本语化スクリプト

OSMC日本语化スクリプト

osmc-jp-font-replace.sh
#!/bin/sh
 
URL="https://gist.github.com/mzyy94/15ee1b3880107e9d7ece/download"
TMP="/tmp/mplusfonts"
FONTSDIR="/usr/share/kodi/addons/skin.osmc/fonts/"
FONTCONF="/usr/share/kodi/addons/skin.osmc/16x9/Font.xml"
 
set -x
 
mkdir -p ${TMP}
wget ${URL} -O - | tar -zxvC ${TMP}
find ${TMP} -name "*.tar.gz" -exec tar -zxvf {} -C ${TMP} \;
find ${TMP} -name "mplus-1[cp]-*.ttf" -exec cp {} ${FONTSDIR} \;
sed -i.bak -e 's/NotoSans/mplus-1c/' -e 's/OpenSans/mplus-1p/' -e 's/Roboto/mplus-1c/' -e 's/-\([A-Z]\)/-\L\1/' ${FONTCONF}
rm -rf ${TMP}

sh 流浪者 - MISP

流浪者 - MISP

MISP.sh
# Create an Admin User
sudo adduser admin
# Pull the latest updates
sudo apt update && sudo apt dist-upgrade -y

# install postfix, there will be some questions.
sudo apt install -y postfix
# Postfix Configuration: Satellite system
# change the relay server later with:
#sudo postconf -e 'relayhost = example.com'
#sudo postfix reload

# 1st round of dependencies...
sudo apt-get install curl gcc git gnupg-agent make python openssl redis-server sudo vim zip

# MariaDB of course..
sudo apt-get install mariadb-client mariadb-server

# Secure the MariaDB installation (especially by setting a strong root password)
sudo mysql_secure_installation

# Install Apache2
sudo apt install -y apache2 apache2-doc apache2-utils

# Enable modules, settings, and default of SSL in Apache
sudo a2dismod status \
sudo a2enmod ssl \
sudo a2enmod rewrite \
sudo a2dissite 000-default \
sudo a2ensite default-ssl \

# Install PHP and dependencies
apt install -y libapache2-mod-php php php-cli php-crypt-gpg php-dev php-json php-mysql php-opcache php-readline php-redis

# Apply all changes
sudo systemctl restart apache2

sh 在Debian上安装zRAM(8)

在Debian上安装zRAM(8)

debian-install-zram.sh
#!/bin/bash
#

not_root() {
    echo "ERROR: You have to be root to execute this script"
    exit 1
}

zram_exists() {
    echo "ERROR: /etc/init.d/zram already exists"
    exit 1
}

# Check if user is root
[ $EUID != 0 ] && not_root

# Check if zram file already exists
[ -f /etc/init.d/zram ] && zram_exists



cat >/etc/init.d/zram <<EOL
#!/bin/sh
### BEGIN INIT INFO
# Provides:          zram
# Required-Start:    $local_fs
# Required-Stop:     $local_fs
# Default-Start:     S
# Default-Stop:      0 1 6
# Short-Description: Use compressed RAM as in-memory swap
# Description:       Use compressed RAM as in-memory swap
### END INIT INFO

# Author: Antonio Galea <antonio.galea@gmail.com>
# Thanks to Przemysław Tomczyk for suggesting swapoff parallelization

FRACTION=75

MEMORY=\`perl -ne'/^MemTotal:\s+(\d+)/ && print \$1*1024;' < /proc/meminfo\`
CPUS=\`grep -c processor /proc/cpuinfo\`
SIZE=\$(( MEMORY * FRACTION / 100 / CPUS ))

case "\$1" in
  "start")
    param=\`modinfo zram|grep num_devices|cut -f2 -d:|tr -d ' '\`
    modprobe zram \$param=\$CPUS
    for n in \`seq \$CPUS\`; do
      i=\$((n - 1))
      echo \$SIZE > /sys/block/zram\$i/disksize
      mkswap /dev/zram\$i
      swapon /dev/zram\$i -p 10
    done
    ;;
  "stop")
    for n in \`seq \$CPUS\`; do
      i=$((n - 1))
      swapoff /dev/zram\$i && echo "disabled disk \$n of \$CPUS" &
    done
    wait
    sleep .5
    modprobe -r zram
    ;;
  *)
    echo "Usage: \`basename \$0\` (start | stop)"
    exit 1
    ;;
esac
EOL

chmod +x /etc/init.d/zram

insserv zram

/etc/init.d/zram start

exit 0

sh 转换git repo以使用git lfs

转换git repo以使用git lfs

convert_repo_to_lfs_bfg.sh
#!/bin/bash

# May not always work. In that case use convert_repo_to_lfs
bfg --convert-to-git-lfs '*.fla' --no-blob-protection
convert_repo_to_lfs.sh
#!/bin/bash

# Try convert_repo_to_lfs_bfg.sh first
git filter-branch --prune-empty --tree-filter '
git lfs track "*.fla"
git lfs track "*.mov"

git add .gitattributes

git ls-files -z | xargs -0 git check-attr filter | grep "filter: lfs" | sed -E "s/(.*): filter: lfs/\1/" | tr "\n" "\0" | while read -r -d $'"'\0'"' file; do
    echo "Processing ${file}"

    git rm -f --cached "${file}"
    echo "Adding $file lfs style"
    git add -f "${file}"
done

' --tag-name-filter cat -- --all

sh 永久删除Git仓库中的文件和文件夹

永久删除Git仓库中的文件和文件夹

git-rm-repo.sh
git filter-branch -f --tree-filter 'rm -rf DIR' HEAD

sh docker3k.sh

update-sysctl.sh
#!/bin/bash
echo "net.ipv4.neigh.default.gc_thresh1 = 30000" >> /etc/sysctl.conf
echo "net.ipv4.neigh.default.gc_thresh2 = 32000" >> /etc/sysctl.conf
echo "net.ipv4.neigh.default.gc_thresh3 = 32768" >> /etc/sysctl.conf
sysctl -p
run-config.sh
#!/bin/bash
cat init_config | curl -XPOST --unix-socket /var/run/docker.sock -H "Content-Type: application/json" -d @- http:/swarm/init
docker3k.sh
#!/bin/bash
tee /root/init_config <<EOF
{
  "ListenAddr": "0.0.0.0:2377",
  "AdvertiseAddr": "$1:2377",
  "ForceNewCluster": true,
  "Spec": {
    "Orchestration": {},
    "Raft": { "KeepOldSnapshots": 1000000 },
    "Dispatcher": {},
    "CAConfig": {}
  }
}
EOF

sh 使用用户数据(自动运行脚本)在启动时设置Java 8(最新)EC2服务器

使用用户数据(自动运行脚本)在启动时设置Java 8(最新)EC2服务器

userdata_ec2.sh
#!/bin/bash
sudo yum -y update
sudo yum -y upgrade
sed -i s/enabled=0/enabled=1/g /etc/yum.repos.d/epel.repo
sudo yum -y install htop
sudo yum -y install java-1.8.0
sudo yum -y remove java-1.7.0-openjdk
sudo curl -s "https://get.sdkman.io" | bash

sh dkms linux内核模块在ubuntu上重新编译

dkms linux内核模块在ubuntu上重新编译

ubuntu_recompile_modules.sh
ls /var/lib/initramfs-tools |     sudo xargs -n1 /usr/lib/dkms/dkms_autoinstaller start

sh 根据活动的virtualenv,git branch和last命令的返回状态设置颜色bash提示符。

根据活动的virtualenv,git branch和last命令的返回状态设置颜色bash提示符。

bash_prompt.sh
#!/bin/bash
#
# DESCRIPTION:
#
#   Set the bash prompt according to:
#    * the active virtualenv
#    * the branch/status of the current git repository
#    * the return value of the previous command
#    * the fact you just came from Windows and are used to having newlines in
#      your prompts.
#
# USAGE:
#
#   1. Save this file as ~/.bash_prompt
#   2. Add the following line to the end of your ~/.bashrc or ~/.bash_profile:
#        . ~/.bash_prompt
#
# LINEAGE:
#
#   Based on work by woods
#
#   https://gist.github.com/31967

# The various escape codes that we can use to color our prompt.
        RED="\[\033[0;31m\]"
     YELLOW="\[\033[1;33m\]"
      GREEN="\[\033[0;32m\]"
       BLUE="\[\033[1;34m\]"
  LIGHT_RED="\[\033[1;31m\]"
LIGHT_GREEN="\[\033[1;32m\]"
      WHITE="\[\033[1;37m\]"
 LIGHT_GRAY="\[\033[0;37m\]"
 COLOR_NONE="\[\e[0m\]"

# Detect whether the current directory is a git repository.
function is_git_repository {
  git branch > /dev/null 2>&1
}

# Determine the branch/state information for this git repository.
function set_git_branch {
  # Capture the output of the "git status" command.
  git_status="$(git status 2> /dev/null)"

  # Set color based on clean/staged/dirty.
  if [[ ${git_status} =~ "working directory clean" ]]; then
    state="${GREEN}"
  elif [[ ${git_status} =~ "Changes to be committed" ]]; then
    state="${YELLOW}"
  else
    state="${LIGHT_RED}"
  fi

  # Set arrow icon based on status against remote.
  remote_pattern="# Your branch is (.*) of"
  if [[ ${git_status} =~ ${remote_pattern} ]]; then
    if [[ ${BASH_REMATCH[1]} == "ahead" ]]; then
      remote="↑"
    else
      remote="↓"
    fi
  else
    remote=""
  fi
  diverge_pattern="# Your branch and (.*) have diverged"
  if [[ ${git_status} =~ ${diverge_pattern} ]]; then
    remote="↕"
  fi

  # Get the name of the branch.
  branch_pattern="^# On branch ([^${IFS}]*)"
  if [[ ${git_status} =~ ${branch_pattern} ]]; then
    branch=${BASH_REMATCH[1]}
  fi

  # Set the final branch string.
  BRANCH="${state}(${branch})${remote}${COLOR_NONE} "
}

# Return the prompt symbol to use, colorized based on the return value of the
# previous command.
function set_prompt_symbol () {
  if test $1 -eq 0 ; then
      PROMPT_SYMBOL="\$"
  else
      PROMPT_SYMBOL="${LIGHT_RED}\$${COLOR_NONE}"
  fi
}

# Determine active Python virtualenv details.
function set_virtualenv () {
  if test -z "$VIRTUAL_ENV" ; then
      PYTHON_VIRTUALENV=""
  else
      PYTHON_VIRTUALENV="${BLUE}[`basename \"$VIRTUAL_ENV\"`]${COLOR_NONE} "
  fi
}

# Set the full bash prompt.
function set_bash_prompt () {
  # Set the PROMPT_SYMBOL variable. We do this first so we don't lose the
  # return value of the last command.
  set_prompt_symbol $?

  # Set the PYTHON_VIRTUALENV variable.
  set_virtualenv

  # Set the BRANCH variable.
  if is_git_repository ; then
    set_git_branch
  else
    BRANCH=''
  fi

  # Set the bash prompt variable.
  PS1="
${PYTHON_VIRTUALENV}${GREEN}\u@\h ${YELLOW}\w${COLOR_NONE} ${BRANCH}
${PROMPT_SYMBOL} "
}

# Tell bash to execute this function just before displaying its prompt.
PROMPT_COMMAND=set_bash_prompt

sh Docker助手脚本

Docker助手脚本

docker-cleanup.sh
#!/bin/bash

# Delete all stopped containers
docker rm $( docker ps -q -f status=exited)
# Delete all dangling (unused) images
docker rmi $( docker images -q -f dangling=true)
docker-cleanup-full.sh
!/bin/bash

#Delete all containers
docker rm $(docker ps -a -q)

#Delete all images
docker rmi $(docker images -q)