summaryrefslogtreecommitdiff
path: root/releng/airootfs/usr/local/bin/raveos-telepito-frissites
blob: 9254448816e0bacbc6e300452429b3cbfbd8c7a0 (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
#!/bin/bash
set -uo pipefail

NAPLO=/var/log/raveos-telepito-frissites.log
CSOMAGOK=(calamares raveos-calamares-module raveos-calamares-theme)
MENTES=/tmp/calamares-elozo.tar
LISTA=/tmp/calamares-elozo.lista
REPOCONF=/tmp/raveos-csak-repo.conf

ZOLD=$'\e[38;2;106;168;79m'
HALVANY=$'\e[38;2;140;150;158m'
SARGA=$'\e[38;2;214;158;46m'
ALAP=$'\e[0m'

exec 3>&1
exec >>"$NAPLO" 2>&1
echo "== RaveOS installer update: $(date)"

kiir() {
  printf '%s\n' "$2"
  printf '  %s%s%s\n' "$1" "$2" "$ALAP" >&3
}

printf '\e[?25l\n  %sRaveOS Installer%s\n  %sChecking for the latest installer version%s\n\n' "$ZOLD" "$ALAP" "$HALVANY" "$ALAP" >&3

van_net() {
  curl -fsI --max-time 6 https://page.rp1.hu/x86_64/ >/dev/null || curl -fsI --max-time 6 https://rp1.hu/ >/dev/null
}

kiir "$HALVANY" "Checking internet connection..."
for _ in $(seq 1 10); do
  van_net && break
  sleep 2
done

if ! van_net; then
  kiir "$SARGA" "No internet connection. Choose a Wi-Fi network from the list (Esc: skip)."
  sleep 2
  printf '\e[?25h' >&3
  nmtui-connect </dev/tty >/dev/tty 2>&1
  printf '\e[?25l\e[2J\e[H\n' >&3
  for _ in $(seq 1 10); do
    van_net && break
    sleep 2
  done
fi

if ! van_net; then
  kiir "$SARGA" "No internet connection, starting the installer as is."
  sleep 2
  exit 0
fi

for _ in $(seq 1 60); do
  systemctl is-active --quiet pacman-init.service && break
  sleep 1
done

sed -n '1,/^\[core\]/p' /etc/pacman.conf | sed '$d' > "$REPOCONF"

kiir "$HALVANY" "Checking for updates..."
if ! timeout 60 pacman --config "$REPOCONF" --noprogressbar -Sy; then
  kiir "$SARGA" "The RaveOS repository is not reachable, starting the installer as is."
  sleep 2
  exit 0
fi

FRISS=$(pacman --config "$REPOCONF" -Qu "${CSOMAGOK[@]}" 2>/dev/null)
if [ -z "$FRISS" ]; then
  kiir "$ZOLD" "The installer is up to date."
  sleep 1
  exit 0
fi
echo "Available updates:"
echo "$FRISS"
kiir "$HALVANY" "Installing update:"
while IFS= read -r sor; do
  kiir "$HALVANY" "  $sor"
done <<< "$FRISS"

{
  pacman -Qlq "${CSOMAGOK[@]}" | grep -v '/$'
  for cs in "${CSOMAGOK[@]}"; do
    ls -d /var/lib/pacman/local/"$cs"-[0-9]* 2>/dev/null
  done
} | sed 's#^/##' | sort > "$LISTA"
tar -cf "$MENTES" -C / -T "$LISTA" 2>/dev/null

visszaallit() {
  kiir "$SARGA" "$1"
  rm -f /var/lib/pacman/db.lck
  pacman -Qlq "${CSOMAGOK[@]}" 2>/dev/null | grep -v '/$' | sed 's#^/##' | sort > "$LISTA.uj"
  comm -13 "$LISTA" "$LISTA.uj" | while IFS= read -r f; do rm -f "/$f"; done
  for cs in "${CSOMAGOK[@]}"; do
    rm -rf /var/lib/pacman/local/"$cs"-[0-9]*
  done
  tar -xf "$MENTES" -C /
  sleep 3
  exit 0
}

if ! timeout 180 pacman --config "$REPOCONF" --noprogressbar -S --needed --noconfirm "${CSOMAGOK[@]}"; then
  visszaallit "The update failed, starting the installer as is."
fi

if ldd /usr/bin/calamares /usr/lib/libcalamares*.so* /usr/lib/calamares/modules/*/*.so 2>&1 | grep -q "not found"; then
  visszaallit "The new installer is missing a library, starting the previous version."
fi

kiir "$ZOLD" "The installer has been updated."
sleep 1