-
Notifications
You must be signed in to change notification settings - Fork 1
/
serve-update-files.sh
executable file
·117 lines (96 loc) · 3.2 KB
/
serve-update-files.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
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
#!/bin/bash
#
# Self-host the LineageOS update files
#
# Author: Vasyl Gello <[email protected]>
# Date: 08.04.2019
# Requires: basename, busybox, dirname, grep, kill, mkdir
# readlink, rm, sed, socat, unzip
#
SCRIPTDIR=$(readlink -f "$0")
SCRIPTDIR=$(dirname "$SCRIPTDIR")
# check hostname and domain of computer
SERVER_HOSTNAME=$(cat /etc/hostname)
SERVER_DNSDOMAIN=$(grep "^search " /etc/resolv.conf | sed 's|^search ||')
SERVER_PORT=8080
if [ -z "$SERVER_HOSTNAME" ]
then
echo "Cannot determine server hostname! Exiting..."
exit 1
fi
if [ ! -z "$SERVER_DNSDOMAIN" ]
then
SERVER_URL="$SERVER_HOSTNAME.$SERVER_DNSDOMAIN"
else
SERVER_URL="$SERVER_HOSTNAME"
fi
# Delete all updater reponses
if [ ! -d "$SCRIPTDIR/out/dist/updates" ]
then
mkdir -p "$SCRIPTDIR/out/dist/updates"
fi
# Find all signed updates and create updater responses
#
# Expect the following name sequence:
# $BUILD_FLAVOR-$BUILD_VERSION-$BUILD_DATE-$BUILD_RELTYPE-$DEVICE_CANDIDATE
#
for SIGNED_FILE in $(find "$SCRIPTDIR/out/dist/" -type f -name "*-signed.zip")
do
OTAFILENAME=$(basename "$SIGNED_FILE")
OTAFILESIZE=$(stat -c "%s" "$SIGNED_FILE")
# Extract the required props and generate resulting ZIP name
BUILD_PROP=$(unzip -p "$SIGNED_FILE" system/build.prop)
DEVICE_CANDIDATE=$(echo "$BUILD_PROP" | \
grep "ro.product.device" | \
grep -ioe "=.*$" | \
sed 's#=##')
BUILD_VERSION=$(echo "$BUILD_PROP" | \
grep "ro.cm.build.version=" | \
grep -ioe "=.*$" | \
sed 's#=##')
BUILD_RELTYPE=$(echo "$BUILD_PROP" | \
grep "ro.cm.releasetype" | \
grep -ioe "=.*$" | \
sed 's#=##')
BUILD_DATE_TS=$(echo "$BUILD_PROP" | \
grep "ro.build.date.utc" | \
grep -ioe "=[0-9]*$" | \
sed 's#=##')
BUILD_RELEASE_CHANNEL=$(echo "$BUILD_RELTYPE" | tr '[:upper:]' '[:lower:]')
# Generate updater file
cat << UPDATERFILE > "$SCRIPTDIR/out/dist/updates/$DEVICE_CANDIDATE"_"$BUILD_RELEASE_CHANNEL"
{
"response": [
{
"datetime": $BUILD_DATE_TS,
"filename": "$OTAFILENAME",
"id": "$BUILD_DATE_TS-$OTAFILENAME",
"romtype": "$BUILD_RELTYPE",
"size": $OTAFILESIZE,
"url": "https://$SERVER_URL:$SERVER_PORT/$OTAFILENAME",
"version": "$BUILD_VERSION"
}
]
}
UPDATERFILE
done
# Start the HTTP server
which busybox 1>/dev/null 2>/dev/null
if [ $? -ne 0 ]
then
echo "ERROR: Can not start busybox httpd - busybox missing!"
exit 1
else
echo "Starting HTTPS server on port $SERVER_PORT. Press Enter to stop..."
OLDPWD="$PWD"
cd "$SCRIPTDIR/out/dist"
busybox httpd -v -f -p 127.0.0.1:62000 &
BUSYBOX_PID=$!
socat OPENSSL-LISTEN:$SERVER_PORT,reuseaddr,fork,pf=ip6,certificate="$SCRIPTDIR/certs/$SERVER_URL.pem",verify=0 TCP:127.0.0.1:62000 &
read -s password
kill $BUSYBOX_PID $(ps aux | grep OPENSSL-LISTEN | grep -v grep | awk '{print $2}')
echo "HTTPS Server on port $SERVER_PORT terminated, have fun!"
cd "$OLDPWD"
fi
# Delete the updater response files
rm -f $SCRIPTDIR/out/dist/updates/*