Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·147 lines (126 loc) · 5.04 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·147 lines (126 loc) · 5.04 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
#!/bin/bash
# ============================================
# refugiOS - Launcher Bootstrapper
# (Prepares the minimum indispensable for Python)
# ============================================
set -e
# Base directory setup
REFUGIOS_DIR="$HOME/refugiOS"
mkdir -p "$REFUGIOS_DIR/Scripts"
# Initial log functions (will be supplemented by i18n)
log_info() { echo -e "\e[1;34m[*]\e[0m $1"; }
log_err() {
echo -e "\e[1;31m[X] ERROR:\e[0m $1"
if [ -t 0 ] && [ -t 1 ]; then
read -p "$(t press_enter 2>/dev/null || echo 'Press ENTER to close...')" -r || true
fi
exit 1
}
# Important paths and URLs
REPO_URL="https://raw.githubusercontent.com/Ganso/refugiOS/main"
I18N_SH="$REFUGIOS_DIR/Scripts/i18n.sh"
PYTHON_SCRIPT="$REFUGIOS_DIR/install.py"
I18N_PY="$REFUGIOS_DIR/i18n.py"
# Define fallback localization function BEFORE sourcing
t() { echo "$1"; }
t_info="INFO"
t_error="ERROR"
# Developer Mode: when the installer is run from a checkout of the repository, the local
# files take precedence and nothing is fetched from GitHub. Otherwise local changes would
# be silently replaced by the published version and could never be tested.
LOCAL_SCRIPTS="$(dirname "$0")"
DEV_MODE=0
if [ -f "$LOCAL_SCRIPTS/install.py" ] && [ -f "$LOCAL_SCRIPTS/i18n.py" ]; then
DEV_MODE=1
fi
if [ "$DEV_MODE" == "1" ]; then
log_info "Developer Mode: using local files, skipping GitHub downloads."
if [ -f "$LOCAL_SCRIPTS/scripts/i18n.sh" ]; then
cp "$LOCAL_SCRIPTS/scripts/i18n.sh" "$I18N_SH"
fi
cp "$LOCAL_SCRIPTS/i18n.py" "$I18N_PY"
cp "$LOCAL_SCRIPTS/install.py" "$PYTHON_SCRIPT"
# install.py runs from its copy in ~/refugiOS: tell it where the checkout is,
# or it cannot see the local scripts/ and media/ and fetches the published ones
REFUGIOS_SRC_DIR="$(cd "$LOCAL_SCRIPTS" && pwd)"
export REFUGIOS_SRC_DIR
else
# Sync system clock via HTTP port 80 if skewed (prevents SSL certificate errors on cold boots)
if command -v curl >/dev/null 2>&1; then
for srv in "http://deb.debian.org" "http://www.google.com" "http://cloudflare.com"; do
HTTP_DATE=$(curl -sI --max-time 3 "$srv" 2>/dev/null | grep -i '^date:' | head -n 1 | sed 's/^[Dd]ate: //')
if [ -n "$HTTP_DATE" ]; then
sudo date -u -s "$HTTP_DATE" >/dev/null 2>&1 || true
break
fi
done
fi
# Download localization system
log_info "Fetching latest localization system..."
wget -q "$REPO_URL/scripts/i18n.sh?nocache=$RANDOM" -O "$I18N_SH" || true
fi
# Try to source i18n if it exists and is not empty
if [ -s "$I18N_SH" ]; then
source "$I18N_SH" || true
fi
log_info "$(t checking_deps)"
if [ "${DEBUG:-0}" == "1" ]; then
echo -e "\e[1;33m[!] $(t warning):\e[0m $(t debug_mode)"
else
# Resolve package locks in Live environments
sudo systemctl stop unattended-upgrades 2>/dev/null || true
sudo dpkg --configure -a || true
fi
# List of system dependencies needed for the Python installer to work well
DEPENDENCIES="python3 python3-dialog dialog aria2 pciutils wget curl bash jq rsync apt-utils flatpak"
MISSING=""
for pkg in $DEPENDENCIES; do
if dpkg -s "$pkg" >/dev/null 2>&1; then
echo -e "\e[1;34m[*]\e[0m $pkg: \e[1;32m[$(t installed)]\e[0m"
else
echo -e "\e[1;34m[*]\e[0m $pkg: \e[1;31m[$(t missing)]\e[0m"
MISSING="$MISSING $pkg"
fi
done
if [ -n "$MISSING" ]; then
if [ "${DEBUG:-0}" == "1" ]; then
echo -e "\e[1;33m[!] $(t warning):\e[0m The system detected missing packages ($MISSING), but they will not be downloaded."
else
log_info "$(t installing_deps) $MISSING"
sudo apt-get update -y >/dev/null 2>&1 || true
sudo apt-get install -f -y < /dev/null || true
if ! sudo apt-get install -y $MISSING < /dev/null; then
log_err "$(t fail_installing_deps 2>/dev/null || echo 'Failed to install required dependencies. Please check your internet connection.')"
fi
fi
fi
# Download Python installer components
if [ "$DEV_MODE" != "1" ]; then
log_info "$(t downloading_installer)"
wget -q "$REPO_URL/i18n.py?nocache=$RANDOM" -O "$I18N_PY" || true
if wget -q "$REPO_URL/install.py?nocache=$RANDOM" -O "$PYTHON_SCRIPT"; then
log_info "$(t download_success)"
else
log_info "$(t download_fallback)"
fi
fi
if [ ! -s "$PYTHON_SCRIPT" ]; then
log_err "$(t fail_critical)"
fi
# The Python installer cannot start without its localization module
if [ ! -s "$I18N_PY" ]; then
log_err "$(t fail_i18n)"
fi
log_info "$(t launching_python)"
export HOME_DIR="$HOME"
export REPO_URL="$REPO_URL"
# Force interactive reading from virtual terminal (tty)
# to solve 'EOFError' if the master script was launched through a pipe (like: curl ... | bash)
# No basta con comprobar que /dev/tty exista: sin terminal de control el fichero
# está ahí pero abrirlo falla, y la redirección tumbaría el instalador.
if (exec < /dev/tty) 2>/dev/null; then
python3 "$PYTHON_SCRIPT" "$@" < /dev/tty
else
echo -e "\e[1;33m[!] $(t warning):\e[0m $(t no_tty)"
python3 "$PYTHON_SCRIPT" "$@"
fi