-
Notifications
You must be signed in to change notification settings - Fork 204
Expand file tree
/
Copy pathsetup
More file actions
113 lines (94 loc) · 5.12 KB
/
setup
File metadata and controls
113 lines (94 loc) · 5.12 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
#!/usr/bin/env bash
set -Eeuo pipefail
# ================ AnnieXMusic=======================
# Only collects env and writes .env with summary UI
# ===================================================
IS_TTY=0; [ -t 1 ] && IS_TTY=1
has() { command -v "$1" >/dev/null 2>&1; }
c(){
if [ "$IS_TTY" -eq 1 ] && has tput; then
case "$1" in
bold) tput bold;; dim) tput dim;; ul) tput smul;;
red) tput setaf 1;; green) tput setaf 2;; yellow) tput setaf 3;;
blue) tput setaf 4;; magenta) tput setaf 5;; cyan) tput setaf 6;;
reset) tput sgr0;; *) tput sgr0;;
esac
else
case "$1" in
bold) printf '\033[1m';; dim) printf '\033[2m';; ul) printf '\033[4m';;
red) printf '\033[31m';; green) printf '\033[32m';; yellow) printf '\033[33m';;
blue) printf '\033[34m';; magenta) printf '\033[35m';; cyan) printf '\033[36m';;
reset) printf '\033[0m';; *) printf '\033[0m';;
esac
fi
}
term_width(){ (stty size 2>/dev/null | awk '{print $2}') || echo 100; }
hr(){ local w; w="$(term_width)"; printf "%s\n" "$(c dim)$(printf '─%.0s' $(seq 1 "$w"))$(c reset)"; }
banner(){ clear; printf "%s" "$(c magenta)"; cat <<'EOF'
_ _ ___ _ _ _
/ \ _ __ _ __ (_) ___ |_ _|_ __ ___| |_ __ _| | | ___ _ __
/ _ \ | '_ \| '_ \| |/ _ \ | || '_ \/ __| __/ _` | | |/ _ \ '__|
/ ___ \| | | | | | | | __/ | || | | \__ \ || (_| | | | __/ |
/_/ \_\_| |_|_| |_|_|\___| |___|_| |_|___/\__\__,_|_|_|\___|_|
EOF
printf "%s%s%s\n" "$(c bold)" "$(c cyan)A clean, guided setup experience" "$(c reset)"
hr
}
info(){ printf " %sℹ%s %s\n" "$(c blue)" "$(c reset)" "$1"; }
warn(){ printf " %s!%s %s\n" "$(c yellow)" "$(c reset)" "$1"; }
good(){ printf " %s✔%s %s\n" "$(c green)" "$(c reset)" "$1"; }
bad(){ printf " %s✖%s %s\n" "$(c red)" "$(c reset)" "$1"; }
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
trap 'stty sane 2>/dev/null || true' EXIT
# ------- Prompts -------
prompt_req(){ local label="$1" var="$2" val=""; while :; do IFS= read -r -p " $(c yellow)$label (required): $(c reset)" val || true; [ -n "$val" ] && break; printf " %s!%s required field\n" "$(c yellow)" "$(c reset)"; done; printf -v "$var" '%s' "$val"; }
prompt_opt(){ local label="$1" var="$2" val=""; IFS= read -r -p " $(c yellow)$label (optional): $(c reset)" val || true; printf -v "$var" '%s' "$val"; }
ell(){ local s="$1" max="$2" n=${#1}; if [ "$n" -gt "$max" ]; then printf "%s…" "${s:0:$((max-1))}"; else printf "%s" "$s"; fi }
# ------- Summary Table -------
print_table(){ local h1="$1" h2="$2"; shift 2; local rows=("$@"); local max1=${#h1} r c1 c2; for r in "${rows[@]}"; do c1="${r%%|*}"; [ ${#c1} -gt $max1 ] && max1=${#c1}; done; local w right sep1 sep2; w="$(term_width)"; right=$(( w - max1 - 7 )); [ $right -lt 20 ] && right=20; sep1="$(printf '─%.0s' $(seq 1 $((max1+2))))"; sep2="$(printf '─%.0s' $(seq 1 $right))"; printf "%s┌%s┬%s%s\n" "$(c dim)" "$sep1" "$sep2" "$(c reset)"; printf "│ %-${max1}s │ %s\n" "$(c bold)$h1$(c reset)" "$(c bold)$h2$(c reset)"; printf "%s├%s┼%s%s\n" "$(c dim)" "$sep1" "$sep2" "$(c reset)"; for r in "${rows[@]}"; do c1="${r%%|*}"; c2="${r#*|}"; printf "│ %-${max1}s │ %s\n" "$c1" "$(ell "$c2" "$right")"; done; printf "%s└%s┴%s%s\n" "$(c dim)" "$sep1" "$sep2" "$(c reset)"; }
write_env(){ umask 077; local tmp; tmp="$(mktemp .env.tmp.XXXXXX)"; {
printf "API_HASH=%s\n" "$api_hash"
printf "API_ID=%s\n" "$api_id"
printf "API_KEY=%s\n" "$api_key"
printf "VIDEO_API_URL=%s\n" "$video_api_url"
printf "API_URL=%s\n" "$api_url"
printf "BOT_TOKEN=%s\n" "$bot_token"
printf "COOKIE_URL=%s\n" "$cookie_url"
printf "DEEP_API=%s\n" "$deep_api"
printf "LOGGER_ID=%s\n" "$logger"
printf "MONGO_DB_URI=%s\n" "$mongo_db"
printf "OWNER_ID=%s\n" "$ownid"
printf "STRING_SESSION=%s\n" "$string_session"
} >"$tmp"; mv "$tmp" .env; }
collect_config(){ banner; info "Enter the following values"; printf "\n";
prompt_req "API ID" api_id
prompt_req "API HASH" api_hash
prompt_req "OWNER ID" ownid
prompt_req "LOG GROUP ID" logger
prompt_req "BOT TOKEN" bot_token
prompt_req "STRING SESSION" string_session
prompt_req "MONGO DB URI" mongo_db
prompt_req "COOKIE URL" cookie_url
prompt_opt "DEEP API" deep_api
prompt_opt "API_URL" api_url
prompt_opt "VIDEO_API_URL" video_api_url
prompt_opt "API_KEY" api_key
write_env; clear; printf "%sEnvironment Summary%s\n" "$(c bold)" "$(c reset)"; hr;
print_table "Key" "Value" \
"API_ID|$api_id" \
"API_HASH|$api_hash" \
"OWNER_ID|$ownid" \
"LOGGER_ID|$logger" \
"BOT_TOKEN|$bot_token" \
"STRING_SESSION|$string_session" \
"MONGO_DB_URI|$mongo_db" \
"COOKIE_URL|$cookie_url" \
"DEEP_API|$deep_api" \
"API_URL|$api_url" \
"VIDEO_API_URL|$video_api_url" \
"API_KEY|$api_key"
}
final_notes(){ printf "\n"; hr; good ".env saved successfully"; info "Edit: ./.env"; printf "\nThank you for using Annie Installer%s\n" "$(c bold)$(c cyan)" "$(c reset)"; }
main(){ banner; info "Project: $(basename "$SCRIPT_DIR")"; collect_config; final_notes; }
main "$@"