diff --git a/Config/Docker/Installs/gitea.sh b/Config/Docker/Installs/gitea.sh index dc709b5..eed2f74 100644 --- a/Config/Docker/Installs/gitea.sh +++ b/Config/Docker/Installs/gitea.sh @@ -1,18 +1,16 @@ #!/bin/bash -if ! command -v sudo &> /dev/null; then - echo "该软件需要安装sudo才能正常安装" - exit -fi - declare install_path=$1 declare service_port=$2 -sudo useradd -m git -sudo -u git ssh-keygen -t rsa -b 4096 -C "Gitea Host Key" -f /home/git/.ssh/id_rsa -N "" -sudo -u git sh -c 'cat /home/git/.ssh/id_rsa.pub >> /home/git/.ssh/authorized_keys' -sudo -u git sh -c 'chmod a+x /usr/local/bin/gitea' -sudo -u git sh -c 'echo "ssh -p '$(( service_port+22 ))' -o StrictHostKeyChecking=no git@127.0.0.1 \"SSH_ORIGINAL_COMMAND=\\\"\$SSH_ORIGINAL_COMMAND\\\" \$0 \$@\"" > /usr/local/bin/gitea' +useradd -m git + +su - git -c "ssh-keygen -t rsa -b 4096 -C \"Gitea Host Key\" -f /home/git/.ssh/id_rsa -N \"\"" +su - git -c "cat /home/git/.ssh/id_rsa.pub >> /home/git/.ssh/authorized_keys" +echo "ssh -p $(( service_port+22 )) -o StrictHostKeyChecking=no git@127.0.0.1 \"SSH_ORIGINAL_COMMAND=\\\"\$SSH_ORIGINAL_COMMAND\\\" \$0 \$@\"" > /usr/local/bin/gitea +chown git:git /usr/local/bin/gitea +su - git -c "chmod a+x /usr/local/bin/gitea" + declare user_id=$( id git | awk -F'[=() ]+' '{print $2}' ) declare group_id=$( id git | awk -F'[=() ]+' '{print $5}' ) @@ -60,5 +58,4 @@ services: - ./mysql:/var/lib/mysql EOF chown -R git:git $install_path -sudo docker compose up -d - +docker compose up -d \ No newline at end of file diff --git a/Config/Docker/Installs/menu.sh b/Config/Docker/Installs/menu.sh index 9184d90..2200a1c 100644 --- a/Config/Docker/Installs/menu.sh +++ b/Config/Docker/Installs/menu.sh @@ -5,53 +5,55 @@ declare selected_file_name echo "========$(basename $0 .sh)========" declare file_count=0 declare -a file_array -for file in "${local_directory}"/*;do - selected_file_name=$(awk -F '.' '{print $1}' <<< "$(basename $file)") - if [[ $selected_file_name == "test" || $selected_file_name == "menu" ]]; then - continue - fi - file_count=$((file_count + 1)) - file_array[$file_count]=$selected_file_name - echo "${file_count}.${selected_file_name}" +for file in "${local_directory}"/*; do + selected_file_name=$(awk -F '.' '{print $1}' <<<"$(basename $file)") + if [[ $selected_file_name == "test" || $selected_file_name == "menu" ]]; then + continue + fi + file_count=$((file_count + 1)) + file_array[$file_count]=$selected_file_name + echo "${file_count}.${selected_file_name}" done echo "输入其他字符返回主页" read -p "请输入:" user_choice -if [[ ! ${user_choice} =~ [1-$file_count] ]];then +if [[ ! "$user_choice" =~ ^[0-9]+$ ]] || [ "$user_choice" -lt 1 ] || [ "$user_choice" -gt "$file_count" ]; then exit fi declare storage_path -read -p "请输入软件存储位置,默认 /var/www/${file_array[${user_choice}]} :" storage_path -if [[ -z ${storage_path} ]];then +read -p "请输入软件存储位置,默认 /var/www/${file_array[${user_choice}]} :" storage_path +if [[ -z ${storage_path} ]]; then storage_path="/var/www/${file_array[${user_choice}]}" fi -if [[ ! -d "$storage_path" ]];then - sudo mkdir -p "$storage_path" || { echo "目录创建失败"; exit 1; } -elif [[ ! -z "$(find "$storage_path" -mindepth 1 -print -quit)" ]];then - echo "该目录存有文件" - exit +if [[ ! -d "$storage_path" ]]; then + mkdir -p "$storage_path" || { + echo "目录创建失败" + exit 1 + } +elif [[ ! -z "$(find "$storage_path" -mindepth 1 -print -quit)" ]]; then + echo "该目录存有文件" + exit fi declare random_port=$(($RANDOM % 9000 + 1000)) -while ss -tuln | grep $random_port &> /dev/null -do - random_port=$(($RANDOM % 9000 + 1000)) +while ss -tuln | grep $random_port &>/dev/null; do + random_port=$(($RANDOM % 9000 + 1000)) done declare access_port -read -p "请输入访问端口,默认 $random_port :" access_port +read -p "请输入访问端口,默认 $random_port :" access_port -if [[ -z $access_port ]];then +if [[ -z $access_port ]]; then access_port=$random_port fi -if ss -tuln | grep $access_port &> /dev/null;then +if ss -tuln | grep $access_port &>/dev/null; then echo "端口已被占用" exit fi bash "${local_directory}/${file_array[user_choice]}.sh" "$storage_path" "$access_port" -echo "${file_array[${user_choice}]} 安装完成,访问端口 ${access_port}" \ No newline at end of file +echo "${file_array[${user_choice}]} 安装完成,访问端口 ${access_port}" diff --git a/Config/Docker/Installs/typecho.sh b/Config/Docker/Installs/typecho.sh index a67e2fc..bc5ebc7 100644 --- a/Config/Docker/Installs/typecho.sh +++ b/Config/Docker/Installs/typecho.sh @@ -108,11 +108,11 @@ rm typecho.zip cd $installation_directory -sudo chown -R 1000:1000 $installation_directory +chown -R 1000:1000 $installation_directory -sudo chmod -R 777 data +chmod -R 777 data -sudo docker compose up -d +docker compose up -d echo "数据库地址:mysql" echo "数据库用户名:root" diff --git a/Config/Task/Installs/backup.sh b/Config/Task/Installs/backup.sh index 6bacfc2..4589784 100644 --- a/Config/Task/Installs/backup.sh +++ b/Config/Task/Installs/backup.sh @@ -43,11 +43,11 @@ fi if [[ ! $baidu_backup_choice =~ [Nn] ]];then if [[ -f "/usr/bin/apt-get" ]];then - sudo apt-get install python3-venv -y + apt-get install python3-venv -y elif [[ -f "/usr/bin/apt" ]];then - sudo apt-get install python3-venv -y + apt-get install python3-venv -y elif [[ -f "/usr/bin/pacman" ]];then - sudo pacman -Sy python3-venv --noconfirm + pacman -Sy python3-venv --noconfirm else echo "无法自动安装 python3-venv,请手动安装" exit diff --git a/Config/Task/Installs/menu.sh b/Config/Task/Installs/menu.sh index ede4841..49f00ba 100644 --- a/Config/Task/Installs/menu.sh +++ b/Config/Task/Installs/menu.sh @@ -17,10 +17,11 @@ done echo "输入其他任意值返回主页" read -p "请输入:" user_choice -if [[ ! ${user_choice} =~ [1-$file_count] ]];then +if [[ ! "$user_choice" =~ ^[0-9]+$ ]] || [ "$user_choice" -lt 1 ] || [ "$user_choice" -gt "$file_count" ]; then exit fi + read -p "请输入脚本存放路径(默认:/var/script):" script_path if [[ -z $script_path ]];then diff --git a/Config/Task/Installs/up-docker_compose.sh b/Config/Task/Installs/up-docker_compose.sh index 5f294b2..e9bc71f 100644 --- a/Config/Task/Installs/up-docker_compose.sh +++ b/Config/Task/Installs/up-docker_compose.sh @@ -15,7 +15,7 @@ cat > "${docker_compose_path}/up-docker_compose.sh" << EOF #!/bin/bash for dir in "${data_directory}"/*/; do cd "\$dir" || exit - sudo docker compose pull - sudo docker compose up -d + docker compose pull + docker compose up -d done EOF \ No newline at end of file diff --git a/Config/Task/Installs/update.sh b/Config/Task/Installs/update.sh index 3f36312..ce4e14e 100644 --- a/Config/Task/Installs/update.sh +++ b/Config/Task/Installs/update.sh @@ -3,13 +3,13 @@ declare update_path="$1" echo '#!/bin/bash' > "${update_path}/update.sh" if [[ -f "/usr/bin/apt" ]];then - echo 'sudo apt update -y' >> "${update_path}/update.sh" - echo 'sudo apt-get dist-upgrade -y' >> "${update_path}/update.sh" + echo 'apt update -y' >> "${update_path}/update.sh" + echo 'apt-get dist-upgrade -y' >> "${update_path}/update.sh" elif [[ -f "/usr/bin/apt-get" ]];then - echo 'sudo apt-get update -y' >> "${update_path}/update.sh" - echo 'sudo apt dist-upgrade -y' >> "${update_path}/update.sh" + echo 'apt-get update -y' >> "${update_path}/update.sh" + echo 'apt dist-upgrade -y' >> "${update_path}/update.sh" elif [[ -f "/usr/bin/pacman" ]];then - sudo pacman -Syu --noconfirm + pacman -Syu --noconfirm else rm "${update_path}/update.sh" echo "暂不支持该系统的自动更新配置" diff --git a/run.sh b/run.sh index cef818a..81e422b 100644 --- a/run.sh +++ b/run.sh @@ -44,7 +44,7 @@ if [[ $local_path != $script_path ]]; then fi read -p "请输入要使用的功能:" user_choice -if [[ "${user_choice}" =~ [1-${#function_array[*]}] ]];then +if [[ "$user_choice" =~ ^[0-9]+$ ]] && [ "$user_choice" -ge 1 ] && [ "$user_choice" -le "${#function_array[*]}" ]; then clear if [[ -d "${local_path}/${function_array[$user_choice]}" ]]; then local_path="${local_path}/${function_array[$user_choice]}"