mirror of
https://github.com/community-scripts/ProxmoxVED.git
synced 2026-02-25 05:57:26 +00:00
Do what mick said
This commit is contained in:
218
misc/core.func
Normal file
218
misc/core.func
Normal file
@@ -0,0 +1,218 @@
|
||||
# Copyright (c) 2021-2025 community-scripts ORG
|
||||
# Author: michelroegl-brunner
|
||||
# License: MIT | https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/LICENSE
|
||||
|
||||
color() {
|
||||
# Colors
|
||||
YW=$(echo "\033[33m")
|
||||
YWB=$(echo "\033[93m")
|
||||
BL=$(echo "\033[36m")
|
||||
RD=$(echo "\033[01;31m")
|
||||
BGN=$(echo "\033[4;92m")
|
||||
GN=$(echo "\033[1;92m")
|
||||
DGN=$(echo "\033[32m")
|
||||
|
||||
# Formatting
|
||||
CL=$(echo "\033[m")
|
||||
BOLD=$(echo "\033[1m")
|
||||
HOLD=" "
|
||||
TAB=" "
|
||||
|
||||
# Icons
|
||||
CM="${TAB}✔️${TAB}"
|
||||
CROSS="${TAB}✖️${TAB}${CL}"
|
||||
INFO="${TAB}💡${TAB}${CL}"
|
||||
OS="${TAB}🖥️${TAB}${CL}"
|
||||
OSVERSION="${TAB}🌟${TAB}${CL}"
|
||||
CONTAINERTYPE="${TAB}📦${TAB}${CL}"
|
||||
DISKSIZE="${TAB}💾${TAB}${CL}"
|
||||
CPUCORE="${TAB}🧠${TAB}${CL}"
|
||||
RAMSIZE="${TAB}🛠️${TAB}${CL}"
|
||||
SEARCH="${TAB}🔍${TAB}${CL}"
|
||||
VERBOSE_CROPPED="🔍${TAB}"
|
||||
VERIFYPW="${TAB}🔐${TAB}${CL}"
|
||||
CONTAINERID="${TAB}🆔${TAB}${CL}"
|
||||
HOSTNAME="${TAB}🏠${TAB}${CL}"
|
||||
BRIDGE="${TAB}🌉${TAB}${CL}"
|
||||
NETWORK="${TAB}📡${TAB}${CL}"
|
||||
GATEWAY="${TAB}🌐${TAB}${CL}"
|
||||
DISABLEIPV6="${TAB}🚫${TAB}${CL}"
|
||||
DEFAULT="${TAB}⚙️${TAB}${CL}"
|
||||
MACADDRESS="${TAB}🔗${TAB}${CL}"
|
||||
VLANTAG="${TAB}🏷️${TAB}${CL}"
|
||||
ROOTSSH="${TAB}🔑${TAB}${CL}"
|
||||
CREATING="${TAB}🚀${TAB}${CL}"
|
||||
ADVANCED="${TAB}🧩${TAB}${CL}"
|
||||
FUSE="${TAB}🔧${TAB}${CL}"
|
||||
}
|
||||
|
||||
declare -A MSG_INFO_SHOWN
|
||||
SPINNER_ACTIVE=0
|
||||
SPINNER_PID=""
|
||||
SPINNER_MSG=""
|
||||
|
||||
start_spinner() {
|
||||
local msg="$1"
|
||||
local frames=(⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏)
|
||||
local spin_i=0
|
||||
local interval=0.1
|
||||
|
||||
SPINNER_MSG="$msg"
|
||||
printf "\r\e[2K" >&2
|
||||
|
||||
{
|
||||
while [[ "$SPINNER_ACTIVE" -eq 1 ]]; do
|
||||
printf "\r\e[2K%s %b" "${frames[spin_i]}" "${YW}${SPINNER_MSG}${CL}" >&2
|
||||
spin_i=$(((spin_i + 1) % ${#frames[@]}))
|
||||
sleep "$interval"
|
||||
done
|
||||
} &
|
||||
|
||||
SPINNER_PID=$!
|
||||
disown "$SPINNER_PID"
|
||||
}
|
||||
|
||||
stop_spinner() {
|
||||
if [[ ${SPINNER_PID+v} && -n "$SPINNER_PID" ]] && kill -0 "$SPINNER_PID" 2>/dev/null; then
|
||||
kill "$SPINNER_PID" 2>/dev/null
|
||||
sleep 0.1
|
||||
kill -0 "$SPINNER_PID" 2>/dev/null && kill -9 "$SPINNER_PID" 2>/dev/null
|
||||
wait "$SPINNER_PID" 2>/dev/null || true
|
||||
fi
|
||||
SPINNER_ACTIVE=0
|
||||
unset SPINNER_PID
|
||||
}
|
||||
|
||||
spinner_guard() {
|
||||
if [[ "$SPINNER_ACTIVE" -eq 1 ]] && [[ -n "$SPINNER_PID" ]]; then
|
||||
kill "$SPINNER_PID" 2>/dev/null
|
||||
wait "$SPINNER_PID" 2>/dev/null || true
|
||||
SPINNER_ACTIVE=0
|
||||
unset SPINNER_PID
|
||||
fi
|
||||
}
|
||||
|
||||
msg_info() {
|
||||
local msg="$1"
|
||||
if [ "${SPINNER_ACTIVE:-0}" -eq 1 ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
SPINNER_ACTIVE=1
|
||||
start_spinner "$msg"
|
||||
}
|
||||
|
||||
msg_ok() {
|
||||
if [ -n "${SPINNER_PID:-}" ] && ps -p "$SPINNER_PID" >/dev/null 2>&1; then
|
||||
kill "$SPINNER_PID" >/dev/null 2>&1
|
||||
wait "$SPINNER_PID" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
local msg="$1"
|
||||
printf "\r\e[2K${CM}${GN}%b${CL}\n" "$msg" >&2
|
||||
unset SPINNER_PID
|
||||
SPINNER_ACTIVE=0
|
||||
|
||||
log_message "OK" "$msg"
|
||||
}
|
||||
|
||||
msg_error() {
|
||||
if [ -n "${SPINNER_PID:-}" ] && ps -p "$SPINNER_PID" >/dev/null 2>&1; then
|
||||
kill "$SPINNER_PID" >/dev/null 2>&1
|
||||
wait "$SPINNER_PID" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
local msg="$1"
|
||||
printf "\r\e[2K${CROSS}${RD}%b${CL}\n" "$msg" >&2
|
||||
unset SPINNER_PID
|
||||
SPINNER_ACTIVE=0
|
||||
log_message "ERROR" "$msg"
|
||||
}
|
||||
shell_check() {
|
||||
if [[ "$(basename "$SHELL")" != "bash" ]]; then
|
||||
clear
|
||||
msg_error "Your default shell is currently not set to Bash. To use these scripts, please switch to the Bash shell."
|
||||
echo -e "\nExiting..."
|
||||
sleep 2
|
||||
exit
|
||||
fi
|
||||
}
|
||||
root_check() {
|
||||
if [[ "$(id -u)" -ne 0 || $(ps -o comm= -p $PPID) == "sudo" ]]; then
|
||||
clear
|
||||
msg_error "Please run this script as root."
|
||||
echo -e "\nExiting..."
|
||||
sleep 2
|
||||
exit
|
||||
fi
|
||||
}
|
||||
|
||||
pve_check() {
|
||||
if ! pveversion | grep -Eq "pve-manager/8\.[1-9](\.[0-9]+)*"; then
|
||||
msg_error "${CROSS}${RD}This version of Proxmox Virtual Environment is not supported"
|
||||
echo -e "Requires Proxmox Virtual Environment Version 8.1 or later."
|
||||
echo -e "Exiting..."
|
||||
sleep 2
|
||||
exit
|
||||
fi
|
||||
}
|
||||
|
||||
arch_check() {
|
||||
if [ "$(dpkg --print-architecture)" != "amd64" ]; then
|
||||
echo -e "\n ${INFO}${YWB}This script will not work with PiMox! \n"
|
||||
echo -e "\n ${YWB}Visit https://github.com/asylumexp/Proxmox for ARM64 support. \n"
|
||||
echo -e "Exiting..."
|
||||
sleep 2
|
||||
exit
|
||||
fi
|
||||
}
|
||||
|
||||
ssh_check() {
|
||||
if command -v pveversion >/dev/null 2>&1; then
|
||||
if [ -n "${SSH_CLIENT:+x}" ]; then
|
||||
if whiptail --backtitle "Proxmox VE Helper Scripts" --defaultno --title "SSH DETECTED" --yesno "It's suggested to use the Proxmox shell instead of SSH, since SSH can create issues while gathering variables. Would you like to proceed with using SSH?" 10 62; then
|
||||
echo "you've been warned"
|
||||
else
|
||||
clear
|
||||
exit
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
log_message() {
|
||||
local level="$1"
|
||||
local message="$2"
|
||||
local timestamp
|
||||
local logdate
|
||||
timestamp=$(date '+%Y-%m-%d %H:%M:%S')
|
||||
logdate=$(date '+%Y-%m-%d')
|
||||
|
||||
LOGDIR="/usr/local/community-scripts/logs"
|
||||
mkdir -p "$LOGDIR"
|
||||
|
||||
LOGFILE="${LOGDIR}/${logdate}_${NSAPP}.log"
|
||||
echo "$timestamp - $level: $message" >>"$LOGFILE"
|
||||
}
|
||||
|
||||
exit-script() {
|
||||
clear
|
||||
echo -e "\n${CROSS}${RD}User exited script${CL}\n"
|
||||
exit
|
||||
}
|
||||
|
||||
set_std_mode() {
|
||||
if [ "$VERB" = "yes" ]; then
|
||||
STD=""
|
||||
else
|
||||
STD="silent"
|
||||
fi
|
||||
}
|
||||
|
||||
silent() {
|
||||
if [ "$VERB" = "no" ]; then
|
||||
"$@" >>"$LOGFILE" 2>&1
|
||||
else
|
||||
"$@" 2>&1 | tee -a "$LOGFILE"
|
||||
fi
|
||||
}
|
||||
Reference in New Issue
Block a user