| 1 | #!/bin/bash |
| 2 | # |
| 3 | # This script is used for stage 1 of the release process. It operates exclusively on the airlock. |
| 4 | # This script, for the RELEASEMANAGER (RM): |
| 5 | # - builds and uploads all binaries to airlock, |
| 6 | # - assumes all keys are available, and signs everything |
| 7 | # This script, for other builders: |
| 8 | # - builds all reproducible binaries, |
| 9 | # - downloads binaries built by the release manager (from airlock if SFTPUSER, else from website), |
| 10 | # compares and signs them, |
| 11 | # - and then uploads sigs (if SFTPUSER), else they can be submitted as PR to spesmilo/electrum-signatures |
| 12 | # Note: the .dmg should be built separately beforehand and copied into dist/ |
| 13 | # (as it is built on a separate machine) |
| 14 | # |
| 15 | # |
| 16 | # env vars: |
| 17 | # - ELECBUILD_NOCACHE: if set, forces rebuild of docker images |
| 18 | # |
| 19 | # "uploadserver" is set in /etc/hosts |
| 20 | # |
| 21 | # Note: steps before doing a new release: |
| 22 | # - update locale: |
| 23 | # 1. cd /opt/electrum-locale && ./update.py && git push |
| 24 | # 2. cd to the submodule dir, and git pull |
| 25 | # 3. cd .. && git push |
| 26 | # - update RELEASE-NOTES and version.py |
| 27 | # - $ git tag -s "$VERSION" -m "$VERSION" |
| 28 | # - $ git push "$REMOTE_ORIGIN" tag "$VERSION" |
| 29 | # |
| 30 | # ----- |
| 31 | # Then, typical release flow: |
| 32 | # - RM runs release.sh |
| 33 | # - Another SFTPUSER BUILDER runs `$ ./release.sh` |
| 34 | # - now airlock contains new binaries and two sigs for each |
| 35 | # - deploy.sh will verify sigs and move binaries across airlock |
| 36 | # - new binaries are now publicly available on uploadserver, but not linked from website yet |
| 37 | # - other BUILDERS can now also try to reproduce binaries and open PRs with sigs against spesmilo/electrum-signatures |
| 38 | # - these PRs can get merged as they come |
| 39 | # - run add_cosigner |
| 40 | # - after some time, RM can run release_www.sh to create and commit website-update |
| 41 | # - then run WWW_DIR/publish.sh to update website |
| 42 | # - at least two people need to run WWW_DIR/publish.sh |
| 43 | # |
| 44 | |
| 45 | set -e |
| 46 | |
| 47 | PROJECT_ROOT="$(dirname "$(readlink -e "$0")")/.." |
| 48 | CONTRIB="$PROJECT_ROOT/contrib" |
| 49 | |
| 50 | cd "$PROJECT_ROOT" |
| 51 | |
| 52 | . "$CONTRIB"/build_tools_util.sh |
| 53 | |
| 54 | # rm -rf dist/* |
| 55 | # rm -f .buildozer |
| 56 | |
| 57 | GPGUSER=$1 |
| 58 | if [ -z "$GPGUSER" ]; then |
| 59 | fail "usage: $0 gpg_username" |
| 60 | fi |
| 61 | |
| 62 | RELEASEMANAGER="" |
| 63 | if [ "$GPGUSER" == "ThomasV" ]; then |
| 64 | PUBKEY="--local-user 6694D8DE7BE8EE5631BED9502BD5824B7F9470E6" |
| 65 | export SSHUSER=thomasv |
| 66 | RELEASEMANAGER=1 |
| 67 | elif [ "$GPGUSER" == "sombernight_releasekey" ]; then |
| 68 | PUBKEY="--local-user 0EEDCFD5CAFB459067349B23CA9EEEC43DF911DC" |
| 69 | export SSHUSER=sombernight |
| 70 | else |
| 71 | warn "unexpected GPGUSER=$GPGUSER" |
| 72 | PUBKEY="" |
| 73 | export SSHUSER="" |
| 74 | fi |
| 75 | |
| 76 | |
| 77 | if [ ! -z "$RELEASEMANAGER" ] ; then |
| 78 | echo -n "Code signing passphrase:" |
| 79 | read -s password |
| 80 | # tests password against keystore |
| 81 | keytool -list -storepass $password |
| 82 | # the same password is used for windows signing |
| 83 | export WIN_SIGNING_PASSWORD=$password |
| 84 | fi |
| 85 | |
| 86 | |
| 87 | VERSION=$("$CONTRIB"/print_electrum_version.py) |
| 88 | info "VERSION: $VERSION" |
| 89 | REV=$(git describe --tags) |
| 90 | info "REV: $REV" |
| 91 | COMMIT=$(git rev-parse HEAD) |
| 92 | |
| 93 | export ELECBUILD_COMMIT="${COMMIT}^{commit}" |
| 94 | |
| 95 | |
| 96 | git_status=$(git status --porcelain) |
| 97 | if [ ! -z "$git_status" ]; then |
| 98 | echo "$git_status" |
| 99 | fail "git repo not clean, aborting" |
| 100 | fi |
| 101 | |
| 102 | set -x |
| 103 | |
| 104 | # create tarball |
| 105 | tarball="Electrum-$VERSION.tar.gz" |
| 106 | if test -f "dist/$tarball"; then |
| 107 | info "file exists: $tarball" |
| 108 | else |
| 109 | ./contrib/build-linux/sdist/build.sh |
| 110 | fi |
| 111 | |
| 112 | # create source-only tarball |
| 113 | srctarball="Electrum-sourceonly-$VERSION.tar.gz" |
| 114 | if test -f "dist/$srctarball"; then |
| 115 | info "file exists: $srctarball" |
| 116 | else |
| 117 | OMIT_UNCLEAN_FILES=1 ./contrib/build-linux/sdist/build.sh |
| 118 | fi |
| 119 | |
| 120 | # appimage |
| 121 | appimage="electrum-$REV-x86_64.AppImage" |
| 122 | if test -f "dist/$appimage"; then |
| 123 | info "file exists: $appimage" |
| 124 | else |
| 125 | ./contrib/build-linux/appimage/build.sh |
| 126 | fi |
| 127 | |
| 128 | |
| 129 | # windows |
| 130 | win1="electrum-$REV.exe" |
| 131 | win2="electrum-$REV-portable.exe" |
| 132 | win3="electrum-$REV-setup.exe" |
| 133 | if test -f "dist/$win1"; then |
| 134 | info "file exists: $win1" |
| 135 | else |
| 136 | pushd . |
| 137 | if test -f "contrib/build-wine/dist/$win1"; then |
| 138 | info "unsigned file exists: $win1" |
| 139 | else |
| 140 | ./contrib/build-wine/build.sh |
| 141 | fi |
| 142 | cd contrib/build-wine/ |
| 143 | if [ ! -z "$RELEASEMANAGER" ] ; then |
| 144 | ./sign.sh |
| 145 | cp ./signed/*.exe "$PROJECT_ROOT/dist/" |
| 146 | else |
| 147 | cp ./dist/*.exe "$PROJECT_ROOT/dist/" |
| 148 | fi |
| 149 | popd |
| 150 | fi |
| 151 | |
| 152 | # android |
| 153 | apk1="Electrum-$VERSION-armeabi-v7a-release.apk" |
| 154 | apk2="Electrum-$VERSION-arm64-v8a-release.apk" |
| 155 | apk3="Electrum-$VERSION-x86_64-release.apk" |
| 156 | for arch in armeabi-v7a arm64-v8a x86_64 |
| 157 | do |
| 158 | apk="Electrum-$VERSION-$arch-release.apk" |
| 159 | apk_unsigned="Electrum-$VERSION-$arch-release-unsigned.apk" |
| 160 | if test -f "dist/$apk"; then |
| 161 | info "file exists: $apk" |
| 162 | else |
| 163 | info "file does not exists: $apk" |
| 164 | if [ ! -z "$RELEASEMANAGER" ] ; then |
| 165 | ./contrib/android/build.sh qml $arch release $password |
| 166 | else |
| 167 | if test -f "dist/$apk_unsigned"; then |
| 168 | # has already been built separately before |
| 169 | info "found unsigned: $apk_unsigned" |
| 170 | else |
| 171 | ./contrib/android/build.sh qml $arch release-unsigned |
| 172 | fi |
| 173 | mv "dist/$apk_unsigned" "dist/$apk" |
| 174 | fi |
| 175 | fi |
| 176 | done |
| 177 | |
| 178 | # the macos binary is built on a separate machine. |
| 179 | # the file that needs to be copied over is the codesigned release binary (regardless of builder role) |
| 180 | dmg="electrum-$VERSION.dmg" |
| 181 | if ! test -f "dist/$dmg"; then |
| 182 | if [ ! -z "$RELEASEMANAGER" ] ; then # RM |
| 183 | fail "dmg is missing, aborting. Please build and codesign the dmg on a mac and copy it over." |
| 184 | else # other builders |
| 185 | fail "dmg is missing, aborting. Please build the unsigned dmg on a mac, compare it with file built by RM, and if matches, copy RM's dmg." |
| 186 | fi |
| 187 | fi |
| 188 | |
| 189 | # now that we have all binaries, if we are the RM, sign them. |
| 190 | if [ ! -z "$RELEASEMANAGER" ] ; then |
| 191 | if test -f "dist/$dmg.asc"; then |
| 192 | info "packages are already signed" |
| 193 | else |
| 194 | info "signing packages" |
| 195 | ./contrib/sign_packages "$GPGUSER" |
| 196 | fi |
| 197 | fi |
| 198 | |
| 199 | info "build complete" |
| 200 | sha256sum dist/*.tar.gz |
| 201 | sha256sum dist/*.AppImage |
| 202 | sha256sum contrib/build-wine/dist/*.exe |
| 203 | |
| 204 | echo -n "proceed (y/n)? " |
| 205 | read answer |
| 206 | |
| 207 | if [ "$answer" != "y" ]; then |
| 208 | echo "exit" |
| 209 | exit 1 |
| 210 | fi |
| 211 | |
| 212 | |
| 213 | if [ -z "$RELEASEMANAGER" ] ; then |
| 214 | # people OTHER THAN release manager. |
| 215 | # download binaries built by RM |
| 216 | rm -rf "$PROJECT_ROOT/dist/releasemanager" |
| 217 | mkdir --parent "$PROJECT_ROOT/dist/releasemanager" |
| 218 | cd "$PROJECT_ROOT/dist/releasemanager" |
| 219 | |
| 220 | if [ -z "$SSHUSER" ]; then |
| 221 | info "No SFTP access, downloading binaries from website" |
| 222 | BASE_URL="https://download.electrum.org/$VERSION" |
| 223 | FILES_TO_DOWNLOAD=( |
| 224 | "$tarball" |
| 225 | "$srctarball" |
| 226 | "$appimage" |
| 227 | "$win1" |
| 228 | "$win2" |
| 229 | "$win3" |
| 230 | "$apk1" |
| 231 | "$apk2" |
| 232 | "$apk3" |
| 233 | "$dmg" |
| 234 | ) |
| 235 | |
| 236 | for filename in "${FILES_TO_DOWNLOAD[@]}"; do |
| 237 | if [ ! -f "$filename" ]; then |
| 238 | info "Downloading $filename..." |
| 239 | wget -q "$BASE_URL/$filename" -O "$filename" || fail "Failed to download $filename" |
| 240 | else |
| 241 | info "File already exists: $filename" |
| 242 | fi |
| 243 | done |
| 244 | else |
| 245 | # TODO check somehow that RM had finished uploading |
| 246 | sftp -oBatchMode=no -b - "$SSHUSER@uploadserver" <<-EOF |
| 247 | cd electrum-downloads-airlock |
| 248 | cd "$VERSION" |
| 249 | mget * |
| 250 | bye |
| 251 | EOF |
| 252 | fi |
| 253 | |
| 254 | # check we have each binary |
| 255 | test -f "$tarball" || fail "tarball not found among sftp downloads" |
| 256 | test -f "$srctarball" || fail "srctarball not found among sftp downloads" |
| 257 | test -f "$appimage" || fail "appimage not found among sftp downloads" |
| 258 | test -f "$win1" || fail "win1 not found among sftp downloads" |
| 259 | test -f "$win2" || fail "win2 not found among sftp downloads" |
| 260 | test -f "$win3" || fail "win3 not found among sftp downloads" |
| 261 | test -f "$apk1" || fail "apk1 not found among sftp downloads" |
| 262 | test -f "$apk2" || fail "apk2 not found among sftp downloads" |
| 263 | test -f "$apk3" || fail "apk3 not found among sftp downloads" |
| 264 | test -f "$dmg" || fail "dmg not found among sftp downloads" |
| 265 | test -f "$PROJECT_ROOT/dist/$tarball" || fail "tarball not found among built files" |
| 266 | test -f "$PROJECT_ROOT/dist/$srctarball" || fail "srctarball not found among built files" |
| 267 | test -f "$PROJECT_ROOT/dist/$appimage" || fail "appimage not found among built files" |
| 268 | test -f "$CONTRIB/build-wine/dist/$win1" || fail "win1 not found among built files" |
| 269 | test -f "$CONTRIB/build-wine/dist/$win2" || fail "win2 not found among built files" |
| 270 | test -f "$CONTRIB/build-wine/dist/$win3" || fail "win3 not found among built files" |
| 271 | test -f "$PROJECT_ROOT/dist/$apk1" || fail "apk1 not found among built files" |
| 272 | test -f "$PROJECT_ROOT/dist/$apk2" || fail "apk2 not found among built files" |
| 273 | test -f "$PROJECT_ROOT/dist/$apk3" || fail "apk3 not found among built files" |
| 274 | test -f "$PROJECT_ROOT/dist/$dmg" || fail "dmg not found among built files" |
| 275 | # compare downloaded binaries against ones we built |
| 276 | cmp --silent "$tarball" "$PROJECT_ROOT/dist/$tarball" || fail "files are different. tarball." |
| 277 | cmp --silent "$srctarball" "$PROJECT_ROOT/dist/$srctarball" || fail "files are different. srctarball." |
| 278 | cmp --silent "$appimage" "$PROJECT_ROOT/dist/$appimage" || fail "files are different. appimage." |
| 279 | rm -rf "$CONTRIB/build-wine/signed/" && mkdir --parents "$CONTRIB/build-wine/signed/" |
| 280 | cp -f "$win1" "$win2" "$win3" "$CONTRIB/build-wine/signed/" |
| 281 | "$CONTRIB/build-wine/unsign.sh" || fail "files are different. windows." |
| 282 | "$CONTRIB/android/apkdiff.py" "$apk1" "$PROJECT_ROOT/dist/$apk1" || fail "files are different. android." |
| 283 | "$CONTRIB/android/apkdiff.py" "$apk2" "$PROJECT_ROOT/dist/$apk2" || fail "files are different. android." |
| 284 | "$CONTRIB/android/apkdiff.py" "$apk3" "$PROJECT_ROOT/dist/$apk3" || fail "files are different. android." |
| 285 | cmp --silent "$dmg" "$PROJECT_ROOT/dist/$dmg" || fail "files are different. macos." |
| 286 | # all files matched. sign them. |
| 287 | rm -rf "$PROJECT_ROOT/dist/sigs/" |
| 288 | mkdir --parents "$PROJECT_ROOT/dist/sigs/" |
| 289 | for fname in "$tarball" "$srctarball" "$appimage" "$win1" "$win2" "$win3" "$apk1" "$apk2" "$apk3" "$dmg" ; do |
| 290 | signame="$fname.$GPGUSER.asc" |
| 291 | gpg --sign --armor --detach $PUBKEY --output "$PROJECT_ROOT/dist/sigs/$signame" "$fname" |
| 292 | done |
| 293 | |
| 294 | if [ -z "$SSHUSER" ]; then |
| 295 | info "Signing successfully, now open a pull request with your signatures to spesmilo/electrum-signatures" |
| 296 | exit 0 |
| 297 | else |
| 298 | # upload sigs |
| 299 | ELECBUILD_UPLOADFROM="$PROJECT_ROOT/dist/sigs/" "$CONTRIB/upload.sh" |
| 300 | fi |
| 301 | |
| 302 | else |
| 303 | # ONLY release manager |
| 304 | |
| 305 | cd "$PROJECT_ROOT" |
| 306 | |
| 307 | # check we have each binary |
| 308 | test -f "$PROJECT_ROOT/dist/$tarball" || fail "tarball not found among built files" |
| 309 | test -f "$PROJECT_ROOT/dist/$srctarball" || fail "srctarball not found among built files" |
| 310 | test -f "$PROJECT_ROOT/dist/$appimage" || fail "appimage not found among built files" |
| 311 | test -f "$PROJECT_ROOT/dist/$win1" || fail "win1 not found among built files" |
| 312 | test -f "$PROJECT_ROOT/dist/$win2" || fail "win2 not found among built files" |
| 313 | test -f "$PROJECT_ROOT/dist/$win3" || fail "win3 not found among built files" |
| 314 | test -f "$PROJECT_ROOT/dist/$apk1" || fail "apk1 not found among built files" |
| 315 | test -f "$PROJECT_ROOT/dist/$apk2" || fail "apk2 not found among built files" |
| 316 | test -f "$PROJECT_ROOT/dist/$apk3" || fail "apk3 not found among built files" |
| 317 | test -f "$PROJECT_ROOT/dist/$dmg" || fail "dmg not found among built files" |
| 318 | |
| 319 | if [ "$REV" != "$VERSION" ]; then |
| 320 | fail "versions differ, not uploading" |
| 321 | fi |
| 322 | |
| 323 | # upload the files |
| 324 | ./contrib/upload.sh |
| 325 | |
| 326 | fi |
| 327 | |
| 328 | set +x |
| 329 | |
| 330 | info "release.sh finished successfully." |
| 331 | info "After two people ran release.sh, the binaries will be publicly available on uploadserver." |
| 332 | info "Then, we wait for additional signers, and run add_cosigner for them." |
| 333 | info "Finally, release_www.sh needs to be run, for the website to be updated." |