Older/resources/deploy.sh

115 lines
3.9 KiB
Bash
Raw Normal View History

2024-10-07 13:57:55 +08:00
#!/bin/bash
set -e
2024-10-31 19:40:29 +08:00
SERVER_ADDRESS=172.16.103.87
SERVER_PORT=22
2024-10-07 13:57:55 +08:00
USER=root
function update() {
echo "start update packages"
2024-10-07 21:10:35 +08:00
ssh $USER@$SERVER_ADDRESS -p $SERVER_PORT <<EOF
2024-10-07 13:57:55 +08:00
apt update
apt upgrade -y
EOF
echo "update packages finished."
}
function init() {
echo "start deploy server"
2024-12-01 18:58:58 +08:00
scp -P $SERVER_PORT resources/openresty.service $USER@$SERVER_ADDRESS:/lib/systemd/system/
scp -P $SERVER_PORT resources/frps.service $USER@$SERVER_ADDRESS:/etc/systemd/system/
scp -P $SERVER_PORT resources/freedom.service $USER@$SERVER_ADDRESS:/etc/systemd/system/
2024-10-07 13:57:55 +08:00
2024-10-07 21:10:35 +08:00
ssh $USER@$SERVER_ADDRESS -p $SERVER_PORT <<EOF
2024-12-01 18:58:58 +08:00
apt install unzip
2024-10-31 19:40:29 +08:00
if [ ! -d /root/Server ]; then
mkdir -p /root/Server /root/Server/logs
fi
2024-10-07 13:57:55 +08:00
if command -v openresty > /dev/null 2>&1; then
echo "OpenResty has installed."
else
apt -y install --no-install-recommends wget gnupg ca-certificates lsb-release
wget -O - https://openresty.org/package/pubkey.gpg | gpg --dearmor -o /usr/share/keyrings/openresty.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/openresty.gpg] http://openresty.org/package/ubuntu $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/openresty.list > /dev/null
apt update
apt -y install openresty
fi
2024-12-01 18:58:58 +08:00
if [ -f /root/Server/frp_0.61.0_linux_amd64/frps ]; then
2024-10-07 21:10:35 +08:00
echo "frps has installed."
else
pushd /root/Server
2024-12-15 21:14:57 +08:00
wget https://github.com/fatedier/frp/releases/download/v0.61.0/frp_0.61.0_linux_amd64.tar.gz
2024-12-01 18:58:58 +08:00
tar xvf ./frp_0.61.0_linux_amd64.tar.gz
rm frp_0.61.0_linux_amd64.tar.gz
popd
fi
if [ -f freedom_5.22.0_linux_amd64/freedom ]; then
echo "v2ray has installed."
else
pushd /root/Server
2024-12-15 21:14:57 +08:00
wget https://github.com/v2fly/v2ray-core/releases/download/v5.22.0/v2ray-linux-64.zip -O freedom_v5.22.0_linux_amd64.zip
2024-12-01 18:58:58 +08:00
unzip freedom_v5.22.0_linux_amd64.zip -d freedom_v5.22.0_linux_amd64
mv freedom_v5.22.0_linux_amd64/v2ray freedom_v5.22.0_linux_amd64/freedom
rm freedom_v5.22.0_linux_amd64.zip
2024-10-07 21:10:35 +08:00
popd
2024-10-07 13:57:55 +08:00
fi
if command -v docker &> /dev/null; then
echo "docker has installed."
else
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
chmod a+r /etc/apt/keyrings/docker.asc
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
tee /etc/apt/sources.list.d/docker.list > /dev/null
2024-12-01 18:58:58 +08:00
apt update
apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
fi
if [ "$(docker ps -q -f name=twikoo)" ]; then
echo "twikoo has running."
else
pushd /root/Server
docker run --name twikoo --restart=always -e TWIKOO_THROTTLE=1000 -p 8083:8080 -v /root/Server/twikoo:/app/data -d imaegoo/twikoo
popd
2024-10-07 13:57:55 +08:00
fi
2024-10-07 21:10:35 +08:00
if [ "$(docker ps -q -f name=librespeed)" ]; then
echo "librespeed has running."
else
pushd /root/Server
2024-12-01 18:58:58 +08:00
docker run -d --restart=unless-stopped --name=librespeed -e PASSWORD=88888888 -p 8087:80 \
-v /root/Server/librespeed:/config --restart unless-stopped lscr.io/linuxserver/librespeed:latest
2024-10-07 21:10:35 +08:00
popd
fi
2024-10-07 13:57:55 +08:00
EOF
echo "update packages finished."
}
function main() {
local cmd=$1
shift 1
case $cmd in
update)
update
;;
init)
init
;;
*)
build
;;
esac
}
main $@