1+ # Copyright (c) 2021-2024 tteck
2+ # Author: tteck (tteckster)
3+ # Co-Author: MickLesk
4+ # License: MIT
5+ # https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
6+
7+ # This function sets color variables for formatting output in the terminal
18color() {
9+ # Colors
210 YW=$(echo "\033[33m")
11+ YWB=$(echo "\033[93m")
312 BL=$(echo "\033[36m")
413 RD=$(echo "\033[01;31m")
5- BGN=$(echo "\033[4;92m")
614 GN=$(echo "\033[1;92m")
7- DGN=$(echo "\033[32m")
15+
16+ # Formatting
817 CL=$(echo "\033[m")
18+ BFR="\\r\\033[K"
19+ BOLD=$(echo "\033[1m")
20+ TAB=" "
21+
22+ # System
923 RETRY_NUM=10
1024 RETRY_EVERY=3
1125 i=$RETRY_NUM
12- CM="${GN}✓${CL}"
13- CROSS="${RD}✗${CL}"
14- BFR="\\r\\033[K"
15- HOLD="-"
26+
27+ # Icons
28+ CM="${TAB}✔️${TAB}${CL}"
29+ CROSS="${TAB}✖️${TAB}${CL}"
30+ INFO="${TAB}💡${TAB}${CL}"
31+ NETWORK="${TAB}📡${TAB}${CL}"
32+ OS="${TAB}🖥️${TAB}${CL}"
33+ OSVERSION="${TAB}🌟${TAB}${CL}"
34+ HOSTNAME="${TAB}🏠${TAB}${CL}"
35+ GATEWAY="${TAB}🌐${TAB}${CL}"
36+ DEFAULT="${TAB}⚙️${TAB}${CL}"
1637}
1738
39+ # This function enables IPv6 if it's not disabled and sets verbose mode if the global variable is set to "yes"
1840verb_ip6() {
1941 if [ "$VERBOSE" = "yes" ]; then
2042 STD=""
@@ -27,11 +49,13 @@ verb_ip6() {
2749 fi
2850}
2951
52+ # This function catches errors and handles them with the error handler function
3053catch_errors() {
3154 set -Eeuo pipefail
3255 trap 'error_handler $LINENO "$BASH_COMMAND"' ERR
3356}
3457
58+ # This function handles errors
3559error_handler() {
3660 local exit_code="$?"
3761 local line_number="$1"
@@ -40,21 +64,25 @@ error_handler() {
4064 echo -e "\n$error_message\n"
4165}
4266
67+ # This function displays an informational message with a yellow color.
4368msg_info() {
4469 local msg="$1"
45- echo -ne " ${HOLD} ${YW}${msg}... "
70+ echo -ne " ${TAB} ${YW}${msg}"
4671}
4772
73+ # This function displays a success message with a green color.
4874msg_ok() {
4975 local msg="$1"
50- echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
76+ echo -e "${BFR}${CM}${GN}${msg}${CL}"
5177}
5278
79+ # This function displays a error message with a red color.
5380msg_error() {
5481 local msg="$1"
55- echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}"
82+ echo -e "${BFR}${CROSS}${RD}${msg}${CL}"
5683}
5784
85+ # This function sets up the Container OS by generating the locale, setting the timezone, and checking the network connection
5886setting_up_container() {
5987 msg_info "Setting up Container OS"
6088 while [ $i -gt 0 ]; do
@@ -68,23 +96,26 @@ setting_up_container() {
6896
6997 if [ "$(ip addr show | grep 'inet ' | grep -v '127.0.0.1' | awk '{print $2}' | cut -d'/' -f1)" = "" ]; then
7098 echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}"
71- echo -e " 🖧 Check Network Settings"
99+ echo -e "${NETWORK} Check Network Settings"
72100 exit 1
73101 fi
74102 msg_ok "Set up Container OS"
75103 msg_ok "Network Connected: ${BL}$(ip addr show | grep 'inet ' | awk '{print $2}' | cut -d'/' -f1 | tail -n1)${CL}"
76104}
77105
106+ # This function checks the network connection by pinging a known IP address and prompts the user to continue if the internet is not connected
78107network_check() {
79108 set +e
80109 trap - ERR
81- if ping -c 1 -W 1 1.1.1.1 &>/dev/null; then msg_ok "Internet Connected"; else
110+ if ping -c 1 -W 1 1.1.1.1 &>/dev/null || ping -c 1 -W 1 8.8.8.8 &>/dev/null || ping -c 1 -W 1 9.9.9.9 &>/dev/null; then
111+ msg_ok "Internet Connected";
112+ else
82113 msg_error "Internet NOT Connected"
83114 read -r -p "Would you like to continue anyway? <y/N> " prompt
84115 if [[ "${prompt,,}" =~ ^(y|yes)$ ]]; then
85- echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}"
116+ echo -e "${INFO} ${RD}Expect Issues Without Internet${CL}"
86117 else
87- echo -e " 🖧 Check Network Settings"
118+ echo -e "${NETWORK} Check Network Settings"
88119 exit 1
89120 fi
90121 fi
@@ -94,27 +125,54 @@ network_check() {
94125 trap 'error_handler $LINENO "$BASH_COMMAND"' ERR
95126}
96127
128+ # This function updates the Container OS by running apt-get update and upgrade
97129update_os() {
98130 msg_info "Updating Container OS"
99131 $STD apk update
100132 $STD apk upgrade
101133 msg_ok "Updated Container OS"
102134}
103135
136+ # This function modifies the message of the day (motd) and SSH settings
104137motd_ssh() {
138+ # Set terminal to 256-color mode
105139 echo "export TERM='xterm-256color'" >>/root/.bashrc
106- echo -e "$APPLICATION LXC provided by https://Helper-Scripts.com/\n" >/etc/motd
140+ IP=$(ip -4 addr show eth0 | awk '/inet / {print $2}' | cut -d/ -f1 | head -n 1)
141+ # Get OS information
142+ if [ -f "/etc/os-release" ]; then
143+ OS_NAME=$(grep ^NAME /etc/os-release | cut -d= -f2 | tr -d '"')
144+ OS_VERSION=$(grep ^VERSION_ID /etc/os-release | cut -d= -f2 | tr -d '"')
145+ else
146+ OS_NAME="Alpine Linux"
147+ OS_VERSION="Unknown"
148+ fi
149+ # Set MOTD with application info and system details
150+ MOTD_FILE="/etc/motd"
151+ if [ -f "$MOTD_FILE" ]; then
152+ echo -e "\n${BOLD}${APPLICATION} LXC Container${CL}" > "$MOTD_FILE"
153+ echo -e "${TAB}${GATEWAY}${YW} Provided by: ${GN}community-scripts ORG ${YW}| Project: ${GN}ProxmoxVE ${YW}| GitHub: ${GN}https://github.com/community-scripts/ProxmoxVE${CL}\n" >> "$MOTD_FILE"
154+ echo -e "${TAB}${OS}${YW} OS: ${GN}${OS_NAME} ${OS_VERSION}${CL}" >> "$MOTD_FILE"
155+ echo -e "${TAB}${HOSTNAME}${YW} Hostname: ${GN}$(hostname)${CL}" >> "$MOTD_FILE"
156+ echo -e "${TAB}${INFO}${YW} IP Address: ${GN}${IP}${CL}" >> "$MOTD_FILE"
157+ else
158+ echo -e "${RD}[WARNING] MOTD file does not exist!${CL}" >&2
159+ fi
160+ # Configure SSH if enabled
107161 if [[ "${SSH_ROOT}" == "yes" ]]; then
162+ # Enable sshd service
108163 $STD rc-update add sshd
164+ # Allow root login via SSH
109165 sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config
166+ # Start the sshd service
110167 $STD /etc/init.d/sshd start
111168 fi
112169}
113170
171+ # This function customizes the container and enables passwordless login for the root user
114172customize() {
115173 if [[ "$PASSWORD" == "" ]]; then
116174 msg_info "Customizing Container"
117175 bash -c "passwd -d root" >/dev/null 2>&1
118176 msg_ok "Customized Container"
119177 fi
120- }
178+ }
0 commit comments