Skip to content

Commit

Permalink
chore: refine scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
alomerry committed Apr 25, 2024
1 parent 8bb028b commit a8bd164
Show file tree
Hide file tree
Showing 31 changed files with 198 additions and 181 deletions.
26 changes: 26 additions & 0 deletions vm/scripts/app/acme/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

GITHUB_TOKEN=${GITHUB_TOKEN}

load_SK() {
# 将 curl 返回值 return 到变量中
res=$(curl "${SECRET_PATH}/$1" -H "Authorization: token ${GITHUB_TOKEN}" -H 'Accept: application/vnd.github.v3.raw')
echo "$res"
}

main() {
if command -v acme.sh; then
/root/.acme.sh/acme.sh --upgrade
return
fi

wget -qO - https://get.acme.sh | sh -s [email protected]
/root/.acme.sh/acme.sh --register-account -m [email protected]
/root/.acme.sh/acme.sh --set-default-ca --server letsencrypt

serverCfg=$(load_SK "vm/vps/acme/account.conf")
echo "$serverCfg"
echo "$serverCfg" > /root/.acme.sh/account.conf
}

main "$@"
File renamed without changes.
File renamed without changes.
File renamed without changes.
34 changes: 34 additions & 0 deletions vm/scripts/app/frp/frp-server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

FRP_VERSION=${FRP_VERSION:-"0.54.0"}

load_SK() {
res=$(curl "${SECRET_PATH}/$1" -H "Authorization: token ${GITHUB_TOKEN}" -H 'Accept: application/vnd.github.v3.raw')
echo "$res"
}

main() {
if [ -f /root/apps/frps/${FRP_VERSION}.version ]; then
return
fi

wget https://github.com/fatedier/frp/releases/download/v${FRP_VERSION}/frp_${FRP_VERSION}_linux_amd64.tar.gz -qO /tmp/frp.tar.gz

rm -rf /root/apps/frps && mkdir /root/apps/frps -p
tar -xf /tmp/frp.tar.gz --strip-components 1 -C /root/apps/frps/

wget $FRP_PATH/cfg/frps.service -qO /etc/systemd/system/frps.service

touch /root/apps/frps/${FRP_VERSION}.version
rm /root/apps/frps/*.toml /root/apps/frps/{LICENSE,frpc}

serverCfg=$(load_SK "vm/vps/frps/frps.toml")
echo "$serverCfg" > /root/apps/frps/frps.toml

systemctl enable frps.service && systemctl stop frps.service
systemctl daemon-reload && systemctl start frps.service

rm -rf /tmp/frp.tar.gz
}

main "$@"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions vm/scripts/app/nginx/aio.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

# 安装 nginx
curl ${NGINX_PATH}/install.sh | bash
# 初始化 nginx
curl ${NGINX_PATH}/init.sh | bash
# 配置 nginx
curl ${NGINX_PATH}/setup.sh | bash
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions vm/scripts/app/nginx/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

if [ ! -d /root/apps/nginx ]; then
mkdir /root/apps/nginx/{site,cert,conf,logs} -p
mkdir /root/apps/nginx/site/{admin,blog,ref,empty,it-tools}.alomerry.com -p
touch /root/apps/nginx/cert/{privkey,fullchain}.pem
fi
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#!/bin/bash

main() {
if ! command -v nginx > /dev/null 2>&1; then
echo "y" | apt-get install socat curl gnupg2 ca-certificates lsb-release ubuntu-keyring;

curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor | tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
gpg --dry-run --quiet --no-keyring --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/ubuntu $(lsb_release -cs) nginx" | tee /etc/apt/sources.list.d/nginx.list
echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" | tee /etc/apt/preferences.d/99nginx
apt update && apt install nginx -y
}

main "$@"
fi
23 changes: 23 additions & 0 deletions vm/scripts/app/nginx/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash


if [ ! -f /etc/systemd/system/nginx.service ]; then
wget ${NGINX_PATH}/cfg/nginx.service -qO /etc/systemd/system/nginx.service
systemctl enable nginx
fi

if [ ! -f /etc/nginx/nginx.conf ]; then
wget ${NGINX_PATH}/cfg/nginx.conf -qO /etc/nginx/nginx.conf
fi

if [ ! -f /root/apps/nginx/conf/website.conf ]; then
wget ${NGINX_PATH}/cfg/website.conf -qO /root/apps/nginx/conf/website.conf
fi

chmod 644 /etc/nginx/nginx.conf

systemctl daemon-reload
sleep 1
systemctl stop nginx
sleep 1
systemctl start nginx
File renamed without changes.
31 changes: 31 additions & 0 deletions vm/scripts/app/v2ray/install-server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

GITHUB_TOKEN=${GITHUB_TOKEN}

# 根据传入配置地址返回内容,例如 vm/vps/v2ray/server.json
load_SK() {
# 将 curl 返回值 return 到变量中
res=$(curl "${SECRET_PATH}/$1" -H "Authorization: token ${GITHUB_TOKEN}" -H 'Accept: application/vnd.github.v3.raw')
echo "$res"
}

main() {
# 检查是否有 v2ray server 配置
if [ ! -f /usr/local/etc/v2ray/server.json ]; then
# 下载配置文件
serverCfg=$(load_SK "vm/vps/v2ray/server.json")
echo "$serverCfg" > /usr/local/etc/v2ray/server.json
fi

if ! command -v v2ray > /dev/null 2>&1; then
curl ${GIT_RAW_URL}/v2fly/fhs-install-v2ray/master/install-release.sh | bash
mv /usr/local/etc/v2ray/server.json /usr/local/etc/v2ray/config.json
systemctl enable v2ray
fi

systemctl stop v2ray
sleep 1
systemctl start v2ray
}

main "$@"
File renamed without changes.
28 changes: 0 additions & 28 deletions vm/scripts/cfg/acme/acme.sh

This file was deleted.

24 changes: 0 additions & 24 deletions vm/scripts/cfg/nginx/nginx.sh

This file was deleted.

29 changes: 0 additions & 29 deletions vm/scripts/cfg/v2ray/v2ray.sh

This file was deleted.

96 changes: 0 additions & 96 deletions vm/scripts/run.sh

This file was deleted.

17 changes: 17 additions & 0 deletions vm/scripts/tools/env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# export http_proxy=127.0.0.1:7890 https_proxy=127.0.0.1:7890
# unset http_proxy https_proxy

PROXY=127.0.0.1:7890

# https://raw.githubusercontent.com/alomerry/mix/master/vm/scripts
export GIT_RAW_URL=https://raw.githubusercontent.com; \
export BRANCH=master; \
export MIX_REPOSITORY=alomerry/mix; \
export MIX_VM_VPS_STATIC=vm/scripts/app; \
export SCRIPTS_PATH=${GIT_RAW_URL}/${MIX_REPOSITORY}/${BRANCH}/${MIX_VM_VPS_STATIC}; \
export NGINX_PATH=${GIT_RAW_URL}/${MIX_REPOSITORY}/${BRANCH}/${MIX_VM_VPS_STATIC}/nginx; \
export V2RAY_PATH=${GIT_RAW_URL}/${MIX_REPOSITORY}/${BRANCH}/${MIX_VM_VPS_STATIC}/v2ray; \
export ACME_PATH=${GIT_RAW_URL}/${MIX_REPOSITORY}/${BRANCH}/${MIX_VM_VPS_STATIC}/acme; \
export FRP_PATH=${GIT_RAW_URL}/${MIX_REPOSITORY}/${BRANCH}/${MIX_VM_VPS_STATIC}/frp; \
export SECRET_PATH=${GIT_RAW_URL}/alomerry/secrets/master; \
export JAVA_VERSION=${JAVA_VERSION:-"8"};
Loading

0 comments on commit a8bd164

Please sign in to comment.