diff --git a/build.sh b/build.sh index 3ff34d6..2bc5eb7 100755 --- a/build.sh +++ b/build.sh @@ -2,35 +2,106 @@ set -e -apt-get update +echo "Updating apt..." +apt-get -qq update -apt-get -q -y -o Dpkg::Use-Pty=0 install curl jq +echo "Installing get tools..." +apt-get -qq -y --no-install-recommends install curl jq ca-certificates git > /dev/null -REPO_NAME=deltachat/deltachat-desktop -TAG_NAME=$(curl --silent --fail --show-error "https://api.github.com/repos/$REPO_NAME/releases/latest" | jq -r .tag_name) +REPO_NAME="deltachat/deltachat-desktop" +REPO_URL="https://github.com/${REPO_NAME}.git" -GET_SRC_MODE="tar" -SRC_DIR_PATH="./" - -if [ $GET_SRC_MODE = "github-tar" ]; then - mkdir tmp_extract - curl --silent --fail -L "https://api.github.com/repos/${REPO_NAME}/tarball/${TAG_NAME}" -o - | tar xvz -f - -C "$SRC_DIR_PATH" || rm -rf tmp_extract && exit 1 - mv tmp_extract/* ../src +if [ -z ${1+x} ]; then + echo "No release selected, selecting the latest..." + CHECKOUT="$(curl --silent --fail --show-error "https://api.github.com/repos/${REPO_NAME}/releases/latest" | jq -r .tag_name)" + echo "Latest release: ${CHECKOUT}" else - if [ $GET_SRC_MODE = "github" ] - git clone "https://github.com/${REPO_NAME}.git" src - cd src - git checkout "${TAG_NAME}" - cd .. - else - echo "Not valid mode" - exit 1 - fi + CHECKOUT="${1}" + echo "Release selected: ${CHECKOUT}" fi -apt-get -q -y -o Dpkg::Use-Pty=0 --no-install-recommends install npm cargo +echo "Getting the source..." +./getsauce.sh "git" \ + "${REPO_URL}" \ + "${CHECKOUT}" + +cd project + +echo "Installing build dependencies (apt)..." +apt-get -qq -y --no-install-recommends install npm cargo > /dev/null +echo "Installing build dependencies (npm)..." +npm install +echo "Build dependencies installed." -npm install --no-audit +echo "Building the app..." NODE_ENV=production npm run build NO_ASAR=true npm run pack:generate_config +echo "App built successfully." + +echo "Packaging..." npm run pack:linux +echo "App packaged successfully." + +cd .. + +echo "Package(s) deploy..." +mkdir pkg +cp project/dist/*.deb pkg/ + +echo "Moving package(s) to the repo..." +mkdir -p repo +chmod 600 keys +mv pkg/*.deb repo/ + +cd repo + +echo "Updating the repo..." +apt-ftparchive packages . > Packages +gzip -k -f Packages +apt-ftparchive release . > Release + +cd .. + +apt-get -qq -y --no-install-recommends install gpg gpg-agent + +echo "Checking if is possible to sign the repo..." +mkdir -p keys +chmod 600 keys +export GNUPGHOME="${PWD}/keys" + +if [ ! -f "keys/pubring.kbx" ]; then + echo "The file 'pubring.kbx' file has not been found. Generating automatically a new one with a new set of keys..." + KEY_NAME="Joe Tester" + KEY_PASSPHRASE="over-the-lazy-dog" + cat >foo_keys < keys/passphrase +fi + +if [ -z ${GPG_SUBKEY_ID+x} ]; then + echo "A GPG key id has not been defined. Automatically selecting a fingerprint..." + # List key and its subkey with their respective fingerprints | filter fingerprints of both keys | pick fingerprint of the second row + # (the subkey seems to be listed always after its respective subkey) + GPG_SUBKEY_ID="$(gpg --list-secret-key --with-subkey-fingerprint --with-colons | awk -F: '$1 == "fpr" {print $10;}' | sed -n '2 p')" +fi + +echo "Signing the repo..." +gpg --passphrase-file keys/passphrase --pinentry-mode loopback --default-key $GPG_SUBKEY_ID -abs -o - repo/Release > repo/Release.gpg +gpg --passphrase-fd keys/passphrase --pinentry-mode loopback --default-key $GPG_SUBKEY_ID --clearsign -o - repo/Release > repo/InRelease +echo "Done." + diff --git a/getsauce.sh b/getsauce.sh new file mode 100755 index 0000000..9ba52b2 --- /dev/null +++ b/getsauce.sh @@ -0,0 +1,54 @@ +#!/bin/sh + +set -e + +if [ $# -eq 0 ]; then + echo "No arguments provided. Aborting..." + exit 1 +fi + +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then + echo "usage: ./getsauce.sh [-h] [mode [checkout]] + +Retrieves the source for you. + +Possible values for the arguments: + +mode git, github-tar +URL url of the repo +repoName name of the repo with user/org included (e.g. username/repo or organization/repo) +checkout tag, branch or complete hash of a commit + +Dependencies: curl jq ca-certificates git +" + exit 0 +fi + +if [ $# -lt 3 ]; then + echo "Arguments \"mode\" and \"URL/repoName\" not provided. Aborting..." + exit 1 +fi + + +GET_SRC_MODE=$1 +URL_REPONAME=$2 +[ ! -z ${3+x} ] && CHECKOUT=$3 +[ -z ${REPO_PATH+x} ] && REPO_PATH="project" +SRC_DIR_PATH="./" +TMP_DIR="tmp_extract" + +if [ $GET_SRC_MODE = "github-tar" ]; then + mkdir "${TMP_DIR}" + curl --silent --fail -L "https://api.github.com/repos/${URL_REPONAME}/tarball/${CHECKOUT}" -o - | tar xvz -f - -C "$SRC_DIR_PATH" || rm -rf "${TMP_DIR}" && exit 1 + mv "${TMP_DIR}"/* "${REPO_PATH}/" +elif [ $GET_SRC_MODE = "git" ]; then + TMP_POSITION="${PWD}" + git clone "${URL_REPONAME}" "${REPO_PATH}" + cd "${REPO_PATH}" + [ ! -z ${CHECKOUT+x} ] && git checkout "${CHECKOUT}" + cd "${TMP_POSITION}" +else + echo "Not valid mode" + exit 1 +fi +