forked from community-scripts/ProxmoxVED
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalpine-cloudflared.sh
More file actions
143 lines (125 loc) · 3.8 KB
/
Copy pathalpine-cloudflared.sh
File metadata and controls
143 lines (125 loc) · 3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env bash
# shellcheck source=misc/build.func
source <(curl -s https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/build.func)
# Copyright (c) 2021-2026 community-scripts ORG
# Author: bandogora
# License: MIT | https://github.com/community-scripts/ProxmoxVED/raw/main/LICENSE
# Source: https://www.cloudflare.com/
APP="Alpine-Cloudflared"
var_tags="${var_tags:-network;cloudflare}"
var_cpu="${var_cpu:-1}"
var_ram="${var_ram:-512}"
var_disk="${var_disk:-2}"
var_os="${var_os:-alpine}"
var_version="${var_version:-3.23}"
var_unprivileged="${var_unprivileged:-1}"
var_token="${var_token:-}"
var_config_path="${var_config_path:-/usr/local/etc/cloudflared}"
header_info "$APP"
variables
color
catch_errors
user_configuration() {
token_valid() {
local token="$1"
# Sanitize token of unprintable chars
token=$(echo "$token" | tr -cd '[:print:]')
# Validate token is present and alphanumeric (should be Base64)
if [ -z "$token" ] || ! [[ "$token" =~ ^[[:alnum:]]+$ ]]; then
return 1
fi
# export for use in install script
export TOKEN=$token
}
# If user supplied $var_token and it's valid skip menu
token_valid "$var_token" && return 0
while true; do
local type
if type=$(
whiptail --title "Tunnel Type" \
--menu "Select Tunnel Type:" 9 52 2 \
"remotely-managed" "Uses a token (Recommended)" \
"locally-managed" "Uses a local configuration file" \
3>&1 1>&2 2>&3
); then
# if "remotely-managed" get token from user
if [[ "$type" == "remotely-managed" ]]; then
if var_token=$(
whiptail --title "Tunnel Token" \
--inputbox "Enter Tunnel Token" 10 80 "" \
3>&1 1>&2 2>&3
); then
if token_valid "$var_token"; then
# break to continue script
break
else
# || true to prevent failure on escape key
whiptail --msgbox "Invalid token: contains special characters" 7 46 || true
fi
else
# continue to prevent failure on escape key
continue
fi
else
# export for use in install script and break to continue script
export CONFIG_PATH=$var_config_path
break
fi
else
clear
printf "\e[?25h"
echo -e "\n${CROSS}${RD}User exited script${CL}\n"
kill 0
exit 1
fi
done
}
function update_script() {
header_info
check_container_storage
check_container_resources
# Check if installation is present
if [[ ! -f /etc/init.d/cloudflared ]]; then
msg_error "No ${APP} Installation Found!"
exit
fi
# Stopping Services
msg_info "Stopping $APP"
rc-service cloudflared stop
msg_ok "Stopped $APP"
# Execute Update
msg_info "Updating $APP"
$STD apk -U upgrade
$STD cloudflared update
msg_ok "Updated $APP to $(cloudflared -V)"
# Starting Services
msg_info "Starting $APP"
rc-service cloudflared start
msg_ok "Started $APP"
# Cleaning up
msg_info "Cleaning Up"
$STD apk cache clean
find /var/log -type f -delete 2>/dev/null
find /tmp -mindepth 1 -delete 2>/dev/null
$STD apk update
msg_ok "Cleanup Completed"
# Last Action
msg_ok "Update Successful"
exit
}
start
user_configuration
if [ -z "$var_token" ]; then
echo -e "${TAB}📝${TAB}${BOLD}${DGN}Tunnel Config: ${BGN}${CONFIG_PATH}/config.yml${CL}"
else
echo -e "${TAB}🪪${TAB}${BOLD}${DGN}Tunnel Token: ${BGN}${TOKEN:0:33}...${CL}"
fi
build_container
description
msg_ok "Completed successfully!\n"
echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}"
if [ -z "$var_token" ]; then
echo -e "${INFO}${YW} Edit the config file at:${CL}"
echo -e "${TAB}${ADVANCED}${GN} ${var_config_path}/config.yml${CL}"
echo -e "${INFO}${BGN}Run \"rc-service cloudflared start\" to start!${CL}"
fi