-
-
Notifications
You must be signed in to change notification settings - Fork 429
Expand file tree
/
Copy pathremote_install.sh
More file actions
144 lines (121 loc) · 2.88 KB
/
remote_install.sh
File metadata and controls
144 lines (121 loc) · 2.88 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
144
#!/usr/bin/env sh
# UniFi Data Directory
DATA_DIR="/data"
# A change in the name udm-boot would need to be reflected as well in systemctl calls.
SYSTEMCTL_PATH="/etc/systemd/system/udm-boot.service"
SYMLINK_SYSTEMCTL="/etc/systemd/system/multi-user.target.wants/udm-boot.service"
SERVICE_META_URL="https://raw.githubusercontent.com/unifi-utilities/unifi-common/HEAD/udm-boot.service"
# --- Functions ---
header() {
cat <<EOF
___ ___ _
/ _ \ _ _ | _ ) ___ ___ | |_
| (_) || ' \ | _ \/ _ \/ _ \| _|
\___/ |_||_||___/\___/\___/ \__|
Execute any script when your system
starts.
EOF
}
command_exists() {
command -v "${1:-}" >/dev/null 2>&1
}
depends_on() {
! command_exists "${1:-}" && echo "Missing dependency: \`$*\`" 1>&2 && exit 1
}
udm_model() {
case "$(ubnt-device-info model || true)" in
"UniFi Dream Machine SE")
echo "udmse"
;;
"UniFi Dream Machine Pro")
echo "udmpro"
;;
"UniFi Dream Machine")
echo "udm"
;;
"UniFi Dream Router")
echo "udr"
;;
"UniFi Dream Router 7")
echo "udr7"
;;
"UniFi Dream Machine Pro Max")
echo "udmpromax"
;;
"UniFi Cloud Gateway Ultra")
echo "ucgult"
;;
"UniFi Cloud Gateway Max")
echo "uxgmax"
;;
"UniFi Express")
echo "ux"
;;
"UniFi Express 7")
echo "ux7"
;;
"UniFi Cloud Gateway Fiber")
echo "ucgfiber"
;;
"UniFi NeXt-Gen Gateway Fiber")
echo "uxgfiber"
;;
"Enterprise Fortress Gateway")
echo "udment"
;;
*)
echo "unknown"
;;
esac
}
# download_on_path <path> <url>
download_on_path() {
[ $# -lt 2 ] &&
echo "Missing arguments: \`$*\`" 1>&2 &&
return 1
curl -sLJo "$1" "$2"
[ -r "$1" ]
}
install_on_boot_udr_se() {
systemctl disable udm-boot 2>/dev/null || true
systemctl daemon-reload
rm -f "$SYMLINK_SYSTEMCTL"
echo "Creating systemctl service file"
if ! download_on_path "$SYSTEMCTL_PATH" "$SERVICE_META_URL"; then
echo
echo "Failed to download on-boot script service" 1>&2
exit 1
fi
sleep 1s
echo "Enabling UDM boot..."
systemctl daemon-reload
systemctl enable "udm-boot"
systemctl start "udm-boot"
[ -e "$SYMLINK_SYSTEMCTL" ]
}
header
depends_on ubnt-device-info
depends_on curl
ON_BOOT_D_PATH="${DATA_DIR}/on_boot.d"
case "$(udm_model)" in
udr | udmse | udm | udmpro | udmpromax | uxgmax | ucgult | ucgfiber | ux | uxgfiber | udr7 | ux7 | udment)
echo "$(ubnt-device-info model) version $(ubnt-device-info firmware) was detected"
echo "Installing on-boot script..."
depends_on systemctl
if ! install_on_boot_udr_se; then
echo
echo "Failed to install on-boot script service" 1>&2
exit 1
fi
echo "UDM Boot Script installed"
;;
*)
echo "Unsupported model: $(ubnt-device-info model)" 1>&2
exit 1
;;
esac
echo
echo "On boot script installation finished"
echo
echo "You can now place your scripts in \`${ON_BOOT_D_PATH}\`"
echo