修复菜单脚本文件数量过多判断问题,gitea脚本执行顺序问题,去掉sudo检查

This commit is contained in:
lsy 2025-05-19 01:41:13 +08:00
parent a29c459709
commit 601b8ea2fb
8 changed files with 50 additions and 50 deletions

View File

@ -1,18 +1,16 @@
#!/bin/bash #!/bin/bash
if ! command -v sudo &> /dev/null; then
echo "该软件需要安装sudo才能正常安装"
exit
fi
declare install_path=$1 declare install_path=$1
declare service_port=$2 declare service_port=$2
sudo useradd -m git 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' su - git -c "ssh-keygen -t rsa -b 4096 -C \"Gitea Host Key\" -f /home/git/.ssh/id_rsa -N \"\""
sudo -u git sh -c 'chmod a+x /usr/local/bin/gitea' su - git -c "cat /home/git/.ssh/id_rsa.pub >> /home/git/.ssh/authorized_keys"
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' 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 user_id=$( id git | awk -F'[=() ]+' '{print $2}' )
declare group_id=$( id git | awk -F'[=() ]+' '{print $5}' ) declare group_id=$( id git | awk -F'[=() ]+' '{print $5}' )
@ -60,5 +58,4 @@ services:
- ./mysql:/var/lib/mysql - ./mysql:/var/lib/mysql
EOF EOF
chown -R git:git $install_path chown -R git:git $install_path
sudo docker compose up -d docker compose up -d

View File

@ -5,53 +5,55 @@ declare selected_file_name
echo "========$(basename $0 .sh)========" echo "========$(basename $0 .sh)========"
declare file_count=0 declare file_count=0
declare -a file_array declare -a file_array
for file in "${local_directory}"/*;do for file in "${local_directory}"/*; do
selected_file_name=$(awk -F '.' '{print $1}' <<< "$(basename $file)") selected_file_name=$(awk -F '.' '{print $1}' <<<"$(basename $file)")
if [[ $selected_file_name == "test" || $selected_file_name == "menu" ]]; then if [[ $selected_file_name == "test" || $selected_file_name == "menu" ]]; then
continue continue
fi fi
file_count=$((file_count + 1)) file_count=$((file_count + 1))
file_array[$file_count]=$selected_file_name file_array[$file_count]=$selected_file_name
echo "${file_count}.${selected_file_name}" echo "${file_count}.${selected_file_name}"
done done
echo "输入其他字符返回主页" echo "输入其他字符返回主页"
read -p "请输入:" user_choice 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 exit
fi fi
declare storage_path declare storage_path
read -p "请输入软件存储位置,默认 /var/www/${file_array[${user_choice}]} " storage_path read -p "请输入软件存储位置,默认 /var/www/${file_array[${user_choice}]} " storage_path
if [[ -z ${storage_path} ]];then if [[ -z ${storage_path} ]]; then
storage_path="/var/www/${file_array[${user_choice}]}" storage_path="/var/www/${file_array[${user_choice}]}"
fi fi
if [[ ! -d "$storage_path" ]];then if [[ ! -d "$storage_path" ]]; then
sudo mkdir -p "$storage_path" || { echo "目录创建失败"; exit 1; } mkdir -p "$storage_path" || {
elif [[ ! -z "$(find "$storage_path" -mindepth 1 -print -quit)" ]];then echo "目录创建失败"
echo "该目录存有文件" exit 1
exit }
elif [[ ! -z "$(find "$storage_path" -mindepth 1 -print -quit)" ]]; then
echo "该目录存有文件"
exit
fi fi
declare random_port=$(($RANDOM % 9000 + 1000)) declare random_port=$(($RANDOM % 9000 + 1000))
while ss -tuln | grep $random_port &> /dev/null while ss -tuln | grep $random_port &>/dev/null; do
do random_port=$(($RANDOM % 9000 + 1000))
random_port=$(($RANDOM % 9000 + 1000))
done done
declare access_port 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 access_port=$random_port
fi fi
if ss -tuln | grep $access_port &> /dev/null;then if ss -tuln | grep $access_port &>/dev/null; then
echo "端口已被占用" echo "端口已被占用"
exit exit
fi fi
bash "${local_directory}/${file_array[user_choice]}.sh" "$storage_path" "$access_port" bash "${local_directory}/${file_array[user_choice]}.sh" "$storage_path" "$access_port"
echo "${file_array[${user_choice}]} 安装完成,访问端口 ${access_port}" echo "${file_array[${user_choice}]} 安装完成,访问端口 ${access_port}"

View File

@ -108,11 +108,11 @@ rm typecho.zip
cd $installation_directory 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 "数据库地址mysql"
echo "数据库用户名root" echo "数据库用户名root"

View File

@ -43,11 +43,11 @@ fi
if [[ ! $baidu_backup_choice =~ [Nn] ]];then if [[ ! $baidu_backup_choice =~ [Nn] ]];then
if [[ -f "/usr/bin/apt-get" ]];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 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 elif [[ -f "/usr/bin/pacman" ]];then
sudo pacman -Sy python3-venv --noconfirm pacman -Sy python3-venv --noconfirm
else else
echo "无法自动安装 python3-venv请手动安装" echo "无法自动安装 python3-venv请手动安装"
exit exit

View File

@ -17,10 +17,11 @@ done
echo "输入其他任意值返回主页" echo "输入其他任意值返回主页"
read -p "请输入:" user_choice 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 exit
fi fi
read -p "请输入脚本存放路径(默认:/var/script" script_path read -p "请输入脚本存放路径(默认:/var/script" script_path
if [[ -z $script_path ]];then if [[ -z $script_path ]];then

View File

@ -15,7 +15,7 @@ cat > "${docker_compose_path}/up-docker_compose.sh" << EOF
#!/bin/bash #!/bin/bash
for dir in "${data_directory}"/*/; do for dir in "${data_directory}"/*/; do
cd "\$dir" || exit cd "\$dir" || exit
sudo docker compose pull docker compose pull
sudo docker compose up -d docker compose up -d
done done
EOF EOF

View File

@ -3,13 +3,13 @@ declare update_path="$1"
echo '#!/bin/bash' > "${update_path}/update.sh" echo '#!/bin/bash' > "${update_path}/update.sh"
if [[ -f "/usr/bin/apt" ]];then if [[ -f "/usr/bin/apt" ]];then
echo 'sudo apt update -y' >> "${update_path}/update.sh" echo 'apt update -y' >> "${update_path}/update.sh"
echo 'sudo apt-get dist-upgrade -y' >> "${update_path}/update.sh" echo 'apt-get dist-upgrade -y' >> "${update_path}/update.sh"
elif [[ -f "/usr/bin/apt-get" ]];then elif [[ -f "/usr/bin/apt-get" ]];then
echo 'sudo apt-get update -y' >> "${update_path}/update.sh" echo 'apt-get update -y' >> "${update_path}/update.sh"
echo 'sudo apt dist-upgrade -y' >> "${update_path}/update.sh" echo 'apt dist-upgrade -y' >> "${update_path}/update.sh"
elif [[ -f "/usr/bin/pacman" ]];then elif [[ -f "/usr/bin/pacman" ]];then
sudo pacman -Syu --noconfirm pacman -Syu --noconfirm
else else
rm "${update_path}/update.sh" rm "${update_path}/update.sh"
echo "暂不支持该系统的自动更新配置" echo "暂不支持该系统的自动更新配置"

2
run.sh
View File

@ -44,7 +44,7 @@ if [[ $local_path != $script_path ]]; then
fi fi
read -p "请输入要使用的功能:" user_choice 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 clear
if [[ -d "${local_path}/${function_array[$user_choice]}" ]]; then if [[ -d "${local_path}/${function_array[$user_choice]}" ]]; then
local_path="${local_path}/${function_array[$user_choice]}" local_path="${local_path}/${function_array[$user_choice]}"