From 524427bc687c4352b31be9668e2292a7952c0afc Mon Sep 17 00:00:00 2001 From: Alomerry Wu Date: Thu, 1 Feb 2024 22:19:44 +0800 Subject: [PATCH] chore: add usage for script --- vm/scripts/app/build.sh | 11 +++++++ vm/scripts/app/install/index.sh | 11 +++++++ vm/scripts/app/setup.sh | 11 +++++++ vm/scripts/run.sh | 58 +++++++++++++++++++++++++++------ 4 files changed, 81 insertions(+), 10 deletions(-) diff --git a/vm/scripts/app/build.sh b/vm/scripts/app/build.sh index 418ad2e0..babf0e8c 100644 --- a/vm/scripts/app/build.sh +++ b/vm/scripts/app/build.sh @@ -38,3 +38,14 @@ build() { eval "build_$module" done } + +build_usage() { + command=(blog docs) + desc=(博客 文档) + echo "usage: alomerry.sh build 本地构建" + echo -e "\nOptions:" + for idx in 0 1; do + printf " - %-20s %-20s\n" ${command[$idx]} ${desc[$idx]} + done + exit 1 +} diff --git a/vm/scripts/app/install/index.sh b/vm/scripts/app/install/index.sh index 27469a11..565298b4 100644 --- a/vm/scripts/app/install/index.sh +++ b/vm/scripts/app/install/index.sh @@ -37,3 +37,14 @@ install() { eval "install_$module" done } + +install_usage() { + command=(acme frp_server frp_client java nginx nvm rust v2ray_server v2ray_client) + desc=(acme frp_server frp_client java nginx nvm rust v2ray_server v2ray_client) + echo "usage: alomerry.sh install 安装软件" + echo -e "\nOptions:" + for idx in 0 1 2 3 4 5 6 7 8; do + printf " - %-20s %-20s\n" ${command[$idx]} ${desc[$idx]} + done + exit 1 +} \ No newline at end of file diff --git a/vm/scripts/app/setup.sh b/vm/scripts/app/setup.sh index 6884af4c..aee5ea92 100644 --- a/vm/scripts/app/setup.sh +++ b/vm/scripts/app/setup.sh @@ -36,4 +36,15 @@ setup() { for module in $@ ; do eval "setup_$module" done +} + +setup_usage() { + command=(server local ssh ssl_issue ssl_renew) + desc=(设置服务器 设置家庭 将本地ssh-key添加到服务器 初始化https证书 续签https证书) + echo "usage: alomerry.sh setup 设置系统" + echo -e "\nOptions:" + for idx in 0 1 2 3 4; do + printf " - %-20s %-20s\n" ${command[$idx]} ${desc[$idx]} + done + exit 1 } \ No newline at end of file diff --git a/vm/scripts/run.sh b/vm/scripts/run.sh index ccea47d8..cdfd3be7 100755 --- a/vm/scripts/run.sh +++ b/vm/scripts/run.sh @@ -26,10 +26,18 @@ JAVA_VERSION=${JAVA_VERSION:-"8"} boot() { # https://raw.githubusercontent.com/alomerry/mix/master/vm/scripts/app/tools.sh - wget $SCRIPTS_PATH/app/tools.sh -O /tmp/tools.sh - wget $SCRIPTS_PATH/app/setup.sh -O /tmp/setup.sh - wget $SCRIPTS_PATH/app/build.sh -O /tmp/build.sh - wget $SCRIPTS_PATH/app/install/index.sh -O /tmp/install.sh + if [ ! -f /tmp/tools.sh ]; then + wget $SCRIPTS_PATH/app/tools.sh -O /tmp/tools.sh + fi + if [ ! -f /tmp/setup.sh ]; then + wget $SCRIPTS_PATH/app/setup.sh -O /tmp/setup.sh + fi + if [ ! -f /tmp/build.sh ]; then + wget $SCRIPTS_PATH/app/build.sh -O /tmp/build.sh + fi + if [ ! -f /tmp/install.sh ]; then + wget $SCRIPTS_PATH/app/install/index.sh -O /tmp/install.sh + fi # https://blog.csdn.net/Renard_H/article/details/121458554 source /tmp/tools.sh source /tmp/install.sh @@ -37,19 +45,52 @@ boot() { source /tmp/setup.sh } +usage() { + case "$1" in + setup) + setup_usage ${@:1} + ;; + build) + build_usage ${@:1} + ;; + install) + install_usage ${@:1} + ;; + *) + echo "usage: alomerry.sh" + echo -e "\nOptions:" + echo " - setup" + echo " - build" + echo " - install" + exit 1 + ;; + esac +} + main() { + args=$# boot + # TODO 单独先处理一遍参数 + if [ ${!args} == -h ]; then + usage ${@:1:`expr ${args} - 1`} + return + fi + # ATTENTION: 安装 ansible 以使用 ansible-vault 解密 case "$1" in - setup) # server local ssh ssl ssl_{issue,renew} + setup) setup ${@:2} ;; - build) # blog,docs + build) build ${@:2} ;; - install) # acme rust nginx java frp_{server,client} v2ray_{server,client} nvm + install) install ${@:2} ;; + update) + rm -rf /tmp/tools.sh /tmp/setup.sh /tmp/build.sh /tmp/install.sh + boot + ;; *) echo "Done!" ;; @@ -57,6 +98,3 @@ main() { } main $@ - -# run.sh setup server -# run.sh install frp_client \ No newline at end of file