Skip to content

Commit

Permalink
chore(vm): sperate ubuntu.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
alomerry committed Jan 29, 2024
1 parent 3af084f commit ec2c7ba
Show file tree
Hide file tree
Showing 18 changed files with 387 additions and 334 deletions.
40 changes: 40 additions & 0 deletions vm/scripts/app/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

_build_mix() {
res=/tmp/res.tar.gz
workspace=/root/workspace/mix
website=/root/apps/nginx/site
for module in $@ ; do
cd $workspace/$module
pnpm install && pnpm build
distPath=""

case "$module" in
blog)
distPath=$workspace/blog/dist/
;;
docs)
distPath=$workspace/docs/.vitepress/dist/
;;
esac

tar -zcvf $res -C $distPath .
scp -r $res [email protected]:/tmp/
ssh [email protected] "rm -rf $website/$module.alomerry.com/*; tar -zxvf $res -C $website/$module.alomerry.com/; rm $res"
done
}

build_docs() {
_build_mix docs
}


build_blog() {
_build_mix blog
}

build() {
for module in $@ ; do
eval "build_$module"
done
}
17 changes: 17 additions & 0 deletions vm/scripts/app/install/acme.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

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

# https://raw.githubusercontent.com/alomerry/mix/master/vm/scripts/acme
wget $INSTALL_PATH/acme.sh -O /tmp/acme.sh
cat /tmp/acme.sh | sh -s -- --install-online
/root/.acme.sh/acme.sh --register-account -m [email protected]
/root/.acme.sh/acme.sh --set-default-ca --server letsencrypt

wget $ACME_PATH/account.conf -O /root/.acme.sh/account.conf
ansible-vault decrypt --vault-id ~/.ansible/.vault /root/.acme.sh/account.conf
}
48 changes: 48 additions & 0 deletions vm/scripts/app/install/frp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

install_frp_server() {
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 -O /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 -P /etc/systemd/system/ $FRP_PATH/frps.service

rm /root/apps/frps/frps.ini
wget -P /root/apps/frps/ $FRP_PATH/frps.ini
ansible-vault decrypt --vault-id ~/.ansible/.vault /root/apps/frps/frps.ini

touch /root/apps/frps/${FRP_VERSION}.version
rm -rf /root/apps/frps/{frps.tar.gz,frpc,frpc_full.ini,frps_full.ini,frpc.ini}

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

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

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

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

rm -rf /root/apps/frpc && mkdir /root/apps/frpc -p
tar -xf /tmp/frp.tar.gz --strip-components 1 -C /root/apps/frpc/
wget -P /etc/systemd/system/ $FRP_PATH/frpc.service

rm /root/apps/frpc/frpc.ini
wget -P /root/apps/frpc/ $FRP_PATH/frpc.ini
wget -P /root/apps/frpc/ $FRP_PATH/frpc_conf.ini
ansible-vault decrypt --vault-id ~/.ansible/.vault /root/apps/frpc/frpc.ini

touch /root/apps/frpc/${FRP_VERSION}.version
systemctl enable frpc.service && systemctl stop frpc.service
systemctl daemon-reload && systemctl start frpc.service

rm -rf /tmp/frp.tar.gz
}
33 changes: 33 additions & 0 deletions vm/scripts/app/install/index.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

_load_install() {
wget $SCRIPTS_PATH/app/install/v2ray.sh -O /tmp/install-v2ray.sh
wget $SCRIPTS_PATH/app/install/nginx.sh -O /tmp/install-nginx.sh
wget $SCRIPTS_PATH/app/install/acme.sh -O /tmp/install-acme.sh
wget $SCRIPTS_PATH/app/install/frp.sh -O /tmp/install-frp.sh
wget $SCRIPTS_PATH/app/install/java.sh -O /tmp/install-java.sh
wget $SCRIPTS_PATH/app/install/rust.sh -O /tmp/install-rust.sh
wget $SCRIPTS_PATH/app/install/nvm.sh -O /tmp/install-nvm.sh
source /tmp/install-v2ray.sh
source /tmp/install-nginx.sh
source /tmp/install-acme.sh
source /tmp/install-frp.sh
source /tmp/install-java.sh
source /tmp/install-rust.sh
source /tmp/install-nvm.sh
}

_install_required() {
if ! command -v ansible > /dev/null 2>&1; then
apt_install ansible
fi
}

install() {
_load_install
_install_required

for module in $@ ; do
eval "install_$module"
done
}
12 changes: 12 additions & 0 deletions vm/scripts/app/install/java.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

install_java() {
# 检验命令是否存在
if ! command -v javac > /dev/null 2>&1; then
apt_install openjdk-${JAVA_VERSION}-jdk-headless
fi

if ! command -v javac > /dev/null 2>&1; then
apt_install openjdk-${JAVA_VERSION}-jre-headless
fi
}
24 changes: 24 additions & 0 deletions vm/scripts/app/install/nginx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

install_nginx() {
if ! command -v nginx > /dev/null 2>&1; then
return;
fi

# https://raw.githubusercontent.com/alomerry/mix/master/vm/scripts/install/nginx.sh
wget $INSTALL_PATH/nginx.sh -O /tmp/nginx.sh
cat /tmp/nginx.sh | sh

mkdir /root/apps/nginx/{site,cert,conf,logs} -p
mkdir /root/apps/nginx/site/{docs,blog,empty}.alomerry.com -p
touch /root/apps/nginx/cert/{privkey,fullchain}.pem

wget -P /etc/systemd/system/ $NGINX_PATH/nginx.service
wget -P /etc/nginx/ $NGINX_PATH/nginx.conf
wget -P /root/apps/nginx/conf/ $NGINX_PATH//website.conf
chmod 644 /etc/nginx/nginx.conf

systemctl daemon-reload
sleep 1
systemctl force-reload nginx
}
33 changes: 33 additions & 0 deletions vm/scripts/app/install/nvm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

install_nvm() {
# TODO
if [ ! -d /root/.nvm ]; then
curl -o- ${GIT_RAW_URL}/nvm-sh/nvm/v${NVM_VERSION}/install.sh | bash
source ~/.bashrc
fi

[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

nvm --version

for module in $@ ; do
case "$module" in
node)
which npm >/dev/null 2>&1
if [ $? -ne 0 ]; then
NVM_NODEJS_ORG_MIRROR=https://npmmirror.com/mirrors/node/ nvm install v${NODE_VERSION}
npm config set registry https://registry.npmmirror.com
nvm use v${NODE_VERSION}
fi
;;
pnpm)
which pnpm >/dev/null 2>&1
if [ $? -ne 0 ]; then
npm install -g pnpm
pnpm config set registry https://registry.npmmirror.com
fi
;;
esac
done
}
15 changes: 15 additions & 0 deletions vm/scripts/app/install/rust.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

install_rust() {
install_java
if command -v cargo > /dev/null 2>&1; then
return;
fi
export RUSTUP_DIST_SERVER="https://rsproxy.cn"
export RUSTUP_UPDATE_ROOT="https://rsproxy.cn/rustup"

curl --proto '=https' --tlsv1.2 -sSf https://rsproxy.cn/rustup-init.sh | sh
# 此处需要回车
source "$HOME/.cargo/env"
# https://rsproxy.cn/#getStarted
}
36 changes: 36 additions & 0 deletions vm/scripts/app/install/v2ray.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

# https://iitii.github.io/2020/02/04/1/
install_v2ray_client() {
if command -v v2ray > /dev/null 2>&1; then
return;
fi

# https://raw.githubusercontent.com/alomerry/mix/master/vm/scripts/install/v2ray.sh
curl -fsSL $V2RAY_PATH/v2ray.sh | bash

mkdir /usr/local/etc/v2ray/ -p
wget -P /usr/local/etc/v2ray/ $V2RAY_PATH/client.json
wget -P /etc/systemd/system $V2RAY_PATH/v2ray.service
mv /usr/local/etc/v2ray/client.json /usr/local/etc/v2ray/config.json
ansible-vault decrypt --vault-id ~/.ansible/.vault /usr/local/etc/v2ray/config.json

systemctl enable v2ray
systemctl start v2ray
}

install_v2ray_server() {
if command -v v2ray > /dev/null 2>&1; then
return;
fi

# https://raw.githubusercontent.com/alomerry/mix/master/vm/scripts/install/v2ray.sh
curl -fsSL $V2RAY_PATH/v2ray.sh | sh

wget -P /usr/local/etc/v2ray/ $V2RAY_PATH/server.json
mv /usr/local/etc/v2ray/server.json /usr/local/etc/v2ray/config.json
ansible-vault decrypt --vault-id ~/.ansible/.vault /usr/local/etc/v2ray/config.json

systemctl enable v2ray
systemctl start v2ray
}
39 changes: 39 additions & 0 deletions vm/scripts/app/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

setup_server() {
setup_basic
}

setup_local() {
setup_basic
}

setup_ssl_issue() {
/root/.acme.sh/acme.sh --issue --dns dns_cf -d alomerry.com -d *.alomerry.com
set_ssl
}

set_ssl_renew() {
/root/.acme.sh/acme.sh --renew -d alomerry.com
set_ssl
}

set_ssl() {
/root/.acme.sh/acme.sh --install-cert -d alomerry.com --key-file /root/apps/nginx/cert/privkey.pem --fullchain-file /root/apps/nginx/cert/fullchain.pem
}

setup_ssh() {
ssh-copy-id [email protected]
ssh-copy-id [email protected]
}

setup_basic() {
echo "y" | apt-get install tree aptitude ca-certificates curl gnupg wget cron lsof;
journalctl --vacuum-time=1d && journalctl --vacuum-size=30M
}

setup() {
for module in $@ ; do
eval "setup_$module"
done
}
15 changes: 15 additions & 0 deletions vm/scripts/app/tools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

# TODO 安装失败如何终止
apt_install() {
echo "y" | apt-get install ${@:1};
}

# case "$1" in
# unlock)
# ansible-vault decrypt --vault-id ~/.ansible/.vault /root/workspace/mix/vm/scripts/frp/frpc.ini
# ;;
# lock)
# ansible-vault encrypt --vault-id ~/.ansible/.vault /root/workspace/mix/vm/scripts/frp/frpc.ini
# ;;
# esac
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions vm/scripts/install/nginx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

main() {
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 "$@"
9 changes: 0 additions & 9 deletions vm/scripts/nginx/install.sh

This file was deleted.

6 changes: 6 additions & 0 deletions vm/scripts/nginx/website.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ server {
rewrite ^(/.*)$ https://$host$1 permanent;
}

add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header Cache-Control private;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';

# ssl_certificate /root/apps/nginx/cert/blog.alomerry.com/certificate.crt;
# ssl_certificate_key /root/apps/nginx/cert/blog.alomerry.com/private.key;
ssl_certificate /root/apps/nginx/cert/fullchain.pem;
Expand Down
Loading

0 comments on commit ec2c7ba

Please sign in to comment.