alter_release.sh 2.13 KB
Newer Older
1 2
SUITE="buster"
SECTIONS=$'main\ncontrib\nnon-free'
3 4 5 6 7 8
FTP_URL="http://ftp.debian.org/debian/dists"

# Get distribution directory from cmd
export DIST_DIR=${1}

# Fetch dep11 content for all packages
9 10 11 12 13 14
while read -r SECTION; do
    echo $SECTION
    wget -nd -nc -np -r -l 1 -A gz,xz --reject-regex 'arm|mips|s390x|ppc' ${FTP_URL}/${SUITE}/${SECTION}/dep11 -P ${DIST_DIR}/${SECTION}/dep11
done <<< "$SECTIONS"

cd ${DIST_DIR}
15 16

# Remove PGP Signature block from InRelease
17 18
sed -e '/BEGIN PGP SIGNATURE/,$d' -e '/BEGIN PGP/d' -e '/Hash: SHA512/d' -i InRelease
sed -i '1d' InRelease
19

20 21
# Calculate md5sum, SHA1 and SHA256 for all the files in dep11
while read -r SECTION; do
22
    for i in `find ${SECTION}/dep11 -type f `; do
23
        md5=`md5sum $i | awk '{print $1}'`;md5size=`du -b $i | awk '{print $1}'`
24
        md5check="$md5 $md5size $i\n $md5check"
25
        sha1=`sha1sum $i | awk '{print $1}'`;sha1size=`du -b $i | awk '{print $1}'`
26
        sha1check="$sha1 $sha1size $i\n $sha1check"
27
        sha256=`sha256sum $i | awk '{print $1}'`;sha256size=`du -b $i | awk '{print $1}'`
28
        sha256check="$sha256 $sha256size $i\n $sha256check"
29
    done
30 31
done <<< "$SECTIONS"

32 33 34
# Add MD5, SHA1 checksums to the respective place in Release and InRelease files
function add_checksum {
    for file in InRelease Release; do
35
        sed -i "/"$1"\:/ {
36 37 38 39
             h
             r sum."$2"
             g
             N
40
         }" "$file"
41 42
     done
}
43

44
# Format the encrypted content as per Release file requirements
45 46 47 48 49 50
for encryption in sha1 md5 sha256; do
    encryption_filename=sum."$encryption"
    encryption_check=$"$encryption"check
    echo -e "${!encryption_check}" > "$encryption_filename"
    sed -i -e '1s/^/ /' $encryption_filename
    sed -i.bak '/^[[:blank:]]*$/{$d;}' $encryption_filename
51
done
52

53 54
add_checksum "SHA1" "md5"
add_checksum "SHA256" "sha1"
55 56

# Add checksum for SHA256 at the bottom of Release and InRelease files
57 58 59
cat sum.sha256 >> InRelease
cat sum.sha256 >> Release

60
rm sum.{md5,sha1,sha256} *.bak
61 62

# Sign the mutated InRelease file
63
gpg --clearsign --digest-algo SHA512 --default-key 08A05F60 InRelease
64 65

# Rename the finally generated InRelease.asc
66
mv InRelease.asc InRelease
67