forked from zippyy/GL.iNet-CellularModels-SMSonBoot
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall_combined.sh
More file actions
124 lines (103 loc) · 3.2 KB
/
install_combined.sh
File metadata and controls
124 lines (103 loc) · 3.2 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
#!/bin/sh
set -eu
REPO_RAW_BASE="https://raw.githubusercontent.com/techrelay/GL.iNet-CellularModels-SMSonBoot/main"
CONF="/etc/sms_on_boot_combined.conf"
PREFER=""
PHONE=""
TEXTBELT_KEY=""
WEBHOOK_URL=""
usage() {
cat <<'EOF'
SMS on Boot - Combined Installer
Interactive:
install_combined.sh
Non-interactive:
install_combined.sh --prefer textbelt|sendsms --phone +17192291657 [--textbelt-key KEY] [--webhook-url URL]
Examples:
install_combined.sh --prefer textbelt --phone +17192291657 --textbelt-key textbelt
install_combined.sh --prefer sendsms --phone +17192291657
install_combined.sh --prefer textbelt --phone +17192291657 --textbelt-key textbelt --webhook-url https://example.com
EOF
}
# Parse args (if any)
while [ $# -gt 0 ]; do
case "$1" in
-h|--help) usage; exit 0 ;;
--prefer) PREFER="${2:-}"; shift 2 ;;
--phone) PHONE="${2:-}"; shift 2 ;;
--textbelt-key) TEXTBELT_KEY="${2:-}"; shift 2 ;;
--webhook-url) WEBHOOK_URL="${2:-}"; shift 2 ;;
--) shift; break ;;
*) echo "Unknown arg: $1" >&2; usage; exit 1 ;;
esac
done
if [ "$(id -u)" -ne 0 ]; then
echo "Run as root." >&2
exit 1
fi
if ! command -v curl >/dev/null 2>&1; then
echo "ERROR: curl not found. Install requires curl access." >&2
exit 1
fi
# If not enough args, go interactive
if [ -z "${PREFER:-}" ] || [ -z "${PHONE:-}" ]; then
echo
echo "SMS on Boot - Combined Installer"
echo "--------------------------------"
echo "Choose which provider to try FIRST:"
echo " 1) Textbelt (HTTPS API; good for non-cellular models)"
echo " 2) sendsms (local SIM; cellular models only)"
echo
printf "Enter 1 or 2: "
read choice
if [ "$choice" = "2" ]; then
PREFER="sendsms"
else
PREFER="textbelt"
fi
printf "Destination phone number (E.164, e.g. +17192291657): "
read PHONE
echo "Textbelt key (optional). Leave blank to skip Textbelt."
echo "You can also use: textbelt (limited free tier)"
printf "Textbelt key: "
read TEXTBELT_KEY
echo "Webhook URL (optional). Leave blank to skip."
printf "Webhook URL: "
read WEBHOOK_URL
fi
# Validate
if [ -z "${PHONE:-}" ]; then
echo "ERROR: phone number is required." >&2
exit 1
fi
if [ "$PREFER" != "textbelt" ] && [ "$PREFER" != "sendsms" ]; then
echo "ERROR: --prefer must be textbelt or sendsms." >&2
exit 1
fi
echo "[*] Downloading sms_on_boot_combined.sh..."
curl -fsSL "$REPO_RAW_BASE/sms_on_boot_combined.sh" -o /usr/bin/sms_on_boot_combined.sh
chmod +x /usr/bin/sms_on_boot_combined.sh
echo "[*] Writing config $CONF ..."
# Write config without sed, so special characters in the key never break anything.
umask 077
{
echo "PHONE=\"$PHONE\""
echo "PREFER=\"$PREFER\""
echo "TEXTBELT_KEY=\"$TEXTBELT_KEY\""
echo "WEBHOOK_URL=\"$WEBHOOK_URL\""
} > "$CONF"
echo "[*] Creating init.d service..."
cat > /etc/init.d/sms_on_boot_combined <<'EOF'
#!/bin/sh /etc/rc.common
START=99
start() {
/usr/bin/sms_on_boot_combined.sh &
}
EOF
chmod +x /etc/init.d/sms_on_boot_combined
/etc/init.d/sms_on_boot_combined enable
echo "[OK] Installed Combined version."
echo "To test immediately (no reboot required):"
echo " rm -f /etc/sms_on_boot_combined.last"
echo " /usr/bin/sms_on_boot_combined.sh"
echo " cat /tmp/sms_on_boot_combined.log"