|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -e |
| 4 | + |
| 5 | +usage() { |
| 6 | + echo "Usage: $0 -v <version> -c <config file> [-n]" |
| 7 | + echo |
| 8 | + echo "version: commit-ish to check out and build" |
| 9 | + echo "config file: a path to a json config file to" |
| 10 | + echo "ship with the build. In addition, update_base_url:" |
| 11 | + echo "from this file is used to set up auto-update." |
| 12 | + echo "-n: build with no config file." |
| 13 | + echo |
| 14 | + echo "Values may also be passed as environment variables" |
| 15 | +} |
| 16 | + |
| 17 | +conffile= |
| 18 | +version= |
| 19 | +skipcfg=0 |
| 20 | +while getopts "c:v:n" opt; do |
| 21 | + case $opt in |
| 22 | + c) |
| 23 | + conffile=$OPTARG |
| 24 | + ;; |
| 25 | + v) |
| 26 | + version=$OPTARG |
| 27 | + ;; |
| 28 | + n) |
| 29 | + skipcfg=1 |
| 30 | + ;; |
| 31 | + \?) |
| 32 | + echo "Invalid option: -$OPTARG" >&2 |
| 33 | + usage |
| 34 | + exit |
| 35 | + ;; |
| 36 | + esac |
| 37 | +done |
| 38 | + |
| 39 | +if [ -z "$version" ]; then |
| 40 | + echo "No version supplied" |
| 41 | + usage |
| 42 | + exit |
| 43 | +fi |
| 44 | + |
| 45 | +if [ -z "$conffile" ] && [ "$skipcfg" = 0 ]; then |
| 46 | + echo "No config file given. Use -c to supply a config file or" |
| 47 | + echo "-n to build with no config file (and no auto update)." |
| 48 | + exit |
| 49 | +fi |
| 50 | + |
| 51 | +if [ -n "$conffile" ]; then |
| 52 | + update_base_url=`jq -r .update_base_url $conffile` |
| 53 | + |
| 54 | + if [ -z "$update_base_url" ]; then |
| 55 | + echo "No update URL supplied. Use update_base_url: null if you really" |
| 56 | + echo "want a build with no auto-update." |
| 57 | + usage |
| 58 | + exit |
| 59 | + fi |
| 60 | + # Make sure the base URL ends in a slash if it doesn't already |
| 61 | + update_base_url=`echo $update_base_url | sed -e 's#\([^\/]\)$#\1\/#'` |
| 62 | +fi |
| 63 | + |
| 64 | +if [ ! -f package.json ]; then |
| 65 | + echo "No package.json found. This script must be run from" |
| 66 | + echo "the vector-web directory." |
| 67 | + exit |
| 68 | +fi |
| 69 | + |
| 70 | +echo "Building $version using Update base URL $update_base_url" |
| 71 | + |
| 72 | +projdir=`pwd` |
| 73 | +builddir=`mktemp -d 2>/dev/null || mktemp -d -t 'buildtmp'` |
| 74 | +pushd "$builddir" |
| 75 | +git clone "$projdir" . |
| 76 | +git checkout "$version" |
| 77 | + |
| 78 | +if [ -n "$conffile" ]; then |
| 79 | + popd |
| 80 | + cp "$conffile" "$builddir/" |
| 81 | + pushd "$builddir" |
| 82 | +fi |
| 83 | + |
| 84 | +if [ "$update_base_url" != "null" ]; then |
| 85 | + # Inject a 'publish' configuration into the package.json. This is what |
| 86 | + # electron-builder needs for auto-update on windows but we don't want to |
| 87 | + # keep it in the package.json as we don't want everyone cloning the source |
| 88 | + # and building it for themselves to get our auto-update URL. |
| 89 | + update_url=$update_base_url/install/win32/ |
| 90 | + jq '.build.publish.provider="generic"' package.json \ |
| 91 | + | jq '.build.publish.url="$update_url"' \ |
| 92 | + > package.json.tmp |
| 93 | + mv package.json.tmp package.json |
| 94 | +fi |
| 95 | + |
| 96 | +npm install |
| 97 | +npm run build:electron |
| 98 | + |
| 99 | +popd |
| 100 | + |
| 101 | +distdir="$builddir/electron/dist" |
| 102 | +pubdir="$projdir/electron/pub" |
| 103 | +rm -r "$pubdir" || true |
| 104 | +mkdir -p "$pubdir" |
| 105 | + |
| 106 | +# figure out what version this build is known as |
| 107 | +# (since we could be building from a branch or indeed |
| 108 | +# any commit-ish, not just a version tag) |
| 109 | +vername=`python -c 'import yaml; import sys; print yaml.load(sys.stdin)["version"]' < $builddir/electron/dist/latest.yml` |
| 110 | + |
| 111 | +# Install packages: what the user downloads the first time, |
| 112 | +# (DMGs for mac, exe installer for windows) |
| 113 | +mkdir -p "$pubdir/install/macos" |
| 114 | +cp $distdir/mac/*.dmg "$pubdir/install/macos/" |
| 115 | + |
| 116 | +mkdir -p "$pubdir/install/win32/" |
| 117 | +cp $distdir/*.exe "$pubdir/install/win32/" |
| 118 | +cp $distdir/latest.yml "$pubdir/install/win32/" |
| 119 | + |
| 120 | +# Packages for auto-update on mac (Windows (NSIS) uses the installer exe) |
| 121 | +mkdir -p "$pubdir/update/macos" |
| 122 | +cp $distdir/mac/*.zip "$pubdir/update/macos/" |
| 123 | +echo "$ver" > "$pubdir/update/macos/latest" |
| 124 | + |
| 125 | +# Move the debs to the main project dir's dist folder |
| 126 | +rm -r "$projdir/electron/dist" || true |
| 127 | +mkdir -p "$projdir/electron/dist" |
| 128 | +cp $distdir/*.deb "$projdir/electron/dist/" |
| 129 | + |
| 130 | +rm -rf "$builddir" |
| 131 | + |
| 132 | +echo "Riot Desktop $vername is ready to go in $pubdir: this directory can be hosted on your web server." |
| 133 | +echo "deb archives are in electron/dist/ - these should be added into your debian repository" |
0 commit comments