bitwarden_rs-debian/build.sh
Christian Eriksson 9989534983
Support for arm32v7 (#25)
* Move Dockerfile.patch files to architecture dependent directories

Need a way to distinguish between patches when we implement support for other architectures.
Putting them in different paths seems simple and straight forward enough.

* Add -a option to support arm32v7 and amd64 architectures

Previous releases lacked support for compiling for arm32v7 architecture.
In order to keep previous behaviour the default is set to amd64. Using the
-a option, users can now choose between arm32v7 and amd64. If arm32v7 is
used only the Buster release of debian is supported. The limitation is
due to the libmariadb3:armhf dependency not being avaliable in earlier
debian releases.

* Update documentation to detail the -a option

* Remove reference to local dirs

* Set debian package to report correct architecture for arm32v7 build

* Format arm32v7 Dockerfile.patch to match the amd64

* Handle architecture property in control file dynamically

Similar to version, the architecture property in the control file should be
handled dynamically. The build script will now replace the architecture prop
from control.dist to match the choosen architecture.
2020-11-10 11:08:37 +01:00

79 lines
2.8 KiB
Bash
Executable File

#!/usr/bin/env bash
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
SRC="$DIR/git"
DST="$DIR/dist"
while getopts ":r:o:d:a:" opt; do
case $opt in
r) REF="$OPTARG"
;;
o) OS_VERSION_NAME="$OPTARG"
;;
d) DB_TYPE="$OPTARG"
;;
a) ARCH_DIR="$OPTARG"
;;
\?) echo "Invalid option -$OPTARG" >&2
;;
esac
done
if [ -z "$REF" ]; then REF=$(curl -s https://api.github.com/repos/dani-garcia/bitwarden_rs/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/' | cut -c 1-); fi
if [ -z "$OS_VERSION_NAME" ]; then OS_VERSION_NAME='buster'; fi
if [ -z "$DB_TYPE" ]; then DB_TYPE="sqlite"; fi
if [ -z "$ARCH_DIR" ]; then ARCH_DIR="amd64"; fi
ARCH=$ARCH_DIR
if [[ "$ARCH" =~ ^arm ]]; then ARCH="armhf"; fi
# Clone bitwarden_rs
if [ ! -d "$SRC" ]; then
git clone https://github.com/dani-garcia/bitwarden_rs.git "$SRC"
fi
cd "$SRC" || exit
CREF="$(git branch | grep \* | cut -d ' ' -f2)"
if [ "$CREF" != "$REF" ]; then
git fetch
git checkout "$REF" --force
else
git clean -d -f
git pull
fi
cd - || exit
# Prepare EnvFile
CONFIG="$DIR/debian/config.env"
cp "$SRC/.env.template" "$CONFIG"
sed -i "s#\# DATA_FOLDER=data#DATA_FOLDER=/var/lib/bitwarden_rs#" "$CONFIG"
sed -i "s#\# WEB_VAULT_FOLDER=web-vault/#WEB_VAULT_FOLDER=/usr/share/bitwarden_rs/web-vault/#" "$CONFIG"
sed -i "s/Uncomment any of the following lines to change the defaults/Uncomment any of the following lines to change the defaults\n\n## Warning\n## The default systemd-unit does not allow any custom directories.\n## Be sure to check if the service has appropriate permissions before you set custom paths./g" "$CONFIG"
mkdir -p "$DST"
# Prepare Dockerfile
patch -i "$DIR/patch/$ARCH_DIR/Dockerfile.patch" "$SRC/docker/$ARCH_DIR/Dockerfile" --verbose -o "$DIR/Dockerfile" || exit
sed -E "s/(FROM[[:space:]]*rust:)[^[:space:]]+(.+)/\1${OS_VERSION_NAME}\2/g" -i "$DIR/Dockerfile"
sed -E "s/(FROM[[:space:]]*debian:)[^-]+(-.+)/\1${OS_VERSION_NAME}\2/g" -i "$DIR/Dockerfile"
# Prepare Controlfile
CONTROL="$DIR/debian/control"
cp "$DIR/control.dist" "$CONTROL"
sed -i "s/Version:.*/Version: $REF-1/" "$CONTROL"
sed -i "s/Architecture:.*/Architecture: $ARCH/" "$CONTROL"
# Prepare Systemd-unit
SYSTEMD_UNIT="$DIR/debian/bitwarden_rs.service"
if [ "$DB_TYPE" = "mysql" ]; then
sed -i "s/After=network.target/After=network.target mysqld.service\nRequires=mysqld.service/g" "$SYSTEMD_UNIT"
elif [ "$DB_TYPE" = "postgresql" ]; then
sed -i "s/After=network.target/After=network.target postgresql.service\nRequires=postgresql.service/g" "$SYSTEMD_UNIT"
fi
echo "[INFO] docker build -t bitwarden-deb "$DIR" --build-arg DB=$DB_TYPE"
docker build -t bitwarden-deb "$DIR" --build-arg DB=$DB_TYPE
CID=$(docker run -d bitwarden-deb)
docker cp "$CID":/bitwarden_package/bitwarden-rs.deb "$DST/bitwarden_rs-${OS_VERSION_NAME}-${REF}-${DB_TYPE}-${ARCH_DIR}.deb"
docker rm "$CID"