blob: 5b487d5247f26063ee80c2e76a4a0e807526df53 (
plain)
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
|
#!/bin/bash
# shellcheck source=/dev/null
# hyperterm installer
# shellcheck disable=SC1117
# Languages
# ---------
function msg() {
case ${LANG/_*/} in
es)
echo -e "$1"
;;
*)
echo -e "$2"
;;
esac
}
function msg_err() {
case ${LANG/_*/} in
es)
echo -e "$1" >&2
;;
*)
echo -e "$2" >&2
;;
esac
}
# Check Requirements
# -------------------
function install_package() {
local pkg="$1"
local sudo_cmd=""
local OS_ID=""
# Determine if root or use sudo/doas
case "$(id -u)" in
0) sudo_cmd="" ;;
*)
case "$(command -v doas 2>/dev/null)" in
"") sudo_cmd="sudo" ;;
*) sudo_cmd="doas" ;;
esac
;;
esac
# Get OS ID (e.g., arch, debian, ubuntu, fedora, alpine, etc.)
OS_ID=$(
cat /etc/*release 2>/dev/null |
tr '[:upper:]' '[:lower:]' |
grep "^id=" | head -n1 | cut -d= -f2 | tr -d '"'
)
case "$OS_ID" in
arch|manjaro|endeavouros|hyperbola|artix)
$sudo_cmd pacman -Sy --noconfirm "$pkg"
;;
debian|ubuntu|linuxmint|pop|pop_os)
$sudo_cmd apt update
$sudo_cmd apt install -y "$pkg"
;;
fedora|rhel|centos|amzn|rocky|almalinux)
$sudo_cmd dnf install -y "$pkg"
;;
opensuse*|suse)
$sudo_cmd zypper --non-interactive install "$pkg"
;;
void)
$sudo_cmd xbps-install -Sy "$pkg"
;;
gentoo)
$sudo_cmd emerge "app-arch/$pkg"
;;
alpine)
$sudo_cmd apk add --no-cache "$pkg"
;;
*)
msg_err "Sistema operativo no soportado: $OS_ID" "Unsupported OS: $OS_ID"
exit 1
;;
esac
}
programs=("curl" "less" "ls" "iproute2" "unzip")
for program in "${programs[@]}"; do
if ! command -v "$program" &>/dev/null; then
case "$program" in
ls) pkg="coreutils" ;;
iproute2)
case "$OS_ID" in
fedora|rhel|centos) pkg="iproute" ;;
*) pkg="iproute2" ;;
esac
;;
*) pkg="$program" ;;
esac
msg "Instalando dependencia: $pkg" "Installing dependency: $pkg"
install_package "$pkg"
fi
done
# Check URLs availability
# -----------------------
function _url_exists() {
curl --output /dev/null --silent --head --write-out "%{http_code}" "$1"
}
function _urls() {
URL_1="https://git.fridu.us/heckyel/hyperterm/archive/master.zip"
URL_2="https://c.fridu.us/software/hyperterm.git/snapshot/hyperterm-master.zip"
case "$(_url_exists "$URL_1")" in
200) URL="$URL_1" ;;
*)
case "$(_url_exists "$URL_2")" in
200) URL="$URL_2" ;;
*)
msg_err "No se pudo acceder a las URLs de HyperTerm." \
"Could not access HyperTerm URLs."
exit 1
;;
esac
;;
esac
}
# Show usage
# -----------
function show_usage() {
msg "\n$0: Instalar HyperTerm" \
"\n$0: Install HyperTerm"
msg "Comando:\n$0 [argumentos] \n" \
"Usage:\n$0 [arguments] \n"
msg "Argumentos:" \
"Arguments:"
msg "--help (-h): Muestra mensaje de ayuda" \
"--help (-h): Display this help message"
msg "--silent (-s): Instala sin pedir interacción" \
"--silent (-s): Install silently"
msg "--no-modify-config (-n): No modifica archivo config" \
"--no-modify-config (-n): Do not modify config file"
exit 0
}
# Download and unzip archive
# --------------------------
function download_and_unzip() {
_urls
msg "\e[1;32m==>\e[0m\033[1m Descargando HyperTerm... \e[m" \
"\e[1;32m==>\e[0m\033[1m Downloading HyperTerm... \e[m"
TMP_DIR=$(mktemp -d /tmp/hyperterm.XXXXXX)
ZIP_FILE="$TMP_DIR/hyperterm.zip"
curl -L -o "$ZIP_FILE" "$URL"
msg "\e[1;32m==>\e[0m\033[1m Descomprimiendo HyperTerm... \e[m" \
"\e[1;32m==>\e[0m\033[1m Unzipping HyperTerm... \e[m"
unzip -q "$ZIP_FILE" -d "$TMP_DIR"
# The unzip folder will be something like hyperterm-master or hyperterm-master.zip contents
# Move extracted files to ~/.hyperterm
mkdir -p "$HOME/.hyperterm"
# Find extracted dir
EXTRACTED_DIR=$(find "$TMP_DIR" -mindepth 1 -maxdepth 1 -type d | head -n 1)
cp -r "$EXTRACTED_DIR/hyperterm"/* "$HOME/.hyperterm/"
# Copy .bash_profile and template files if exist
if [[ -f "$EXTRACTED_DIR/.bash_profile" ]]; then
cp "$EXTRACTED_DIR/.bash_profile" "$HOME/"
fi
mkdir -p "$HOME/.hyperterm/template"
if [[ -f "$EXTRACTED_DIR/template/bash_profile.template.bash" ]]; then
cp "$EXTRACTED_DIR/template/bash_profile.template.bash" "$HOME/.hyperterm/template/"
fi
# Clean temp
rm -rf "$TMP_DIR"
}
# Backup and install
# ------------------
function backup_and_install() {
download_and_unzip
test -w "$HOME/$CONFIG_FILE" && cp -aL "$HOME/$CONFIG_FILE" "$HOME/$CONFIG_FILE.bak" &&
msg "\033[0;36mTu archivo original $CONFIG_FILE ha sido respaldado a $CONFIG_FILE.bak \033[0m" \
"\033[0;36mYour original $CONFIG_FILE has been backed up to $CONFIG_FILE.bak \033[0m"
sed "s|{{HYPER_BASH}}|$HYPER_BASH|" "$HOME/.hyperterm/template/bash_profile.template.bash" > "$HOME/$CONFIG_FILE"
msg "\033[0;36mPlantilla copiada a ~/$CONFIG_FILE \033[0m" \
"\033[0;36mTemplate copied to ~/$CONFIG_FILE \033[0m"
}
# Parse args
# ----------
for param in "$@"; do
shift
case "$param" in
"--help") set -- "$@" "-h" ;;
"--silent") set -- "$@" "-s" ;;
"--no-modify-config") set -- "$@" "-n" ;;
*) set -- "$@" "$param" ;;
esac
done
OPTIND=1
while getopts "hsn" opt; do
case "$opt" in
h) show_usage ;;
s) silent=true ;;
n) no_modify_config=true ;;
?) show_usage >&2 ;;
esac
done
shift $((OPTIND - 1))
# Setup config file based on OS
case "$OSTYPE" in
darwin*) CONFIG_FILE=".bash_profile" ;;
*) CONFIG_FILE=".bashrc" ;;
esac
HYPER_BASH="$(cd "$(dirname "$0")" && pwd)"
msg "Instalando HyperTerm" "Installing HyperTerm"
if ! [[ "$silent" ]] && ! [[ "$no_modify_config" ]]; then
if [[ -e "$HOME/$CONFIG_FILE.bak" ]]; then
msg_err "\033[0;36mArchivo de respaldo ya existe. Haz backup antes de instalar.\033[0m" \
"\033[0;36mBackup file already exists. Please backup before installing.\033[0m"
while true; do
read -e -n 1 -r -p "$(msg "¿Sobrescribir backup? [s/N] " "Overwrite backup? [y/N] ") " RESP
case "$RESP" in
[yYsS]) break ;;
[nN]|"") msg "Instalación abortada." "Installation aborted."; exit 1 ;;
*) msg "Elige sí o no." "Choose y or n." ;;
esac
done
fi
while true; do
read -e -n 1 -r -p "$(msg "¿Conservar $CONFIG_FILE y añadir plantilla HyperTerm al final? [s/N] " "Keep $CONFIG_FILE and append HyperTerm template? [y/N] ") " choice
case "$choice" in
[yYsS])
download_and_unzip "$@"
test -w "$HOME/$CONFIG_FILE" && cp -aL "$HOME/$CONFIG_FILE" "$HOME/$CONFIG_FILE.bak" &&
msg "\033[0;36mRespaldo creado en $CONFIG_FILE.bak \033[0m" "\033[0;36mBackup created at $CONFIG_FILE.bak \033[0m"
(sed "s|{{HYPER_BASH}}|$HYPER_BASH|" "$HOME/.hyperterm/template/bash_profile.template.bash" | tail -n +2) >> "$HOME/$CONFIG_FILE"
msg "\033[0;36mPlantilla HyperTerm añadida a $CONFIG_FILE\033[0m" "\033[0;36mHyperTerm template added to $CONFIG_FILE\033[0m"
break
;;
[nN]|"")
backup_and_install "$@"
break
;;
*)
msg "Elige sí o no." "Choose y or n."
;;
esac
done
elif [[ "$silent" ]] && ! [[ "$no_modify_config" ]]; then
backup_and_install "$@"
fi
echo ""
msg "\e[1;32m==>\e[0m\033[1m Instalación finalizada con éxito! Disfruta HyperTerm! \e[m" \
"\e[1;32m==>\e[0m\033[1m Installation finished successfully! Enjoy HyperTerm! \e[m"
msg "\033[0;36mPara empezar, abre una nueva pestaña o haz 'source $HOME/$CONFIG_FILE'.\033[0m" \
"\033[0;36mTo start, open a new tab or 'source $HOME/$CONFIG_FILE'.\033[0m"
echo ""
msg "¡Gracias por instalar!" "Thank you for installing!"
echo -e '\033[0;36m __ __ ______ '
echo -e '\033[0;36m / / / /_ ______ ___ ____/_ __/__ _________ ___ '
echo -e '\033[0;36m / /_/ / / / / __ \/ _ \/ ___// / / _ \/ ___/ __ `__ \ '
echo -e '\033[0;36m / __ / /_/ / /_/ / __/ / / / / __/ / / / / / / / '
echo -e '\033[0;36m /_/ /_/\__, / .___/\___/_/ /_/ \___/_/ /_/ /_/ /_/ '
echo -e '\033[0;36m /____/_/ '
echo -e '\033[m'
msg "Para evitar problemas, activa solo las funciones que uses en $HOME/.hyperterm/_custom.sh" \
"To avoid issues, enable only the features you want from $HOME/.hyperterm/_custom.sh"
msg "Puedes reportar errores en \033[0;36mhttps://todo.sr.ht/~heckyel/hyperterm \033[0m" \
"You can report issues at \033[0;36mhttps://todo.sr.ht/~heckyel/hyperterm \033[0m"
|