2024-09-26 09:48:31 +08:00
|
|
|
|
#!/bin/bash
|
2024-11-18 23:12:52 +08:00
|
|
|
|
declare local_directory=$1
|
|
|
|
|
declare user_choice
|
|
|
|
|
declare selected_file_name
|
2024-09-26 09:48:31 +08:00
|
|
|
|
echo "========$(basename $0 .sh)========"
|
2024-11-18 23:12:52 +08:00
|
|
|
|
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
|
2024-09-26 09:48:31 +08:00
|
|
|
|
continue
|
|
|
|
|
fi
|
2024-11-18 23:12:52 +08:00
|
|
|
|
file_count=$((file_count + 1))
|
|
|
|
|
file_array[$file_count]=$selected_file_name
|
|
|
|
|
echo "${file_count}.${selected_file_name}"
|
2024-09-26 09:48:31 +08:00
|
|
|
|
done
|
2024-11-18 23:12:52 +08:00
|
|
|
|
echo "输入其他字符返回主页"
|
|
|
|
|
read -p "请输入:" user_choice
|
2024-09-26 09:48:31 +08:00
|
|
|
|
|
2024-11-18 23:12:52 +08:00
|
|
|
|
if [[ ! ${user_choice} =~ [1-$file_count] ]];then
|
2024-09-26 09:48:31 +08:00
|
|
|
|
exit
|
|
|
|
|
fi
|
|
|
|
|
|
2024-11-18 23:12:52 +08:00
|
|
|
|
declare storage_path
|
|
|
|
|
read -p "请输入软件存储位置,默认 /var/www/${file_array[${user_choice}]} :" storage_path
|
|
|
|
|
if [[ -z ${storage_path} ]];then
|
|
|
|
|
storage_path="/var/www/${file_array[${user_choice}]}"
|
2024-09-26 09:48:31 +08:00
|
|
|
|
fi
|
|
|
|
|
|
2024-11-18 23:12:52 +08:00
|
|
|
|
if [[ ! -d "$storage_path" ]];then
|
|
|
|
|
sudo mkdir -p "$storage_path" || { echo "目录创建失败"; exit 1; }
|
|
|
|
|
elif [[ ! -z "$(find "$storage_path" -mindepth 1 -print -quit)" ]];then
|
2024-09-26 09:48:31 +08:00
|
|
|
|
echo "该目录存有文件"
|
|
|
|
|
exit
|
|
|
|
|
fi
|
|
|
|
|
|
2024-11-18 23:12:52 +08:00
|
|
|
|
declare random_port=$(($RANDOM % 9000 + 1000))
|
2024-09-26 09:48:31 +08:00
|
|
|
|
|
2024-11-18 23:12:52 +08:00
|
|
|
|
while ss -tuln | grep $random_port &> /dev/null
|
2024-09-26 09:48:31 +08:00
|
|
|
|
do
|
2024-11-18 23:12:52 +08:00
|
|
|
|
random_port=$(($RANDOM % 9000 + 1000))
|
2024-09-26 09:48:31 +08:00
|
|
|
|
done
|
|
|
|
|
|
2024-11-18 23:12:52 +08:00
|
|
|
|
declare access_port
|
|
|
|
|
read -p "请输入访问端口,默认 $random_port :" access_port
|
2024-09-26 09:48:31 +08:00
|
|
|
|
|
2024-11-18 23:12:52 +08:00
|
|
|
|
if [[ -z $access_port ]];then
|
|
|
|
|
access_port=$random_port
|
2024-09-26 09:48:31 +08:00
|
|
|
|
fi
|
|
|
|
|
|
2024-11-18 23:12:52 +08:00
|
|
|
|
if ss -tuln | grep $access_port &> /dev/null;then
|
2024-09-26 09:48:31 +08:00
|
|
|
|
echo "端口已被占用"
|
|
|
|
|
exit
|
|
|
|
|
fi
|
|
|
|
|
|
2024-11-18 23:12:52 +08:00
|
|
|
|
bash "${local_directory}/${file_array[user_choice]}.sh" "$storage_path" "$access_port"
|
|
|
|
|
echo "${file_array[${user_choice}]} 安装完成,访问端口 ${access_port}"
|