-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
157 lines (130 loc) · 6.86 KB
/
install.sh
File metadata and controls
157 lines (130 loc) · 6.86 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
#!/usr/bin/env bash
# Arcane-System : Installateur simplifié
# Met à jour le système avec une barre de progression
set -Eeo pipefail
# ---------- Configuration (minimale) ----------
readonly SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
set -u
# ---------- Couleurs ----------
if command -v tput >/dev/null 2>&1 && [[ -t 1 ]]; then
readonly BOLD=$(tput bold) RESET=$(tput sgr0)
readonly GREEN=$(tput setaf 2) RED=$(tput setaf 1)
readonly CYAN=$(tput setaf 6) YELLOW=$(tput setaf 3)
else
readonly BOLD=$'\033[1m' RESET=$'\033[0m'
readonly GREEN=$'\033[32m' RED=$'\033[31m'
readonly CYAN=$'\033[36m' YELLOW=$'\033[33m'
fi
# ---------- Fonctions ----------
log() { printf "${CYAN}[%s]${RESET} %s\n" "$(date '+%T')" "$*"; }
error_exit() { echo "${RED}✗ $1${RESET}" >&2; exit "${2:-1}"; }
usage() {
cat <<EOF
${BOLD}Installateur Arcane-System (simplifié)${RESET}
${BOLD}Usage:${RESET}
sudo $(basename "$0")
EOF
}
require_root() {
[[ $EUID -ne 0 ]] && error_exit "Ce script nécessite les droits root (sudo)" 1
}
require_cmd() {
local missing=()
for cmd in "$@"; do
command -v "$cmd" >/dev/null 2>&1 || missing+=("$cmd")
done
[[ ${#missing[@]} -gt 0 ]] && error_exit "Commandes manquantes: ${missing[*]}" 2
}
# Affiche une barre de progression animée pendant l'exécution d'une commande
run_with_progress() {
# Exige au moins 2 arguments: message + commande
if [[ $# -lt 2 ]]; then
error_exit "run_with_progress: arguments insuffisants" 9
fi
local message="$1"; shift
local cmd="$*"
# Choisit une sortie visible même si stdout n'est pas un TTY (cas: wget | bash)
local prog_fd
if [[ -w /dev/tty ]]; then
# Utilise le terminal directement
exec {prog_fd}<>/dev/tty
else
# Fallback sur stdout
exec {prog_fd}>&1
fi
printf "%s\n" "${BOLD}${message}${RESET}" >&${prog_fd}
# Lance la commande en arrière-plan avec redirection complète
bash -c "$cmd" >/dev/null 2>&1 &
local cmd_pid=$!
# Prépare l'affichage
local width=40
local i=0
tput civis 2>/dev/null || true
printf "\n" >&${prog_fd} # ligne dédiée à la barre
# Affiche un premier état de barre immédiatement
printf "\r[%s]" "$(printf "%${width}s" | tr ' ' ' ')" >&${prog_fd}
# Petite pause pour garantir au moins une frame visible
sleep 0.1
# Animation tant que la commande tourne
while kill -0 "$cmd_pid" 2>/dev/null; do
i=$(( (i + 1) % (width * 2) ))
local filled=$(( i <= width ? i : (2*width - i) ))
local bar
bar=$(printf "%${filled}s" | tr ' ' '#')
local spaces
spaces=$(printf "%$((width - filled))s")
printf "\r[%s%s]" "$bar" "$spaces" >&${prog_fd}
sleep 0.08
done
# Attend la fin et fixe l'état (ne pas quitter sur set -e)
set +e
wait "$cmd_pid"
local status=$?
set -e
printf "\r[%s]\n" "$(printf "%${width}s" | tr ' ' '#')" >&${prog_fd}
tput cnorm 2>/dev/null || true
# Ferme le descripteur si ouvert sur /dev/tty
exec {prog_fd}>&-
return "$status"
}
# (Téléchargement et verrou supprimés dans la version simplifiée)
# ---------- Bannière ----------
show_banner() {
cat << 'EOF'
╔═════════════════════════════════════════════════════════════════════════════════════╗
║ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ I N S T A L L E R ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ║
╠═════════════════════════════════════════════════════════════════════════════════════╣
║ ┌─────────────────────────────────────────────────────────────────────────────────┐ ║
║ │ │ ║
║ │ █████╗ ██████╗ ██████╗ █████╗ ███╗ ██╗███████╗ ███████╗██╗ ██╗ │ ║
║ │ ██╔══██╗██╔══██╗██╔════╝██╔══██╗████╗ ██║██╔════╝ ██╔════╝██║ ██║ │ ║
║ │ ███████║██████╔╝██║ ███████║██╔██╗ ██║█████╗ ███████╗███████║ │ ║
║ │ ██╔══██║██╔══██╗██║ ██╔══██║██║╚██╗██║██╔══╝ ╚════██║██╔══██║ │ ║
║ │ ██║ ██║██║ ██║╚██████╗██║ ██║██║ ╚████║███████╗ ██╗ ███████║██║ ██║ │ ║
║ │ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝╚═╝ ╚═══╝╚══════╝ ╚═╝ ╚══════╝╚═╝ ╚═╝ │ ║
║ │ │ ║
║ └─────────────────────────────────────────────────────────────────────────────────┘ ║
╚═════════════════════════════════════════════════════════════════════════════════════╝
EOF
}
# (Parsing d'arguments supprimé)
# ---------- Main ----------
main() {
show_banner
require_root
require_cmd apt-get
# Mise à jour du système avec barre de progression
log "Préparation de la mise à jour du système"
local apt_log="/tmp/arcane_apt_update.log"
if run_with_progress "Exécution: apt-get update && apt-get upgrade -y" "apt-get update -y >$apt_log 2>&1 && apt-get upgrade -y >>$apt_log 2>&1"; then
log "${GREEN}✓ Système à jour${RESET}"
else
log "${YELLOW}⚠ La mise à jour du système a rencontré des erreurs${RESET}"
log "Consulte le journal: ${apt_log}"
fi
echo
cat << EOF
${BOLD}${GREEN}✓ Fin de l'installation simplifiée${RESET}
EOF
}
main "$@"