|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -e |
| 4 | + |
| 5 | +# This is a script for preparing and uploading a release of Haskell Language Server. |
| 6 | +# Adapted from https://gitlab.haskell.org/bgamari/ghc-utils/-/commits/master/rel-eng/upload.sh |
| 7 | +# |
| 8 | +# Usage, |
| 9 | +# 1. Set $SIGNING_KEY to your key id (prefixed with '=') |
| 10 | +# 2. Create a directory called haskell-langauge-server-<release_number> and place the binary tarballs there |
| 11 | +# 4. Run this script from that directory |
| 12 | +# |
| 13 | +# You can also invoke the script with an argument to perform only |
| 14 | +# a subset of the usual release, |
| 15 | +# |
| 16 | +# upload.sh gen_hashes generate signed hashes of the release |
| 17 | +# tarballs |
| 18 | +# upload.sh sign generate signed hashes of the release |
| 19 | +# tarballs |
| 20 | +# upload.sh upload upload the tarballs and documentation |
| 21 | +# to downloads.haskell.org |
| 22 | +# |
| 23 | +# Prerequisites: moreutils |
| 24 | + |
| 25 | +# Infer release name from directory name |
| 26 | +if [ -z "$rel_name" ]; then |
| 27 | + rel_name="$(basename $(pwd))" |
| 28 | +fi |
| 29 | + |
| 30 | +# Infer version from tarball names |
| 31 | +if [ -z "$ver" ]; then |
| 32 | + ver="$(ls haskell-language-server-*.tar.* | sed -ne 's/haskell-language-server-\([0-9]\+\.[0-9]\+\.[0-9]\+\(\.[0-9]\+\)\?\).\+/\1/p' | head -n1)" |
| 33 | + if [ -z "$ver" ]; then echo "Failed to infer \$ver"; exit 1; fi |
| 34 | +fi |
| 35 | + |
| 36 | +echo HLS version $ver |
| 37 | + |
| 38 | +host="webhost.haskell.org" |
| 39 | + |
| 40 | +usage() { |
| 41 | + echo "Usage: [rel_name=<name>] SIGNING_KEY=<key> $0 <action>" |
| 42 | + echo |
| 43 | + echo "where," |
| 44 | + echo " rel_name gives the release name (e.g. 1.7.0.0)" |
| 45 | + echo "and <action> is one of," |
| 46 | + echo " [nothing] do everything below" |
| 47 | + echo " gen_hashes generated hashes of the release tarballs" |
| 48 | + echo " sign sign hashes of the release tarballs" |
| 49 | + echo " upload upload the tarballs and documentation to downloads.haskell.org" |
| 50 | + echo " purge_all purge entire release from the CDN" |
| 51 | + echo " purge_file file purge a given file from the CDN" |
| 52 | + echo " verify verify the signatures in this directory" |
| 53 | + echo |
| 54 | +} |
| 55 | + |
| 56 | +if [ -z "$ver" ]; then |
| 57 | + usage |
| 58 | + exit 1 |
| 59 | +fi |
| 60 | +if [ -z "$rel_name" ]; then |
| 61 | + rel_name="$ver" |
| 62 | +fi |
| 63 | + |
| 64 | +# returns the set of files that must have hashes generated. |
| 65 | +function hash_files() { |
| 66 | + echo $(find -maxdepth 1 \ |
| 67 | + -iname '*.xz' \ |
| 68 | + -o -iname '*.lz' \ |
| 69 | + -o -iname '*.bz2' \ |
| 70 | + -o -iname '*.zip' \ |
| 71 | + ) |
| 72 | + echo $(find -maxdepth 1 -iname '*.patch') |
| 73 | +} |
| 74 | + |
| 75 | +function gen_hashes() { |
| 76 | + echo -n "Hashing..." |
| 77 | + sha1sum $(hash_files) >| SHA1SUMS & |
| 78 | + sha256sum $(hash_files) >| SHA256SUMS & |
| 79 | + wait |
| 80 | + echo "done" |
| 81 | +} |
| 82 | + |
| 83 | +function sign() { |
| 84 | + # Kill DISPLAY lest pinentry won't work |
| 85 | + DISPLAY= |
| 86 | + eval "$(gpg-agent --daemon --sh --pinentry-program $(which pinentry))" |
| 87 | + for i in $(hash_files) SHA1SUMS SHA256SUMS; do |
| 88 | + if [ -e $i -a -e $i.sig -a $i.sig -nt $i ]; then |
| 89 | + echo "Skipping signing of $i" |
| 90 | + continue |
| 91 | + elif [ -e $i.sig ] && gpg2 --verify $i.sig; then |
| 92 | + # Don't resign if current signature is valid |
| 93 | + touch $i.sig |
| 94 | + continue |
| 95 | + fi |
| 96 | + echo "Signing $i" |
| 97 | + rm -f $i.sig |
| 98 | + gpg2 --use-agent --detach-sign --local-user="$SIGNING_KEY" $i |
| 99 | + done |
| 100 | +} |
| 101 | + |
| 102 | +function verify() { |
| 103 | + if [ $(find -iname '*.sig' | wc -l) -eq 0 ]; then |
| 104 | + echo "No signatures to verify" |
| 105 | + return |
| 106 | + fi |
| 107 | + |
| 108 | + for i in *.sig; do |
| 109 | + echo |
| 110 | + echo Verifying $i |
| 111 | + gpg2 --verify $i $(basename $i .sig) |
| 112 | + done |
| 113 | +} |
| 114 | + |
| 115 | +function upload() { |
| 116 | + verify |
| 117 | + chmod ugo+r,o-w -R . |
| 118 | + dir=$(echo $rel_name | sed s/-release//) |
| 119 | + lftp -c " \ |
| 120 | + open -u hls: sftp://$host && \ |
| 121 | + mirror -P20 -c --reverse --exclude=fetch-gitlab --exclude=out . hls/$dir && \ |
| 122 | + wait all;" |
| 123 | + chmod ugo-w $(ls *.xz *.bz2 *.zip) |
| 124 | +} |
| 125 | + |
| 126 | +function purge_all() { |
| 127 | + # Purge CDN cache |
| 128 | + curl -X PURGE http://downloads.haskell.org/hls/ |
| 129 | + curl -X PURGE http://downloads.haskell.org/~hls/ |
| 130 | + curl -X PURGE http://downloads.haskell.org/hls/$dir |
| 131 | + curl -X PURGE http://downloads.haskell.org/hls/$dir/ |
| 132 | + curl -X PURGE http://downloads.haskell.org/~hls/$dir |
| 133 | + curl -X PURGE http://downloads.haskell.org/~hls/$dir/ |
| 134 | + for i in *; do |
| 135 | + purge_file $i |
| 136 | + done |
| 137 | +} |
| 138 | + |
| 139 | +function purge_file() { |
| 140 | + curl -X PURGE http://downloads.haskell.org/~hls/$rel_name/$i |
| 141 | + curl -X PURGE http://downloads.haskell.org/~hls/$rel_name/$i/ |
| 142 | + curl -X PURGE http://downloads.haskell.org/hls/$rel_name/$i |
| 143 | + curl -X PURGE http://downloads.haskell.org/hls/$rel_name/$i/ |
| 144 | +} |
| 145 | + |
| 146 | + |
| 147 | +if [ "x$1" == "x" ]; then |
| 148 | + gen_hashes |
| 149 | + sign |
| 150 | + upload |
| 151 | + purge_all |
| 152 | +else |
| 153 | + $@ |
| 154 | +fi |
0 commit comments