-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgh-update-os
executable file
·79 lines (75 loc) · 2.73 KB
/
gh-update-os
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
#!/bin/bash
# A duplicate of gh-update-os, except this one serves the purpose of applying the actual update
if [[ $EUID -ne 0 ]];
then
exec pkexec --disable-internal-agent "$0" "$@"
fi
argdata=$1
ready_watcher=/tmp/gh-update-ready-to-deploy
downloadpath=/home/.gh_offload/updatecontainer
# We assume we entered this step only after confirming that we are okay to continue.
verintg(){
echo "Starting to update..."
if [[ -f "${installcontainer}" ]]; then
CURR_SHA=$(echo $(sha256sum ${installcontainer}) | awk '{print $1}')
if [[ "${CURR_SHA}" == "$(cat ${installcontainer}.sha256)" ]]; then
echo "Validity matches. Continuing to next step."
else
rm -rf ${downloadpath}/${OS_TAG_NAME}
echo "Verification failed. Download contents erased."
exit 1
fi
else
echo "Unable to find update container. (Download issues?)"
exit 1
fi
}
cleandeployments(){
DEPLOYMENTS_PATH=$(btrfs subvolume list /gh_root | awk '{print $9}')
CURR_DEPLOYMENT=$(mount | grep subvol=/rootfs | sed 's/.*subvol=\///g' | sed 's/)//g')
for deployment in $DEPLOYMENTS_PATH;
do
if [[ "$CURR_DEPLOYMENT" == "$deployment" ]]; then
echo "Ignoring deployment $deployment, as it's currently used."
else
echo "Removing unused deployment $deployment..."
btrfs subvolume delete /gh_root/$deployment
fi
done
}
finalizeupd(){
mkdir -p ${installpath}
mount -t btrfs -o subvol=rootfs/${OS_TAG_NAME} -L gh_root ${installpath}
arch-chroot ${installpath} gh-readonly disable
arch-chroot ${installpath} gh-grub-update
arch-chroot ${installpath} gh-readonly enable
umount -l ${installpath}
echo "Cleaning up..."
rm -rf ${downloadpath}/${OS_TAG_NAME}/
echo "Update complete."
}
beginupd(){
# Decompress update container
echo "Decompressing update container..."
zstd -df ${installcontainer}
echo "Removing the unused snapshot..."
cleandeployments
echo "Installing snapshot..."
btrfs receive /gh_root/rootfs/ < ${installfile}
finalizeupd
}
if [[ -f ${argdata} ]]; then
if [[ -f "${ready_watcher}" ]]; then
source ${argdata}
installcontainer=${downloadpath}/${OS_TAG_NAME}/${OS_TAG_NAME}.img.zst
installfile=${downloadpath}/${OS_TAG_NAME}/${OS_TAG_NAME}.img
installpath=/tmp/mounts/${OS_TAG_NAME}
verintg
beginupd
else
echo -e "Arg data was found, but ready to update sentinel was not found.\nAre you sure that the update container download was completed?\nTry running [38;2;23;147;209mgh-update download-update[0m to verify container integrity again."
fi
else
echo "No deploy arguments set."
exit 1
fi