unifi-docker/docker-build.sh

65 lines
1.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# fail on error
set -e
# Retry 5 times with a wait of 10 seconds between each retry
tryfail() {
for i in $(seq 1 5);
do [ $i -gt 1 ] && sleep 10; $* && s=0 && break || s=$?; done;
(exit $s)
}
# Try multiple keyservers in case of failure
addKey() {
for server in $(shuf -e ha.pool.sks-keyservers.net \
hkp://p80.pool.sks-keyservers.net:80 \
keyserver.ubuntu.com \
hkp://keyserver.ubuntu.com:80 \
pgp.mit.edu) ; do \
if apt-key adv --keyserver "$server" --recv "$1"; then
exit 0
fi
done
return 1
}
if [ "x${1}" == "x" ]; then
echo please pass PKGURL as an environment variable
exit 0
fi
apt-get update
apt-get install -qy --no-install-recommends \
apt-transport-https \
curl \
dirmngr \
gpg \
gpg-agent \
openjdk-8-jre-headless \
procps \
libcap2-bin
tryfail apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-3.6.list
apt-get update
echo "deb http://www.ubnt.com/downloads/unifi/debian unifi5 ubiquiti" > /etc/apt/sources.list.d/20ubiquiti.list
tryfail apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 06E85760C0A52C50
curl -L -o ./unifi.deb "${1}"
apt -qy install mongodb-org ./unifi.deb
rm -f ./unifi.deb
chown -R unifi:unifi /usr/lib/unifi
rm -rf /var/lib/apt/lists/*
rm -rf ${ODATADIR} ${OLOGDIR}
mkdir -p ${DATADIR} ${LOGDIR}
ln -s ${DATADIR} ${BASEDIR}/data
ln -s ${RUNDIR} ${BASEDIR}/run
ln -s ${LOGDIR} ${BASEDIR}/logs
rm -rf {$ODATADIR} ${OLOGDIR}
ln -s ${DATADIR} ${ODATADIR}
ln -s ${LOGDIR} ${OLOGDIR}
mkdir -p /var/cert ${CERTDIR}
ln -s ${CERTDIR} /var/cert/unifi
rm -rf "${0}"