-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-images.sh
executable file
·69 lines (61 loc) · 1.38 KB
/
update-images.sh
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
#!/bin/bash
# from: https://github.com/dylanaraps/pure-bash-bible#get-the-directory-name-of-a-file-path
dirname() {
# Usage: dirname "path"
local tmp=${1:-.}
[[ $tmp != *[!/]* ]] && {
printf '/\n'
return
}
tmp=${tmp%%"${tmp##*[!/]}"}
[[ $tmp != */* ]] && {
printf '.\n'
return
}
tmp=${tmp%/*}
tmp=${tmp%%"${tmp##*[!/]}"}
printf '%s\n' "${tmp:-/}"
}
SYNC_DIR=""
if sudo test -d /home/oem/cache/sync
then
errors=999
if sudo test -f /home/oem/cache/sync/SHA256SUMS
then
errors=$(sudo bash -c 'cd /home/oem/cache/sync; sha256sum -c SHA256SUMS | grep -c FAILED')
fi
if [ $errors -gt 0 ];
then
sudo rm -rvf /home/oem/cache
else
SYNC_DIR=/home/oem/cache/sync
fi
fi
if [ "$SYNC_DIR" == "" ];
then
SYNC_DIR=$(dirname $(find /media/$USER 2>/dev/null | grep SHA256SUMS.gpg))
fi
echo $SYNC_DIR
if [ "$SYNC_DIR" == '.' ];
then
echo "No new images found"
exit 1
fi
sudo rm -rf /root/cache/sync
sudo cp -rT $SYNC_DIR /root/cache/sync
sync
echo "Finished copying files - safe to remove drive"
TEST=`sudo bash -c "cd /root/cache/sync; sha256sum -c SHA256SUMS"`
if [[ $TEST == *"FAILED"* ]];
then
echo $TEST
exit 1
fi
sudo rm -rf /root/cache/bootstrap
until sudo apt update
do
sleep 1
done
sudo apt full-upgrade -y --allow-downgrades
# sudo apt autoremove -y
sudo reboot now