-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto.sh
executable file
·70 lines (60 loc) · 1.76 KB
/
auto.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
70
#!/bin/sh
SCRIPT=$(readlink -f $0)
SCRIPTPATH=`dirname $SCRIPT`
# Settings
TYPE=ota_update
if [ -v $ID ] ; then
ID=panther
fi
if [ -v $CHANNEL ] ; then
CHANNEL=stable
fi
if [ -v $EXTRACT ] ; then
EXTRACT=0
fi
echo "Target custom: $ID-$CHANNEL ($TYPE)";
# Directory initialization.
mkdir -p $SCRIPTPATH/ota
mkdir -p $SCRIPTPATH/crt
echo "Run: $(date)" > $SCRIPTPATH/ota/info
# Autodelete of old versions.
find $SCRIPTPATH/ota -type f -mtime +90 -delete
find $SCRIPTPATH/ota -type d -empty -exec rmdir {} \;
# Checking for an docker image
if docker images | grep "avbroot" ; then
echo "Found avbroot (docker)";
else
echo "Build avbroot (docker)";
docker build --build-arg UID="$(id -u)" --build-arg GID="$(id -g)" --build-arg UNAME="$(whoami)" -t avbroot $SCRIPTPATH/docker
fi
# Search for a new version grapheneos.
URL="https://releases.grapheneos.org"
VERSION=$(curl -s $URL/$ID-$CHANNEL | head -n1 | awk '{print $1;}')
TARGET="$ID-$TYPE-$VERSION"
echo "Last version: $TARGET"
# Download new version grapheneos.
cd $SCRIPTPATH/ota
if ! [ -f "$TARGET.zip" ]; then
curl -o $TARGET.zip.original $URL/$TARGET.zip
else
echo "There are no updates";
exit
fi
cd -
# Key generation
if ! [ -f "$SCRIPTPATH/crt/avb_pkmd.bin" ]; then
echo "Creation certificates";
docker run --rm -e UID_C="$(id -u)" -e GID_C="$(id -g)" -it --entrypoint /init.sh -v $SCRIPTPATH/crt:/avbroot/crt avbroot
else
echo "Found certificates";
fi
# Image Patch
docker run --rm -e UID_C="$(id -u)" -e EXTRACT=$EXTRACT -e GID_C="$(id -g)" -e TARGET="$TARGET" -v $SCRIPTPATH/crt:/avbroot/crt:ro -v $SCRIPTPATH/ota:/avbroot/ota avbroot
rm $SCRIPTPATH/ota/$TARGET.zip.original
# Image check
cd $SCRIPTPATH/ota
if [ -f "$TARGET.zip" ]; then
curl -o $ID-$CHANNEL $URL/$ID-$CHANNEL
echo "Success!";
fi
cd -