2019-03-26 18:22:31 +01:00
#!/usr/bin/env bash
set -e
2019-03-26 18:37:12 +01:00
DIR = " $( cd " $( dirname " ${ BASH_SOURCE [0] } " ) " >/dev/null 2>& 1 && pwd ) "
SRC = " $DIR /git "
DST = " $DIR /dist "
2019-12-02 22:32:28 +01:00
2020-04-28 18:22:14 +02:00
while getopts ":r:o:d:" opt; do
2019-12-02 22:32:28 +01:00
case $opt in
r) REF = " $OPTARG "
; ;
o) OS_VERSION_NAME = " $OPTARG "
; ;
2020-04-28 18:22:14 +02:00
d) DB_TYPE = " $OPTARG "
; ;
2019-12-02 22:32:28 +01:00
\? ) echo " Invalid option - $OPTARG " >& 2
; ;
esac
done
2020-06-27 14:45:48 +02:00
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
2019-12-02 22:32:28 +01:00
if [ -z " $OS_VERSION_NAME " ] ; then OS_VERSION_NAME = 'buster' ; fi
2020-04-28 18:22:14 +02:00
if [ -z " $DB_TYPE " ] ; then DB_TYPE = "sqlite" ; fi
2019-03-26 18:37:12 +01:00
2019-03-26 18:52:45 +01:00
# Clone bitwarden_rs
2019-03-27 09:54:29 +01:00
if [ ! -d " $SRC " ] ; then
2019-03-26 18:37:12 +01:00
git clone https://github.com/dani-garcia/bitwarden_rs.git " $SRC "
2019-03-26 18:22:31 +01:00
fi
2019-03-27 09:54:29 +01:00
cd " $SRC " || exit
2019-09-21 14:38:46 +02:00
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
2019-03-27 09:54:29 +01:00
cd - || exit
2019-03-26 18:52:45 +01:00
# 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 "
2020-06-09 19:52:03 +02:00
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 "
2019-03-26 18:52:45 +01:00
2019-03-26 18:37:12 +01:00
mkdir -p " $DST "
2019-03-27 10:19:46 +01:00
# Prepare Dockerfile
2020-04-28 18:22:14 +02:00
patch -i " $DIR /Dockerfile.patch " " $SRC /docker/amd64/ $DB_TYPE /Dockerfile " -o " $DIR /Dockerfile " || exit
2019-12-02 22:32:28 +01:00
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 "
2019-03-27 10:19:46 +01:00
2020-04-28 18:22:14 +02:00
# 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
2019-03-26 18:37:12 +01:00
docker build -t bitwarden-deb " $DIR "
2019-03-26 18:22:31 +01:00
CID = $( docker run -d bitwarden-deb)
2020-04-28 18:22:14 +02:00
docker cp " $CID " :/bitwarden_package/bitwarden-rs.deb " $DST /bitwarden_rs- ${ OS_VERSION_NAME } - ${ REF } - ${ DB_TYPE } .deb "
2019-03-26 18:22:31 +01:00
docker rm " $CID "