大更新

不直接使用变量,方便后续变量位置改变;
解决中途退出问题
不使用 ~用户名 获取家目录,只能识别为字符串
main
AhFei 2023-01-14 01:04:04 +08:00
parent e625fc7334
commit 546a7ae11a
1 changed files with 16 additions and 11 deletions

View File

@ -4,8 +4,10 @@
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
# step 0: prepare
nml_user_name=${1}
nml_user_home=${2}
ss_user_name=${3}
github_project="docker/compose"
tag=$(wget -qO- -t1 -T2 "https://api.github.com/repos/${github_project}/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g')
@ -17,6 +19,7 @@ echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf #修改系统
sysctl -p #保存生效
sysctl net.ipv4.tcp_available_congestion_control #执行
apt update
apt -y install sudo wget curl ufw screen vim git python3-pip
curl -fsSL https://get.docker.com | bash -s docker >${PWD}/step1 2>&1
curl -L https://github.com/docker/compose/releases/download/${tag}/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose && chmod +x /usr/local/bin/docker-compose
@ -24,12 +27,12 @@ echo "step 1: install has finished"
# step 2: localize
useradd -d /home/skf -m ${1}
usermod -s /bin/bash ${1}
usermod -aG sudo ${1} # 有些发行版 RN 的就没有sudo adm
usermod -aG adm ${1}
usermod -aG docker ${1} && newgrp docker
echo `groups ${1}`
useradd -d /home/skf -m ${nml_user_name}
usermod -s /bin/bash ${nml_user_name}
usermod -aG sudo ${nml_user_name} # 有些发行版 RN 的就没有sudo adm
usermod -aG adm ${nml_user_name}
usermod -aG docker ${nml_user_name}
echo `groups ${nml_user_name}`
timedatectl set-timezone Asia/Shanghai
echo `date`
@ -38,12 +41,14 @@ echo "step 2: localize has finished"
# step 3: monitor
mkdir -p ~${1}/myserve/serverstatus && wget --no-check-certificate -qO ~${1}/myserve/serverstatus/client-linux.py 'https://raw.githubusercontent.com/cppla/ServerStatus/master/clients/client-linux.py'
chown -R ${1}:${1} ~${1}/myserve
mkdir -p /home/${nml_user_home}/myserve/serverstatus && wget --no-check-certificate -qO /home/${nml_user_home}/myserve/serverstatus/client-linux.py 'https://raw.githubusercontent.com/cppla/ServerStatus/master/clients/client-linux.py'
chown -R ${nml_user_name}:${nml_user_name} /home/${nml_user_home}/myserve
nohup python3 ~${1}/myserve/serverstatus/client-linux.py SERVER=serverstatus.ahfei.blog USER=ahfei-${2} PASSWORD=A23456.. >/dev/null 2>&1 &
nohup python3 /home/${nml_user_home}/myserve/serverstatus/client-linux.py SERVER=serverstatus.ahfei.blog USER=ahfei-${ss_user_name} PASSWORD=A23456.. >/dev/null 2>&1 &
echo "@reboot python3 ~${1}/myserve/serverstatus/client-linux.py SERVER=serverstatus.ahfei.blog USER=ahfei-${2} PASSWORD=A23456.. >/dev/null 2>&1" >> /var/spool/cron/crontabs/${1}
echo "@reboot python3 /home/${nml_user_home}/myserve/serverstatus/client-linux.py SERVER=serverstatus.ahfei.blog USER=ahfei-${ss_user_name} PASSWORD=A23456.. >/dev/null 2>&1" >> /var/spool/cron/crontabs/${nml_user_name}
chown -R ${nml_user_name}:${nml_user_name} /var/spool/cron/crontabs/${nml_user_name}
chmod 600 /var/spool/cron/crontabs/${nml_user_name}
echo "step 3: monitor has finished"