This commit is contained in:
@@ -20,7 +20,8 @@ readonly YELLOW='\033[1;33m'
|
|||||||
|
|
||||||
# Configuration
|
# Configuration
|
||||||
readonly FILES_URL="https://git.ivanch.me/ivanch/server-scripts/raw/branch/main"
|
readonly FILES_URL="https://git.ivanch.me/ivanch/server-scripts/raw/branch/main"
|
||||||
readonly REQUIRED_PACKAGES=("zip" "unzip" "sha256sum" "curl" "crontab")
|
readonly REQUIRED_PACKAGES=("zip" "unzip" "curl")
|
||||||
|
readonly REQUIRED_COMMANDS=("zip" "unzip" "sha256sum" "curl" "crontab")
|
||||||
readonly AVAILABLE_SCRIPTS=("clean.sh" "backup.sh" "docker-updater.sh")
|
readonly AVAILABLE_SCRIPTS=("clean.sh" "backup.sh" "docker-updater.sh")
|
||||||
|
|
||||||
# Format: [script_name]="cron_schedule"
|
# Format: [script_name]="cron_schedule"
|
||||||
@@ -76,13 +77,23 @@ detect_operating_system() {
|
|||||||
get_missing_packages() {
|
get_missing_packages() {
|
||||||
local missing=()
|
local missing=()
|
||||||
|
|
||||||
for package in "${REQUIRED_PACKAGES[@]}"; do
|
# Check each required command and map to package names
|
||||||
if ! command_exists "$package"; then
|
if ! command_exists "zip"; then
|
||||||
missing+=("$package")
|
missing+=("zip")
|
||||||
fi
|
fi
|
||||||
done
|
if ! command_exists "unzip"; then
|
||||||
|
missing+=("unzip")
|
||||||
|
fi
|
||||||
|
if ! command_exists "curl"; then
|
||||||
|
missing+=("curl")
|
||||||
|
fi
|
||||||
|
# sha256sum is part of coreutils (usually pre-installed)
|
||||||
|
# crontab is part of cron package, but we'll check for cron service later
|
||||||
|
|
||||||
|
# Only print if there are missing packages
|
||||||
|
if [[ ${#missing[@]} -gt 0 ]]; then
|
||||||
printf '%s\n' "${missing[@]}"
|
printf '%s\n' "${missing[@]}"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Install packages based on the detected OS
|
# Install packages based on the detected OS
|
||||||
@@ -92,10 +103,12 @@ install_packages() {
|
|||||||
local packages=("$@")
|
local packages=("$@")
|
||||||
|
|
||||||
if [[ ${#packages[@]} -eq 0 ]]; then
|
if [[ ${#packages[@]} -eq 0 ]]; then
|
||||||
|
log_info "No packages to install"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
log_info "Installing required packages: ${packages[*]}"
|
log_info "Installing required packages: ${packages[*]}"
|
||||||
|
log_info "Debug: Installing ${#packages[@]} packages on $os"
|
||||||
|
|
||||||
case "$os" in
|
case "$os" in
|
||||||
"Alpine")
|
"Alpine")
|
||||||
@@ -152,16 +165,17 @@ check_crontab_service() {
|
|||||||
select_scripts() {
|
select_scripts() {
|
||||||
local selected=()
|
local selected=()
|
||||||
|
|
||||||
log_info "Available scripts for download and installation:"
|
echo >&2 # Send to stderr so it doesn't get captured
|
||||||
echo
|
echo -e "${GREY}[i] Available scripts for download and installation:${NC}" >&2
|
||||||
|
echo >&2
|
||||||
|
|
||||||
for script in "${AVAILABLE_SCRIPTS[@]}"; do
|
for script in "${AVAILABLE_SCRIPTS[@]}"; do
|
||||||
local schedule="${CRONTAB_SCHEDULES[$script]:-"0 0 * * *"}"
|
local schedule="${CRONTAB_SCHEDULES[$script]:-"0 0 * * *"}"
|
||||||
echo -e " ${LIGHT_BLUE}$script${NC} - Schedule: ${GREY}$schedule${NC}"
|
echo -e " ${LIGHT_BLUE}$script${NC} - Schedule: ${GREY}$schedule${NC}" >&2
|
||||||
done
|
done
|
||||||
|
|
||||||
echo
|
echo >&2
|
||||||
log_info "Select scripts to download and install:"
|
echo -e "${GREY}[i] Select scripts to download and install:${NC}" >&2
|
||||||
|
|
||||||
for script in "${AVAILABLE_SCRIPTS[@]}"; do
|
for script in "${AVAILABLE_SCRIPTS[@]}"; do
|
||||||
read -p "Install $script? [Y/n]: " choice </dev/tty
|
read -p "Install $script? [Y/n]: " choice </dev/tty
|
||||||
@@ -171,9 +185,11 @@ select_scripts() {
|
|||||||
done
|
done
|
||||||
|
|
||||||
if [[ ${#selected[@]} -eq 0 ]]; then
|
if [[ ${#selected[@]} -eq 0 ]]; then
|
||||||
die "No scripts selected. Exiting..."
|
echo -e "${RED}[x] No scripts selected. Exiting...${NC}" >&2
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Only output the selected scripts to stdout
|
||||||
printf '%s\n' "${selected[@]}"
|
printf '%s\n' "${selected[@]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,6 +284,21 @@ main() {
|
|||||||
local missing_packages
|
local missing_packages
|
||||||
readarray -t missing_packages < <(get_missing_packages)
|
readarray -t missing_packages < <(get_missing_packages)
|
||||||
|
|
||||||
|
# Filter out empty strings
|
||||||
|
local filtered_packages=()
|
||||||
|
for pkg in "${missing_packages[@]}"; do
|
||||||
|
if [[ -n "$pkg" ]]; then
|
||||||
|
filtered_packages+=("$pkg")
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
missing_packages=("${filtered_packages[@]}")
|
||||||
|
|
||||||
|
# Debug output
|
||||||
|
log_info "Debug: Found ${#missing_packages[@]} missing packages"
|
||||||
|
for i in "${!missing_packages[@]}"; do
|
||||||
|
log_info "Debug: Missing package $((i+1)): '${missing_packages[i]}'"
|
||||||
|
done
|
||||||
|
|
||||||
if [[ ${#missing_packages[@]} -gt 0 ]]; then
|
if [[ ${#missing_packages[@]} -gt 0 ]]; then
|
||||||
log_warning "Missing packages detected: ${missing_packages[*]}"
|
log_warning "Missing packages detected: ${missing_packages[*]}"
|
||||||
install_packages "$detected_os" "${missing_packages[@]}"
|
install_packages "$detected_os" "${missing_packages[@]}"
|
||||||
|
Reference in New Issue
Block a user