-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·173 lines (158 loc) · 7.53 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·173 lines (158 loc) · 7.53 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
#!/usr/bin/env bash
# TUS installer — Telegram Username Sniper
# Usage:
# curl -fsSL https://raw.githubusercontent.com/ixode0/TUS/main/install.sh | bash
# curl -fsSL .../install.sh | bash -s -- --api-id 123 --api-hash abc --phone +1234567890 --usernames user1,user2
#
# Respects: TUS_VERSION (default: latest), INSTALL_DIR (default: ~/.local/bin),
# TUS_CONFIG_DIR (default: ~/.config/tus), API_ID, API_HASH, PHONE,
# USERNAMES (comma-separated), CLAIM_TO (default: channel), SLEEP_MS.
set -euo pipefail
REPO="ixode0/TUS"
BIN_NAME="sniper"
WRAPPER="tus"
INSTALL_DIR="${INSTALL_DIR:-$HOME/.local/bin}"
TUS_CONFIG_DIR="${TUS_CONFIG_DIR:-$HOME/.config/tus}"
VERSION="${TUS_VERSION:-latest}"
API_ID="${API_ID:-}"; API_HASH="${API_HASH:-}"; PHONE="${PHONE:-}"
USERNAMES="${USERNAMES:-}"; CLAIM_TO="${CLAIM_TO:-}"; SLEEP_MS="${SLEEP_MS:-}"
UNINSTALL=0
log() { printf '[tus-install] %s\n' "$*"; }
die() { printf '[tus-install] ERROR: %s\n' "$*" >&2; exit 1; }
usage() {
cat <<EOF
TUS installer (Linux/macOS). Windows: use install.ps1.
Options:
--api-id ID --api-hash HASH --phone +123... --usernames a,b[,c]
--claim-to channel|user --sleep-ms N --version vX.Y.Z|latest
--dir PATH (binary dir, default ~/.local/bin)
--config-dir PATH (default ~/.config/tus)
--uninstall --help
Env equivalents: API_ID API_HASH PHONE USERNAMES CLAIM_TO SLEEP_MS TUS_VERSION.
EOF
}
while [ $# -gt 0 ]; do
case "$1" in
--api-id) API_ID="${2:?}"; shift 2;;
--api-hash) API_HASH="${2:?}"; shift 2;;
--phone) PHONE="${2:?}"; shift 2;;
--usernames) USERNAMES="${2:?}"; shift 2;;
--claim-to) CLAIM_TO="${2:?}"; shift 2;;
--sleep-ms) SLEEP_MS="${2:?}"; shift 2;;
--version) VERSION="${2:?}"; shift 2;;
--dir) INSTALL_DIR="${2:?}"; shift 2;;
--config-dir) TUS_CONFIG_DIR="${2:?}"; shift 2;;
--uninstall) UNINSTALL=1; shift;;
-h|--help) usage; exit 0;;
*) die "unknown flag $1 (see --help)";;
esac
done
# --- platform detection -------------------------------------------------------
OS="$(uname -s)"; ARCH="$(uname -m)"
case "$OS" in
Linux) PLAT="linux";;
Darwin) PLAT="darwin";;
*) die "unsupported OS: $OS. Windows users: run install.ps1.";;
esac
case "$ARCH" in
x86_64|amd64) ARCH="amd64";;
aarch64|arm64) ARCH="arm64";;
*) die "unsupported arch: $ARCH (supported: amd64/arm64 or build: go build -o sniper ./cmd/app)";;
esac
ASSET="sniper-${PLAT}-${ARCH}"
need() { command -v "$1" >/dev/null 2>&1 || die "missing dependency: $1"; }
if command -v curl >/dev/null 2>&1; then
download() { curl -fsSL "$1" -o "$2"; }
elif command -v wget >/dev/null 2>&1; then
download() { wget -q "$1" -O "$2"; }
else
die "need curl or wget"
fi
if command -v sha256sum >/dev/null 2>&1; then SHA="sha256sum"; elif command -v shasum >/dev/null 2>&1; then SHA="shasum -a 256"; else die "need sha256sum or shasum"; fi
if [ "$UNINSTALL" = 1 ]; then
rm -f "$INSTALL_DIR/$BIN_NAME" "$INSTALL_DIR/$WRAPPER"
log "binaries removed (config kept at $TUS_CONFIG_DIR — delete manually if needed)"
exit 0
fi
# --- resolve version ----------------------------------------------------------
if [ "$VERSION" = "latest" ]; then
log "resolving latest release..."
TMP_API="$(mktemp)"; trap 'rm -rf "$TMP" "$TMP_API"' EXIT
download "https://api.github.com/repos/$REPO/releases/latest" "$TMP_API"
VERSION="$(grep -m1 '"tag_name"' "$TMP_API" | cut -d'"' -f4)"
[ -n "${VERSION:-}" ] || die "cannot resolve latest version (set --version vX.Y.Z)"
fi
log "installing TUS $VERSION for $PLAT/$ARCH"
# --- download + verify --------------------------------------------------------
TMP="$(mktemp -d)"; trap 'rm -rf "$TMP" "${TMP_API:-}"' EXIT
BASE="https://github.com/$REPO/releases/download/$VERSION"
download "$BASE/$ASSET" "$TMP/$ASSET" || die "Релиза под твою систему пока нет ($ASSET, version $VERSION). Собери сам: git clone https://github.com/$REPO.git && cd TUS && go build -o sniper ./cmd/app"
download "$BASE/SHA256SUMS.txt" "$TMP/SHA256SUMS.txt" || die "Релиза под твою систему пока нет (SHA256SUMS.txt, version $VERSION). Собери сам: git clone https://github.com/$REPO.git && cd TUS && go build -o sniper ./cmd/app"
(cd "$TMP" && grep " $ASSET\$" SHA256SUMS.txt | $SHA -c -) || die "checksum mismatch for $ASSET (delete TMP, retry or build from source: git clone https://github.com/$REPO.git && cd TUS && go build -o sniper ./cmd/app)"
mkdir -p "$INSTALL_DIR" "$TUS_CONFIG_DIR"
install -m 0755 "$TMP/$ASSET" "$INSTALL_DIR/$BIN_NAME"
# --- launcher (config/session live in XDG dir, not next to the binary) --------
cat > "$INSTALL_DIR/$WRAPPER" <<EOF
#!/usr/bin/env sh
# generated by TUS install.sh $VERSION — do not edit
export CONFIG_PATH="$TUS_CONFIG_DIR/config.json"
export SESSION_PATH="$TUS_CONFIG_DIR/session_DO_NOT_SHARE.json"
exec "$INSTALL_DIR/$BIN_NAME" "\$@"
EOF
chmod +x "$INSTALL_DIR/$WRAPPER"
# --- config -------------------------------------------------------------------
prompt() { # $1=var $2=text $3=default — always asks on a tty (Enter keeps default)
[ -n "$(eval echo "\$$1")" ] && return 0
if [ -n "$3" ]; then
if [ -t 0 ]; then
printf '%s [%s]: ' "$2" "$3" >&2; IFS= read -r val
if [ -n "$val" ]; then eval "$1=\"$val\""; else eval "$1=\"$3\""; fi
return 0
fi
eval "$1=\"$3\""; return 0
fi
[ -t 0 ] && { printf '%s: ' "$2" >&2; IFS= read -r val; eval "$1=\"$val\""; return 0; }
return 1
}
write_template() {
printf '{\n "telegram": {"phone_number": "", "api_id": 0, "api_hash": ""},\n "claim_to": "channel",\n "sleep_between_check": 100,\n "usernames": ["your_username"]\n}\n' > "$CONFIG"
chmod 600 "$CONFIG"
}
have_values() { [ -n "$API_ID" ] && [ "$API_ID" != "0" ] && [ -n "$API_HASH" ] && [ -n "$PHONE" ] && [ -n "$USERNAMES" ]; }
CONFIG="$TUS_CONFIG_DIR/config.json"
if [ ! -f "$CONFIG" ]; then
if ! have_values; then
if [ -t 0 ]; then
prompt API_ID "API ID (my.telegram.org)" "" || true
prompt API_HASH "API Hash" "" || true
prompt PHONE "Phone (+123...)" "" || true
prompt USERNAMES "Usernames (comma-separated, no @)" "" || true
prompt CLAIM_TO "Claim to (channel|user)" "channel" || true
prompt SLEEP_MS "Delay ms" "100" || true
fi
fi
# Non-interactive fallback: prompt() already defaults these, but keep
# the heredoc below safe when flags/env left them empty.
: "${CLAIM_TO:=channel}"
: "${SLEEP_MS:=100}"
case "$CLAIM_TO" in channel|user) ;; *) log "unknown claim_to '$CLAIM_TO', using 'channel'"; CLAIM_TO="channel";; esac
case "$SLEEP_MS" in ''|*[!0-9]*) log "bad delay '$SLEEP_MS', using 100"; SLEEP_MS="100";; esac
if have_values && command -v python3 >/dev/null 2>&1; then
USERNAMES_JSON="$(printf '%s' "$USERNAMES" | tr ',' '\n' | sed 's/^ *//;s/ *$//' | grep . | sed 's/.*/"&"/' | paste -sd, -)"
python3 - "$CONFIG" <<EOF
import json,sys
p=sys.argv[1]
cfg={"telegram":{"phone_number":"$PHONE","api_id":$API_ID,"api_hash":"$API_HASH"},"claim_to":"$CLAIM_TO","sleep_between_check":$SLEEP_MS,"usernames":[${USERNAMES_JSON:-}]}
assert cfg["telegram"]["phone_number"].startswith("+"), "phone must start with +"
assert cfg["usernames"], "at least one username required"
json.dump(cfg,open(p,"w"),indent=2)
EOF
chmod 600 "$CONFIG"
log "config written to $CONFIG (mode 600)"
else
write_template
log "config template at $CONFIG — fill api_id/api_hash/phone/usernames before running"
fi
fi
case ":$PATH:" in *":$INSTALL_DIR:"*) ;; *) log "add to PATH: export PATH=\"\$PATH:$INSTALL_DIR\" (or reopen shell)";; esac
log "done. Run: $WRAPPER (first launch asks for Telegram login code)"