Skip to content

Commit 1f7d85a

Browse files
authored
[core]: unify misc/*.func scripts with centralized logic from core.func (#5316)
* Core Changes * Formatting * add create_lxc patches * Update install.func * remove dev header
1 parent 4e46fd7 commit 1f7d85a

File tree

7 files changed

+396
-692
lines changed

7 files changed

+396
-692
lines changed

misc/alpine-install.func

Lines changed: 11 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,13 @@
1-
# Copyright (c) 2021-2025 tteck
1+
# Copyright (c) 2021-2025 community-scripts ORG
22
# Author: tteck (tteckster)
33
# 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
8-
color() {
9-
# Colors
10-
YW=$(echo "\033[33m")
11-
BL=$(echo "\033[36m")
12-
RD=$(echo "\033[01;31m")
13-
GN=$(echo "\033[1;92m")
14-
15-
# Formatting
16-
CL=$(echo "\033[m")
17-
BFR="\\r\\033[K"
18-
BOLD=$(echo "\033[1m")
19-
TAB=" "
20-
TAB3=" "
21-
22-
# System
23-
RETRY_NUM=10
24-
RETRY_EVERY=3
25-
i=$RETRY_NUM
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-
HOSTNAME="${TAB}🏠${TAB}${CL}"
34-
GATEWAY="${TAB}🌐${TAB}${CL}"
35-
}
4+
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
365

37-
# Function to set STD mode based on verbosity
38-
set_std_mode() {
39-
if [ "$VERBOSE" = "yes" ]; then
40-
STD=""
41-
else
42-
STD="silent"
43-
fi
44-
}
45-
46-
# Silent execution function
47-
silent() {
48-
"$@" >/dev/null 2>&1
49-
}
6+
if ! command -v curl >/dev/null 2>&1; then
7+
apk update && apk add curl >/dev/null 2>&1
8+
fi
9+
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/core.func)
10+
load_functions
5011

5112
# This function enables IPv6 if it's not disabled and sets verbose mode
5213
verb_ip6() {
@@ -74,33 +35,15 @@ error_handler() {
7435
echo -e "\n$error_message\n"
7536
}
7637

77-
# This function displays an informational message with a yellow color.
78-
msg_info() {
79-
local msg="$1"
80-
echo -ne " ${TAB}${YW}${msg}"
81-
}
82-
83-
# This function displays a success message with a green color.
84-
msg_ok() {
85-
local msg="$1"
86-
echo -e "${BFR}${CM}${GN}${msg}${CL}"
87-
}
88-
89-
# This function displays a error message with a red color.
90-
msg_error() {
91-
local msg="$1"
92-
echo -e "${BFR}${CROSS}${RD}${msg}${CL}"
93-
}
94-
9538
# This function sets up the Container OS by generating the locale, setting the timezone, and checking the network connection
9639
setting_up_container() {
9740
msg_info "Setting up Container OS"
98-
while [ "$i" -gt 0 ]; do
41+
while [ $i -gt 0 ]; do
9942
if [ "$(ip addr show | grep 'inet ' | grep -v '127.0.0.1' | awk '{print $2}' | cut -d'/' -f1)" != "" ]; then
10043
break
10144
fi
10245
echo 1>&2 -en "${CROSS}${RD} No Network! "
103-
sleep "$RETRY_EVERY"
46+
sleep $RETRY_EVERY
10447
i=$((i - 1))
10548
done
10649

@@ -149,10 +92,9 @@ update_os() {
14992

15093
# This function modifies the message of the day (motd) and SSH settings
15194
motd_ssh() {
152-
# Set terminal to 256-color mode
15395
echo "export TERM='xterm-256color'" >>/root/.bashrc
15496
IP=$(ip -4 addr show eth0 | awk '/inet / {print $2}' | cut -d/ -f1 | head -n 1)
155-
# Get OS information
97+
15698
if [ -f "/etc/os-release" ]; then
15799
OS_NAME=$(grep ^NAME /etc/os-release | cut -d= -f2 | tr -d '"')
158100
OS_VERSION=$(grep ^VERSION_ID /etc/os-release | cut -d= -f2 | tr -d '"')
@@ -213,6 +155,6 @@ EOF
213155
msg_ok "Customized Container"
214156
fi
215157

216-
echo "bash -c \"\$(curl -fsSL https://github.com/community-scripts/ProxmoxVE/raw/main/ct/${app}.sh)\"" >/usr/bin/update
158+
echo "bash -c \"\$(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/ct/${app}.sh)\"" >/usr/bin/update
217159
chmod +x /usr/bin/update
218160
}

misc/api.func

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
post_to_api() {
66

7-
if ! command -v curl &> /dev/null; then
7+
if ! command -v curl &>/dev/null; then
88
return
99
fi
1010

@@ -20,7 +20,8 @@ post_to_api() {
2020
local pve_version="not found"
2121
pve_version=$(pveversion | awk -F'[/ ]' '{print $2}')
2222

23-
JSON_PAYLOAD=$(cat <<EOF
23+
JSON_PAYLOAD=$(
24+
cat <<EOF
2425
{
2526
"ct_type": $CT_TYPE,
2627
"type":"lxc",
@@ -37,12 +38,12 @@ post_to_api() {
3738
"random_id": "$RANDOM_UUID"
3839
}
3940
EOF
40-
)
41+
)
4142

4243
if [[ "$DIAGNOSTICS" == "yes" ]]; then
4344
RESPONSE=$(curl -s -w "%{http_code}" -L -X POST "$API_URL" --post301 --post302 \
44-
-H "Content-Type: application/json" \
45-
-d "$JSON_PAYLOAD") || true
45+
-H "Content-Type: application/json" \
46+
-d "$JSON_PAYLOAD") || true
4647
fi
4748
}
4849

@@ -52,7 +53,7 @@ post_to_api_vm() {
5253
return
5354
fi
5455
DIAGNOSTICS=$(grep -i "^DIAGNOSTICS=" /usr/local/community-scripts/diagnostics | awk -F'=' '{print $2}')
55-
if ! command -v curl &> /dev/null; then
56+
if ! command -v curl &>/dev/null; then
5657
return
5758
fi
5859

@@ -70,7 +71,8 @@ post_to_api_vm() {
7071

7172
DISK_SIZE_API=${DISK_SIZE%G}
7273

73-
JSON_PAYLOAD=$(cat <<EOF
74+
JSON_PAYLOAD=$(
75+
cat <<EOF
7476
{
7577
"ct_type": 2,
7678
"type":"vm",
@@ -87,42 +89,43 @@ post_to_api_vm() {
8789
"random_id": "$RANDOM_UUID"
8890
}
8991
EOF
90-
)
92+
)
9193

9294
if [[ "$DIAGNOSTICS" == "yes" ]]; then
9395
RESPONSE=$(curl -s -w "%{http_code}" -L -X POST "$API_URL" --post301 --post302 \
94-
-H "Content-Type: application/json" \
95-
-d "$JSON_PAYLOAD") || true
96+
-H "Content-Type: application/json" \
97+
-d "$JSON_PAYLOAD") || true
9698
fi
9799
}
98100

99101
POST_UPDATE_DONE=false
100102
post_update_to_api() {
101103

102-
if ! command -v curl &> /dev/null; then
103-
return
104-
fi
104+
if ! command -v curl &>/dev/null; then
105+
return
106+
fi
105107

106-
if [ "$POST_UPDATE_DONE" = true ]; then
107-
return 0
108-
fi
109-
local API_URL="http://api.community-scripts.org/upload/updatestatus"
110-
local status="${1:-failed}"
111-
local error="${2:-No error message}"
108+
if [ "$POST_UPDATE_DONE" = true ]; then
109+
return 0
110+
fi
111+
local API_URL="http://api.community-scripts.org/upload/updatestatus"
112+
local status="${1:-failed}"
113+
local error="${2:-No error message}"
112114

113-
JSON_PAYLOAD=$(cat <<EOF
115+
JSON_PAYLOAD=$(
116+
cat <<EOF
114117
{
115118
"status": "$status",
116119
"error": "$error",
117120
"random_id": "$RANDOM_UUID"
118121
}
119122
EOF
120-
)
121-
123+
)
124+
122125
if [[ "$DIAGNOSTICS" == "yes" ]]; then
123126
RESPONSE=$(curl -s -w "%{http_code}" -L -X POST "$API_URL" --post301 --post302 \
124-
-H "Content-Type: application/json" \
125-
-d "$JSON_PAYLOAD") || true
127+
-H "Content-Type: application/json" \
128+
-d "$JSON_PAYLOAD") || true
126129
fi
127130

128131
POST_UPDATE_DONE=true

0 commit comments

Comments
 (0)