jina verze
This commit is contained in:
@@ -0,0 +1,221 @@
|
||||
systemLabel="[System]"
|
||||
|
||||
# Runs the full system installation flow.
|
||||
function cmdInstallFull() {
|
||||
systemApt || return 1
|
||||
systemIpset || return 1
|
||||
systemIptables || return 1
|
||||
|
||||
cmdK3sInstall || return 1
|
||||
cmdK3sNamespaceAdd || return 1
|
||||
|
||||
cmdMariadbInstall || return 1
|
||||
cmdRedisInstall || return 1
|
||||
cmdOpenlitespeedInstall || return 1
|
||||
cmdPostfixInstall || return 1
|
||||
cmdWorkerInstall || return 1
|
||||
cmdMetricInstall || return 1
|
||||
}
|
||||
|
||||
# Displays numbered cron job list and stores selected job + current crontab in namerefs.
|
||||
# Known jobs (cronJobs[]): green if installed, gray if missing.
|
||||
# Unknown kube.sh jobs found in crontab: yellow, numbered after known jobs.
|
||||
# $1 (varname): nameref for selected job string
|
||||
# $2 (listvar): nameref for current crontab lines
|
||||
function cmdCronSelect() {
|
||||
local -n __cronJob="$1"
|
||||
local -n __cronList="$2"
|
||||
|
||||
printRow
|
||||
|
||||
local error
|
||||
run __cronList error systemCronList || { printDanger "Error retrieving the CRON job list: $error"; return 1; }
|
||||
|
||||
local -a shownJobs
|
||||
local i job fontColor
|
||||
for ((i=0; i<${#cronJobs[@]}; i++)); do
|
||||
job="${cronJobs[$i]}"
|
||||
shownJobs+=("$job")
|
||||
grep -Fxq -- "$job" <<< "$__cronList" && fontColor="$fontGreen" || fontColor="$fontGray"
|
||||
printf "%2d: %s\n" "$((i+1))" "$fontColor$job$fontReset"
|
||||
done
|
||||
while IFS= read -r job; do
|
||||
[[ -z "$job" ]] && continue
|
||||
grep -Fxq -- "$job" <(printf '%s\n' "${cronJobs[@]}") && continue
|
||||
grep -Fq -- "$appPath/kube.sh" <<< "$job" || continue
|
||||
shownJobs+=("$job")
|
||||
printf "%2d: %s\n" "${#shownJobs[@]}" "$fontYellow$job$fontReset"
|
||||
done <<< "$__cronList"
|
||||
printRow
|
||||
|
||||
local input item
|
||||
read -r -p "Specify the job number: " input
|
||||
printRow
|
||||
|
||||
[[ -z "$input" ]] && input=0
|
||||
[[ "$input" =~ ^[0-9]+$ ]] || { printDanger "Invalid job number"; return 1; }
|
||||
item=$((10#$input - 1))
|
||||
(( item < 0 || item >= ${#shownJobs[@]} )) && { printDanger "Unknown job number"; return 1; }
|
||||
|
||||
__cronJob="${shownJobs[$item]}"
|
||||
}
|
||||
|
||||
# Interactively selects and adds a managed cron job to root crontab.
|
||||
function cmdCronAdd() {
|
||||
local selected jobList
|
||||
cmdCronSelect selected jobList || { printRow; return 1; }
|
||||
|
||||
grep -Fxq -- "$selected" <(printf '%s\n' "${cronJobs[@]}") || {
|
||||
printDanger "Cannot add unmanaged job"
|
||||
printRow
|
||||
return 1
|
||||
}
|
||||
|
||||
if grep -Fxq -- "$selected" <<< "$jobList"; then
|
||||
printSuccess "Job already exists in cron"
|
||||
printRow
|
||||
return 0
|
||||
fi
|
||||
|
||||
local tmp
|
||||
tmp=$(mktemp) || { printRow; return 1; }
|
||||
{ printf '%s\n' "$jobList"; printf '%s\n' "$selected"; } > "$tmp"
|
||||
if crontab -u root "$tmp"; then
|
||||
printSuccess "Successfully added job to cron"
|
||||
else
|
||||
rm -f "$tmp"
|
||||
printDanger "Failed to add job to cron"
|
||||
printRow
|
||||
return 1
|
||||
fi
|
||||
rm -f "$tmp"
|
||||
|
||||
printRow
|
||||
}
|
||||
|
||||
# Interactively selects and removes a managed cron job from root crontab.
|
||||
function cmdCronRemove() {
|
||||
local selected jobList
|
||||
cmdCronSelect selected jobList || { printRow; return 1; }
|
||||
|
||||
if ! grep -Fxq -- "$selected" <<< "$jobList"; then
|
||||
printSuccess "Job not found in cron"
|
||||
printRow
|
||||
return 0
|
||||
fi
|
||||
|
||||
local tmp
|
||||
tmp=$(mktemp) || { printRow; return 1; }
|
||||
grep -Fxv -- "$selected" <<< "$jobList" > "$tmp"
|
||||
if crontab -u root "$tmp"; then
|
||||
printSuccess "Successfully removed job from cron"
|
||||
else
|
||||
rm -f "$tmp"
|
||||
printDanger "Failed to remove job from cron"
|
||||
printRow
|
||||
return 1
|
||||
fi
|
||||
rm -f "$tmp"
|
||||
|
||||
printRow
|
||||
}
|
||||
|
||||
# Shows managed cron jobs; installed entries in green, missing in gray, unknown in yellow.
|
||||
function cmdCronList() {
|
||||
local jobList error
|
||||
run jobList error systemCronList || { printDanger "systemCronList: $error"; return 1; }
|
||||
|
||||
local i job fontColor
|
||||
printRow
|
||||
for ((i=0; i<${#cronJobs[@]}; i++)); do
|
||||
grep -Fxq -- "${cronJobs[$i]}" <<< "$jobList" && fontColor="$fontGreen" || fontColor="$fontGray"
|
||||
printf "%3d: %s\n" "$((i+1))" "$fontColor${cronJobs[$i]}$fontReset"
|
||||
done
|
||||
while IFS= read -r job; do
|
||||
[[ -z "$job" ]] && continue
|
||||
grep -Fxq -- "$job" <(printf '%s\n' "${cronJobs[@]}") && continue
|
||||
grep -Fq -- "$appPath/kube.sh" <<< "$job" || continue
|
||||
((i++))
|
||||
printf "%3d: %s\n" "$i" "$fontYellow$job$fontReset"
|
||||
done <<< "$jobList"
|
||||
printRow
|
||||
}
|
||||
|
||||
# Lists users in the SFTP access group.
|
||||
function cmdSftpUserList() {
|
||||
local output error
|
||||
|
||||
printRow
|
||||
|
||||
if ! run output error sftpUserList "$@"; then
|
||||
printDanger "$error"
|
||||
else
|
||||
printText "$output"
|
||||
fi
|
||||
|
||||
printRow
|
||||
}
|
||||
|
||||
# Enables SFTP access for a domain user.
|
||||
function cmdSftpAccessEnable() {
|
||||
local error
|
||||
|
||||
printRow
|
||||
|
||||
if ! runError error sftpAccessEnable "$@"; then
|
||||
printDotText "SFTP access enable" "$labelFail"
|
||||
printDanger "$error"
|
||||
else
|
||||
printDotText "SFTP access enable" "$labelDone"
|
||||
fi
|
||||
|
||||
printRow
|
||||
}
|
||||
|
||||
# Disables SFTP access for a domain user by removing them from the SFTP group.
|
||||
function cmdSftpAccessDisable() {
|
||||
local error
|
||||
|
||||
printRow
|
||||
|
||||
if ! runError error sftpAccessDisable "$@"; then
|
||||
printDotText "SFTP access enable" "$labelFail"
|
||||
printDanger "$error"
|
||||
else
|
||||
printDotText "SFTP access enable" "$labelDone"
|
||||
fi
|
||||
|
||||
printRow
|
||||
}
|
||||
|
||||
# Sets the SFTP password for a domain user from site config.
|
||||
function cmdSftpPasswordSet() {
|
||||
local error
|
||||
|
||||
printRow
|
||||
|
||||
if ! runError error sftpPasswordSet "$@"; then
|
||||
printDotText "SFTP password set" "$labelFail"
|
||||
printDanger "$error"
|
||||
else
|
||||
printDotText "SFTP password set" "$labelDone"
|
||||
fi
|
||||
|
||||
printRow
|
||||
}
|
||||
|
||||
# [WARNING] Patches sshd_config to enable SFTP via internal-sftp with group-based chroot.
|
||||
function cmdSftpAddingSupport() {
|
||||
local error
|
||||
|
||||
printRow
|
||||
|
||||
if ! runError error sftpAddingSupport; then
|
||||
printDotText "SFTP adding support" "$labelFail"
|
||||
printDanger "$error"
|
||||
else
|
||||
printDotText "SFTP adding support" "$labelDone"
|
||||
fi
|
||||
|
||||
printRow
|
||||
}
|
||||
Reference in New Issue
Block a user