-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·113 lines (93 loc) · 3.03 KB
/
install.sh
File metadata and controls
executable file
·113 lines (93 loc) · 3.03 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 -euo pipefail
IFS=$'\n\t'
# Colores
greenColor="\e[0;32m\033[1m"
purpleColor="\e[0;35m\033[1m"
redColor="\e[0;31m\033[1m"
yellowColor="\e[0;33m\033[1m"
endColor="\033[0m\e[0m"
# Variables
BIN_DIR="$HOME/.local/bin"
SYSTEMD_USER_DIR="$HOME/.config/systemd/user"
SERVICE_FILE="$SYSTEMD_USER_DIR/visual-break.service"
TIMER_FILE="$SYSTEMD_USER_DIR/visual-break.timer"
BIN_FILE="$BIN_DIR/visual-break"
create_directories() {
echo -e "${purpleColor}Creando directorios necesarios...${endColor}"
mkdir -p "$BIN_DIR"
mkdir -p "$SYSTEMD_USER_DIR"
}
check_files_exist() {
local files=("$@")
for file in "${files[@]}"; do
if [[ -n "$file" && ! -f "$file" ]]; then
echo -e "${redColor}[!] Error: El archivo $file no existe.${endColor}"
exit 1
fi
done
}
copy_files() {
local src_bin="$1"
local dst_bin="$2"
local src_service="${3:-}" # Valor por defecto vacío
local dst_service="${4:-}" # Valor por defecto vacío
local src_timer="${5:-}" # Valor por defecto vacío
local dst_timer="${6:-}" # Valor por defecto vacío
# Verifica solo los archivos que no estén vacíos
check_files_exist "$src_bin" "$src_service" "$src_timer"
echo -e "${purpleColor}Copiando archivos...${endColor}"
cp "$src_bin" "$dst_bin"
chmod 755 "$dst_bin"
if [[ -n "$src_service" && -n "$dst_service" ]]; then
sed "s/user/$USER/g" "$src_service" > "$dst_service"
chmod 655 "$dst_service"
fi
if [[ -n "$src_timer" && -n "$dst_timer" ]]; then
sed "s/user/$USER/g" "$src_timer" > "$dst_timer"
chmod 655 "$dst_timer"
fi
}
install_systemd() {
echo -e "${yellowColor}Instalando VisualBrake...${endColor}"
create_directories
copy_files bin/visual-break "$BIN_FILE" services/visual-break.service "$SERVICE_FILE" services/visual-break.timer "$TIMER_FILE"
if ! command -v systemctl &> /dev/null; then
echo -e "${redColor}[!] Error: systemctl no está disponible.${endColor}"
exit 1
fi
if ! systemctl --user daemon-reload; then
echo -e "${redColor}[!] Error recargando systemd.${endColor}"
exit 1
fi
if ! systemctl --user enable visual-break.timer; then
echo -e "${redColor}[!] Error habilitando el temporizador.${endColor}"
exit 1
fi
if ! systemctl --user start visual-break.timer; then
echo -e "${redColor}[!] Error iniciando el temporizador.${endColor}"
exit 1
fi
if ! systemctl --user start visual-break.service; then
echo -e "${redColor}[!] Error iniciando el servicio.${endColor}"
exit 1
fi
echo -e "\n${greenColor}[+] VisualBrake se ha instalado y configurado correctamente.${endColor}\n"
}
print_help() {
echo -e "${yellowColor}Uso: $0 [systemd]${endColor}"
echo " systemd - Instala VisualBrake con systemd timers"
}
if [ $# -ne 1 ]; then
print_help
exit 1
fi
case "$1" in
systemd)
install_systemd
;;
*)
print_help
exit 1
;;
esac