-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathinstaller.sh
More file actions
executable file
·275 lines (241 loc) · 8.09 KB
/
Copy pathinstaller.sh
File metadata and controls
executable file
·275 lines (241 loc) · 8.09 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#!/bin/bash
# Telepipe Installer Script - Version 1.1.0
if [ -t 1 ] && command -v clear >/dev/null 2>&1; then
clear
fi
echo "Welcome to this Telepipe installer!"
echo
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) || exit 1
TELEPIPE_SOURCE="${SCRIPT_DIR}/telepipe"
if [ ! -f "$TELEPIPE_SOURCE" ]; then
echo "Error: Could not find the telepipe executable at $TELEPIPE_SOURCE" >&2
exit 1
fi
if [ "$EUID" -eq 0 ]; then
INSTALL_MODE="system"
BIN_DIR="/usr/local/bin"
CONFIG_DIR="/etc/telepipe"
CONFIG_DIR_MODE="755"
else
INSTALL_MODE="user"
if [ -z "${HOME:-}" ]; then
echo "Error: HOME is not set; cannot determine user installation paths." >&2
exit 1
fi
BIN_DIR="$HOME/.local/bin"
CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/telepipe"
CONFIG_DIR_MODE="700"
fi
INSTALL_PATH="${BIN_DIR}/telepipe"
CONFIG_FILE="${CONFIG_DIR}/config"
install_curl_for_system() {
echo "curl not found. Installing it for the system..."
if command -v apt-get >/dev/null 2>&1; then
apt-get update && apt-get install -y curl
elif command -v dnf >/dev/null 2>&1; then
dnf install -y curl
elif command -v yum >/dev/null 2>&1; then
yum install -y curl
elif command -v apk >/dev/null 2>&1; then
apk add curl
elif command -v pacman >/dev/null 2>&1; then
pacman -Sy --noconfirm curl
elif command -v brew >/dev/null 2>&1; then
brew install curl
else
echo "Error: No supported package manager was detected." >&2
echo "Install curl with your operating system's package manager, then rerun the installer." >&2
return 1
fi
}
explain_user_curl_install() {
echo "Error: curl is required, but it is not installed." >&2
echo "Telepipe will not use sudo or otherwise elevate privileges in user mode." >&2
if command -v apt-get >/dev/null 2>&1; then
echo "Install it with: sudo apt-get update && sudo apt-get install curl" >&2
elif command -v dnf >/dev/null 2>&1; then
echo "Install it with: sudo dnf install curl" >&2
elif command -v yum >/dev/null 2>&1; then
echo "Install it with: sudo yum install curl" >&2
elif command -v apk >/dev/null 2>&1; then
echo "Install it with: sudo apk add curl" >&2
elif command -v pacman >/dev/null 2>&1; then
echo "Install it with: sudo pacman -S curl" >&2
else
echo "Install curl with your operating system's package manager, then rerun the installer." >&2
fi
}
echo "Installation mode: ${INSTALL_MODE}"
echo "Checking for dependencies..."
if ! command -v curl >/dev/null 2>&1; then
if [ "$INSTALL_MODE" = "system" ]; then
if ! install_curl_for_system || ! command -v curl >/dev/null 2>&1; then
echo "Error: curl could not be installed. Install it manually, then rerun the installer." >&2
exit 1
fi
elif command -v brew >/dev/null 2>&1; then
echo "curl not found. Installing it with Homebrew (without sudo)..."
if ! brew install curl || ! command -v curl >/dev/null 2>&1; then
echo "Error: Homebrew could not install curl. Run 'brew install curl', then rerun the installer." >&2
exit 1
fi
else
explain_user_curl_install
exit 1
fi
fi
echo "Creating directories..."
if ! install -d -m 755 "$BIN_DIR"; then
echo "Error: Could not create executable directory $BIN_DIR" >&2
exit 1
fi
if ! install -d -m "$CONFIG_DIR_MODE" "$CONFIG_DIR"; then
echo "Error: Could not create configuration directory $CONFIG_DIR" >&2
exit 1
fi
echo
echo "Please provide your Telegram bot token"
echo "(get it from BotFather https://t.me/botfather; input will be hidden):"
read -r -s BOT_TOKEN
echo
if [ -z "$BOT_TOKEN" ]; then
echo "Error: The Telegram bot token cannot be empty." >&2
exit 1
fi
echo
echo "Please provide your Telegram chat ID:"
read -r CHAT_ID
if [ -z "$CHAT_ID" ]; then
echo "Error: The Telegram chat ID cannot be empty." >&2
exit 1
fi
echo
echo "Maximum message length before sending as file:"
echo " 1) 1024 characters"
echo " 2) 4096 characters (recommended)"
echo " 3) 8192 characters"
echo " 4) Specify custom length"
echo "Max length [2]: "
read -r max_len_choice
case $max_len_choice in
1) MAX_LEN=1024 ;;
3) MAX_LEN=8192 ;;
4)
echo "Enter custom length: "
read -r MAX_LEN
;;
*) MAX_LEN=4096 ;;
esac
if ! [[ "$MAX_LEN" =~ ^[1-9][0-9]*$ ]]; then
echo "Error: Maximum message length must be a positive integer." >&2
exit 1
fi
echo
echo "Request timeout in seconds:"
echo " 1) 3 seconds"
echo " 2) 5 seconds (recommended)"
echo " 3) 10 seconds"
echo " 4) Specify custom timeout"
echo "Timeout [2]: "
read -r timeout_choice
case $timeout_choice in
1) TIMEOUT=3 ;;
3) TIMEOUT=10 ;;
4)
echo "Enter custom timeout: "
read -r TIMEOUT
;;
*) TIMEOUT=5 ;;
esac
if ! [[ "$TIMEOUT" =~ ^[1-9][0-9]*$ ]]; then
echo "Error: Request timeout must be a positive integer." >&2
exit 1
fi
echo
echo "Should Telepipe disable link previews in Telegram?"
echo " 1) Yes (recommended)"
echo " 2) No"
echo "Disable link previews [1]: "
read -r preview_choice
case $preview_choice in
2) DISABLE_LINK_PREVIEW=false ;;
*) DISABLE_LINK_PREVIEW=true ;;
esac
CONFIG_TMP=""
cleanup() {
if [ -n "$CONFIG_TMP" ]; then
rm -f "$CONFIG_TMP"
fi
}
trap cleanup EXIT
echo
echo "Creating configuration file..."
umask 077
CONFIG_TMP=$(mktemp "${CONFIG_DIR}/.config.XXXXXX") || {
echo "Error: Could not create a temporary configuration file in $CONFIG_DIR" >&2
exit 1
}
if ! chmod 600 "$CONFIG_TMP"; then
echo "Error: Could not secure temporary configuration file $CONFIG_TMP" >&2
exit 1
fi
{
printf '%s\n' '# Telepipe Configuration File' ''
printf '%s\n' '# Your Telegram Bot Token' '# Get it from BotFather (https://t.me/botfather)'
printf 'BOT_TOKEN=%q\n\n' "$BOT_TOKEN"
printf '%s\n' '# Telegram Chat ID' '# For channels/groups with -100 prefix, use the full ID including -100'
printf 'CHAT_ID=%q\n\n' "$CHAT_ID"
printf '%s\n' '# Maximum message length before sending as a file (in characters)' '# Default: 4096'
printf 'MAX_LEN=%q\n\n' "$MAX_LEN"
printf '%s\n' '# Request timeout in seconds' '# Default: 5'
printf 'TIMEOUT=%q\n\n' "$TIMEOUT"
printf '%s\n' '# Whether to disable link previews in Telegram (true/false)' '# Default: true'
printf 'DISABLE_LINK_PREVIEW=%q\n' "$DISABLE_LINK_PREVIEW"
} > "$CONFIG_TMP"
if ! mv -f "$CONFIG_TMP" "$CONFIG_FILE"; then
echo "Error: Could not install configuration file at $CONFIG_FILE" >&2
exit 1
fi
CONFIG_TMP=""
if ! chmod 600 "$CONFIG_FILE"; then
echo "Error: Could not secure configuration file $CONFIG_FILE" >&2
exit 1
fi
echo "Installing telepipe to $INSTALL_PATH..."
if ! install -m 755 "$TELEPIPE_SOURCE" "$INSTALL_PATH"; then
echo "Error: Could not install telepipe at $INSTALL_PATH" >&2
exit 1
fi
echo
echo "Testing connection to Telegram API..."
if curl -s -m 10 -o /dev/null -w "%{http_code}" "https://api.telegram.org/bot${BOT_TOKEN}/getMe" | grep -q "200"; then
echo "Connection successful! Bot token appears valid."
else
echo "Warning: Could not verify bot token. Continuing installation anyway."
echo "Please check your network connection and bot token later."
fi
echo
echo "Installation completed!"
echo
echo "Usage:"
echo " echo \"Hello World\" | telepipe"
echo " cat file.txt | telepipe"
echo " command | telepipe"
echo " command | telepipe --quiet # No output if successful"
echo " telepipe --interactive # Start interactive multi-line messaging session"
echo
echo "Configuration file: $CONFIG_FILE"
echo "Binary location: $INSTALL_PATH"
if [ "$INSTALL_MODE" = "user" ]; then
case ":${PATH:-}:" in
*":${BIN_DIR}:"*) ;;
*)
echo
echo "Note: $BIN_DIR is not currently on PATH."
echo "Add this line to the startup file for your shell, then open a new terminal:"
printf ' export PATH="%s:$PATH"\n' "$BIN_DIR"
echo "The installer did not modify any shell startup files."
;;
esac
fi
echo