feat(update_local_appstore): add clone-source and dry-run options
- add --clone-source parameter to specify specific git sources (github, mirror, codeberg, forgejo, gitea) - add --dry-run parameter to preview actions without making changes - add comprehensive dry-run output showing URLs to clone and copy operations - restructure mirror repositories into a associative array for better source management - implement source validation and deduplication logic - update both English and Chinese message strings for new features
This commit is contained in:
parent
8eec3816df
commit
335f800b10
|
|
@ -54,6 +54,15 @@ if $USE_ZH; then
|
|||
MSG_NOTE_UNKNOWN="注意: 未知参数 %s 被忽略"
|
||||
MSG_WARN_APP_MISSING="警告: 应用 '%s' 在仓库中不存在"
|
||||
MSG_TRY_CLONE="正在尝试克隆 %s"
|
||||
MSG_ERR_CLONE_SOURCE_REQUIRE="错误: --clone-source 参数需要指定源名称"
|
||||
MSG_ERR_UNKNOWN_SOURCE="错误: 未知的源 '%s'"
|
||||
MSG_DRY_RUN_MODE="试运行模式已启用,不会执行任何实际更改"
|
||||
MSG_DRY_RUN_URL_HEADER="将按以下顺序克隆 URL:"
|
||||
MSG_DRY_RUN_URL="将克隆: %s"
|
||||
MSG_DRY_RUN_TARGET_DIR_EXISTS="目标目录 %s 存在"
|
||||
MSG_DRY_RUN_TARGET_DIR_NOT_EXISTS="目标目录 %s 不存在"
|
||||
MSG_DRY_RUN_COPY="将复制应用 '%s' 到 %s"
|
||||
MSG_DRY_RUN_COPY_ALL="将复制所有应用到 %s"
|
||||
else
|
||||
MSG_INTRO=" ###########################################
|
||||
# Note #
|
||||
|
|
@ -85,10 +94,22 @@ else
|
|||
MSG_NOTE_UNKNOWN="Note: Unknown parameter %s ignored"
|
||||
MSG_WARN_APP_MISSING="WARNING: App '%s' does not exist in repository"
|
||||
MSG_TRY_CLONE="Trying to clone %s"
|
||||
MSG_ERR_CLONE_SOURCE_REQUIRE="Error: --clone-source parameter requires a source name"
|
||||
MSG_ERR_UNKNOWN_SOURCE="Error: Unknown source '%s'"
|
||||
MSG_DRY_RUN_MODE="Dry run mode enabled, no changes will be made"
|
||||
MSG_DRY_RUN_URL_HEADER="URLs to be cloned (in order):"
|
||||
MSG_DRY_RUN_URL="Would clone: %s"
|
||||
MSG_DRY_RUN_TARGET_DIR_EXISTS="Target directory %s exists"
|
||||
MSG_DRY_RUN_TARGET_DIR_NOT_EXISTS="Target directory %s does not exist"
|
||||
MSG_DRY_RUN_COPY="Would copy app '%s' to %s"
|
||||
MSG_DRY_RUN_COPY_ALL="Would copy all apps to %s"
|
||||
fi
|
||||
|
||||
apps_to_copy=()
|
||||
custom_base_dir=""
|
||||
clone_sources=()
|
||||
dry_run=false
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
--app)
|
||||
|
|
@ -117,6 +138,19 @@ while [[ $# -gt 0 ]]; do
|
|||
exit 1
|
||||
fi
|
||||
;;
|
||||
--clone-source)
|
||||
if [[ -n "$2" && "$2" != --* ]]; then
|
||||
clone_sources+=("$2")
|
||||
shift 2
|
||||
else
|
||||
echo "$MSG_ERR_CLONE_SOURCE_REQUIRE"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
--dry-run)
|
||||
dry_run=true
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
printf "$MSG_NOTE_UNKNOWN\n" "$1"
|
||||
shift
|
||||
|
|
@ -148,33 +182,135 @@ repo_prefixs=(
|
|||
'https://ghproxy.net/https://github.com'
|
||||
)
|
||||
|
||||
independent_repos=(
|
||||
'https://codeberg.org/pooneyy/1Panel-Appstore.git'
|
||||
'https://code.forgejo.org/pooneyy/1Panel-Appstore.git'
|
||||
'https://gitea.com/pooneyy/1Panel-Appstore.git'
|
||||
declare -A mirror_sites=(
|
||||
[codeberg]='https://codeberg.org/pooneyy/1Panel-Appstore.git'
|
||||
[forgejo]='https://code.forgejo.org/pooneyy/1Panel-Appstore.git'
|
||||
[gitea]='https://gitea.com/pooneyy/1Panel-Appstore.git'
|
||||
)
|
||||
mirror_names=("${!mirror_sites[@]}")
|
||||
|
||||
repo_suffix="/pooneyy/1Panel-Appstore.git"
|
||||
|
||||
if [ ${#clone_sources[@]} -eq 0 ]; then
|
||||
clone_sources=("all")
|
||||
fi
|
||||
|
||||
declare -A source_map
|
||||
unique_sources=()
|
||||
for src in "${clone_sources[@]}"; do
|
||||
if [[ -z "${source_map[$src]}" ]]; then
|
||||
source_map[$src]=1
|
||||
unique_sources+=("$src")
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ " ${unique_sources[@]} " =~ " all " ]]; then
|
||||
final_sources=("all")
|
||||
else
|
||||
has_mirror=false
|
||||
for src in "${unique_sources[@]}"; do
|
||||
if [[ "$src" == "mirror" ]]; then
|
||||
has_mirror=true
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if $has_mirror; then
|
||||
final_sources=()
|
||||
for src in "${unique_sources[@]}"; do
|
||||
if [[ "$src" == "mirror" ]] || [[ "$src" == "github" ]]; then
|
||||
final_sources+=("$src")
|
||||
else
|
||||
if [[ -n "${mirror_sites[$src]}" ]]; then
|
||||
:
|
||||
else
|
||||
printf "$MSG_ERR_UNKNOWN_SOURCE\n" "$src"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
done
|
||||
else
|
||||
final_sources=()
|
||||
for src in "${unique_sources[@]}"; do
|
||||
if [[ "$src" == "github" ]] || [[ "$src" == "mirror" ]]; then
|
||||
final_sources+=("$src")
|
||||
elif [[ -n "${mirror_sites[$src]}" ]]; then
|
||||
final_sources+=("$src")
|
||||
else
|
||||
printf "$MSG_ERR_UNKNOWN_SOURCE\n" "$src"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
fi
|
||||
fi
|
||||
|
||||
all_urls=()
|
||||
|
||||
for prefix in "${repo_prefixs[@]}"; do
|
||||
all_urls+=("${prefix}${repo_suffix}")
|
||||
done
|
||||
shuffle_array() {
|
||||
local arr=("$@")
|
||||
local len=${#arr[@]}
|
||||
for ((i=0; i<len; i++)); do
|
||||
j=$((RANDOM % (len - i) + i))
|
||||
tmp=${arr[i]}
|
||||
arr[i]=${arr[j]}
|
||||
arr[j]=$tmp
|
||||
done
|
||||
echo "${arr[@]}"
|
||||
}
|
||||
|
||||
indep_len=${#independent_repos[@]}
|
||||
indices=()
|
||||
for ((i=0; i<indep_len; i++)); do
|
||||
indices[$i]=$i
|
||||
done
|
||||
for ((i=0; i<indep_len; i++)); do
|
||||
j=$((RANDOM % (indep_len - i) + i))
|
||||
tmp=${indices[i]}
|
||||
indices[i]=${indices[j]}
|
||||
indices[j]=$tmp
|
||||
done
|
||||
for idx in "${indices[@]}"; do
|
||||
all_urls+=("${independent_repos[idx]}")
|
||||
done
|
||||
if [[ " ${final_sources[@]} " =~ " all " ]]; then
|
||||
for prefix in "${repo_prefixs[@]}"; do
|
||||
all_urls+=("${prefix}${repo_suffix}")
|
||||
done
|
||||
all_indep_urls=("${mirror_sites[@]}")
|
||||
shuffled_indep=($(shuffle_array "${all_indep_urls[@]}"))
|
||||
all_urls+=("${shuffled_indep[@]}")
|
||||
else
|
||||
if [[ " ${final_sources[@]} " =~ " github " ]]; then
|
||||
for prefix in "${repo_prefixs[@]}"; do
|
||||
all_urls+=("${prefix}${repo_suffix}")
|
||||
done
|
||||
fi
|
||||
|
||||
indep_urls_to_add=()
|
||||
for src in "${final_sources[@]}"; do
|
||||
if [[ "$src" == "mirror" ]]; then
|
||||
indep_urls_to_add=("${mirror_sites[@]}")
|
||||
break
|
||||
elif [[ -n "${mirror_sites[$src]}" ]]; then
|
||||
indep_urls_to_add+=("${mirror_sites[$src]}")
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ${#indep_urls_to_add[@]} -gt 0 ]; then
|
||||
shuffled_indep=($(shuffle_array "${indep_urls_to_add[@]}"))
|
||||
all_urls+=("${shuffled_indep[@]}")
|
||||
fi
|
||||
fi
|
||||
|
||||
if $dry_run; then
|
||||
echo "$MSG_DRY_RUN_MODE"
|
||||
echo ""
|
||||
echo "$MSG_DRY_RUN_URL_HEADER"
|
||||
for url in "${all_urls[@]}"; do
|
||||
printf "$MSG_DRY_RUN_URL\n" "$url"
|
||||
done
|
||||
echo ""
|
||||
target_dir="$BASE_DIR/1panel/resource/apps/local/"
|
||||
if [ ${#apps_to_copy[@]} -gt 0 ]; then
|
||||
for app in "${apps_to_copy[@]}"; do
|
||||
printf "$MSG_DRY_RUN_COPY\n" "$app" "$target_dir"
|
||||
done
|
||||
else
|
||||
printf "$MSG_DRY_RUN_COPY_ALL\n" "$target_dir"
|
||||
fi
|
||||
if [ -d "$target_dir" ]; then
|
||||
printf "$MSG_DRY_RUN_TARGET_DIR_EXISTS\n" "$target_dir"
|
||||
else
|
||||
printf "$MSG_DRY_RUN_TARGET_DIR_NOT_EXISTS\n" "$target_dir"
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
TEMP_DIR=$(mktemp -d)
|
||||
mkdir -p $BASE_DIR/1panel/resource/apps/local/
|
||||
|
|
|
|||
Loading…
Reference in New Issue