aboutsummaryrefslogtreecommitdiff
path: root/lineageos-dl
blob: 5038151c21b2e691b2bf93f3125b7922cc7d32bf (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
#!/bin/bash
#
# Download LineageOS images
#

# Parameters
BASENAME="`basename $0`"
DEVICE="$1"
VERSION="$2"
DATE="$3"
FILE="lineage-${VERSION}-${DATE}-nightly-${DEVICE}-signed.zip"
UPSTREAM="https://download.lineageos.org"
RECOVERY="lineage-${VERSION}-${DATE}-recovery-${DEVICE}.img"
RECOVERY_URL="https://mirrorbits.lineageos.org/recovery/${DEVICE}/${DATE}/${RECOVERY}"
BASE_URL="https://mirrorbits.lineageos.org/full/${DEVICE}/${DATE}/${FILE}"
DL_PAGE="https://download.lineageos.org/${DEVICE}"
DL_PATTERN="mirrorbits"
DL="$HOME/data/distros/lineageos/official/${DEVICE}"
CWD="`pwd`"

# Determine latest image version
function lineageos_dl_determine_latest {
  local type="$1"

  lynx -dump "${UPSTREAM}/${DEVICE}" | grep ${DL_PATTERN} | awk '{ print $2 }' | grep ${type} | sort -r | grep -v  -v '?sha256' | head -1
}

# Syntax check
if [ -z "$DATE" ]; then
  if [ ! -z "$DEVICE" ]; then
    echo "$BASENAME: trying to guess download URLs and file names..."
    BASE_URL="`lineageos_dl_determine_latest full`"
    FILE="`basename $BASE_URL`"
    RECOVERY_URL="`lineageos_dl_determine_latest recovery`"
    RECOVERY="`basename $RECOVERY_URL`"

    if [ -z "$BASE_URL" ]; then
      echo "error: could not automatically determine download URL, please specify version and build date manually"
      exit 1
    fi
  else
    echo "usage:   $BASENAME <device> [<version <build_date>]"
    echo "example: $BASENAME cedric"
    echo "example: $BASENAME cedric 17.1 20210325"
    exit 1
  fi
fi

# Set file names
HASH="$FILE.sha256"
RECOVERY_HASH="$RECOVERY.sha256"

# Ensure destination folder exists
echo "$BASENAME: download destination set to $DL"
mkdir -p $DL

# Download package
if [ ! -e "$DL/$FILE" ]; then
  wget -c $BASE_URL -O $DL/$FILE || exit 1
else
  echo "$BASENAME: file $FILE already exists, skipping"
fi

# Download signature
if [ ! -e "$DL/$HASH" ]; then
  wget -c "$BASE_URL?sha256" -O $DL/$HASH || exit 1
else
  echo "$BASENAME: file $HASH already exists, skipping"
fi

# Download recovery
if [ ! -e "$DL/$RECOVERY" ]; then
  wget -c $RECOVERY_URL -O $DL/$RECOVERY || exit 1
else
  echo "$BASENAME: file $RECOVERY already exists, skipping"
fi

# Download recovery signature
if [ ! -e "$DL/$RECOVERY_HASH" ]; then
  wget -c $RECOVERY_URL?sha256 -O $DL/$RECOVERY_HASH || exit 1
else
  echo "$BASENAME: file $RECOVERY_HASH already exists, skipping"
fi

cd $DL
echo "$BASENAME: checking hashes..."
sha256sum -c $HASH
sha256sum -c $RECOVERY_HASH

# Verify build authenticity
echo "$BASENAME: please verify build authenticity with a procedure like this:"
echo ""
echo "git clone https://github.com/LineageOS/update_verifier"
echo "cd update_verifier"
echo "pip3 install -r requirements.txt"
echo "python3 update_verifier.py lineageos_pubkey $DL/$FILE"
echo ""
echo "more info at https://wiki.lineageos.org/verifying-builds.html"

# Teardown
cd $CWD