mirror of
https://github.com/community-scripts/ProxmoxVE
synced 2025-01-25 10:06:18 +00:00
fix spinner on lxc-ip-tag (#876)
* fix spinner on lxc-ip-tag * fix indention
This commit is contained in:
parent
b18b49ef6f
commit
c60b16229b
@ -7,8 +7,8 @@
|
||||
# Source: https://github.com/gitsang/lxc-iptag
|
||||
|
||||
function header_info {
|
||||
clear
|
||||
cat <<"EOF"
|
||||
clear
|
||||
cat <<"EOF"
|
||||
__ _ ________ ________ ______
|
||||
/ / | |/ / ____/ / _/ __ \ /_ __/___ _____ _
|
||||
/ / | / / / // /_/ /_____/ / / __ `/ __ `/
|
||||
@ -41,7 +41,7 @@ catch_errors() {
|
||||
|
||||
# This function is called when an error occurs. It receives the exit code, line number, and command that caused the error, and displays an error message.
|
||||
error_handler() {
|
||||
if [ -n "$SPINNER_PID" ] && ps -p $SPINNER_PID > /dev/null; then kill $SPINNER_PID > /dev/null; fi
|
||||
if [ -n "$SPINNER_PID" ] && ps -p $SPINNER_PID >/dev/null; then kill $SPINNER_PID >/dev/null; fi
|
||||
printf "\e[?25h"
|
||||
local exit_code="$?"
|
||||
local line_number="$1"
|
||||
@ -50,16 +50,18 @@ error_handler() {
|
||||
echo -e "\n$error_message\n"
|
||||
}
|
||||
|
||||
# This function displays a spinner.
|
||||
spinner() {
|
||||
local frames=('⠋' '⠙' '⠹' '⠸' '⠼' '⠴' '⠦' '⠧' '⠇' '⠏')
|
||||
local spin_i=0
|
||||
local interval=0.1
|
||||
printf "\e[?25l"
|
||||
local orange="\e[38;5;214m"
|
||||
|
||||
local color="${YWB}"
|
||||
|
||||
while true; do
|
||||
printf "\r ${orange}%s\e[0m " "${frames[spin_i]}"
|
||||
spin_i=$(( (spin_i + 1) % ${#frames[@]} ))
|
||||
printf "\r ${color}%s${CL}" "${frames[spin_i]}"
|
||||
spin_i=$(((spin_i + 1) % ${#frames[@]}))
|
||||
sleep "$interval"
|
||||
done
|
||||
}
|
||||
@ -67,33 +69,36 @@ spinner() {
|
||||
# This function displays an informational message with a yellow color.
|
||||
msg_info() {
|
||||
local msg="$1"
|
||||
echo -ne " ${HOLD} ${YW}${msg} "
|
||||
echo -ne "${TAB}${YW}${HOLD}${msg}${HOLD}"
|
||||
spinner &
|
||||
SPINNER_PID=$!
|
||||
}
|
||||
|
||||
# This function displays a success message with a green color.
|
||||
msg_ok() {
|
||||
if [ -n "$SPINNER_PID" ] && ps -p $SPINNER_PID > /dev/null; then kill $SPINNER_PID > /dev/null; fi
|
||||
if [ -n "$SPINNER_PID" ] && ps -p $SPINNER_PID >/dev/null; then kill $SPINNER_PID >/dev/null; fi
|
||||
printf "\e[?25h"
|
||||
local msg="$1"
|
||||
echo -e "${BFR}${CM} ${GN}${msg}${CL}"
|
||||
echo -e "${BFR}${CM}${GN}${msg}${CL}"
|
||||
}
|
||||
|
||||
# This function displays a error message with a red color.
|
||||
msg_error() {
|
||||
if [ -n "$SPINNER_PID" ] && ps -p $SPINNER_PID > /dev/null; then kill $SPINNER_PID > /dev/null; fi
|
||||
if [ -n "$SPINNER_PID" ] && ps -p $SPINNER_PID >/dev/null; then kill $SPINNER_PID >/dev/null; fi
|
||||
printf "\e[?25h"
|
||||
local msg="$1"
|
||||
echo -e "${BFR}${CROSS} ${RD}${msg}${CL}"
|
||||
echo -e "${BFR}${CROSS}${RD}${msg}${CL}"
|
||||
}
|
||||
|
||||
while true; do
|
||||
read -p "This will install ${APP} on ${hostname}. Proceed? (y/n): " yn
|
||||
case $yn in
|
||||
[Yy]*) break ;;
|
||||
[Nn]*) msg_info "Installation cancelled."; exit ;;
|
||||
*) msg_info "Please answer yes or no." ;;
|
||||
[Nn]*)
|
||||
msg_error "Installation cancelled."
|
||||
exit
|
||||
;;
|
||||
*) msg_error "Please answer yes or no." ;;
|
||||
esac
|
||||
done
|
||||
|
||||
@ -118,10 +123,11 @@ msg_ok "Installed Dependencies"
|
||||
|
||||
msg_info "Setting up IP-Tag Scripts"
|
||||
mkdir -p /opt/lxc-iptag
|
||||
msg_ok "Setup IP-Tag Scripts"
|
||||
|
||||
msg_info "Setup Default Config"
|
||||
if [[ ! -f /opt/lxc-iptag/iptag.conf ]]; then
|
||||
cat <<EOF > /opt/lxc-iptag/iptag.conf
|
||||
cat <<EOF >/opt/lxc-iptag/iptag.conf
|
||||
# Configuration file for LXC IP tagging
|
||||
|
||||
# List of allowed CIDRs
|
||||
@ -144,7 +150,7 @@ fi
|
||||
|
||||
msg_info "Setup Main Function"
|
||||
if [[ ! -f /opt/lxc-iptag/iptag ]]; then
|
||||
cat <<'EOF' > /opt/lxc-iptag/iptag
|
||||
cat <<'EOF' >/opt/lxc-iptag/iptag
|
||||
#!/bin/bash
|
||||
|
||||
# =============== CONFIGURATION =============== #
|
||||
@ -322,8 +328,7 @@ chmod +x /opt/lxc-iptag/iptag
|
||||
|
||||
msg_info "Creating Service"
|
||||
if [[ ! -f /lib/systemd/system/iptag.service ]]; then
|
||||
echo "Systemd service file not found. Creating it now..."
|
||||
cat <<EOF > /lib/systemd/system/iptag.service
|
||||
cat <<EOF >/lib/systemd/system/iptag.service
|
||||
[Unit]
|
||||
Description=LXC IP-Tag service
|
||||
After=network.target
|
||||
@ -347,5 +352,5 @@ msg_info "Starting Service"
|
||||
systemctl daemon-reload &>/dev/null
|
||||
systemctl enable -q --now iptag.service &>/dev/null
|
||||
msg_ok "Started Service"
|
||||
|
||||
SPINNER_PID=""
|
||||
echo -e "\n${APP} installation completed successfully! ${CL}\n"
|
||||
|
Loading…
Reference in New Issue
Block a user