Unifi fixes (#99)

* fix database creation, set rc script executable

* fix lint errors

* fix typo
This commit is contained in:
Matt Coleman 2020-05-05 08:58:49 -04:00 committed by GitHub
parent dbfbd489fa
commit 795eb809af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -34,7 +34,7 @@ UP_USER="${!UP_USER:-$1}"
UP_PASS="jail_${1}_up_password" UP_PASS="jail_${1}_up_password"
INCLUDES_PATH="${SCRIPT_DIR}/blueprints/unifi/includes" INCLUDES_PATH="${SCRIPT_DIR}/blueprints/unifi/includes"
if [ -z "${!DB_PASSWORD}" ]; then if [ -z "${!DB_PASS}" ]; then
echo "up_db_password can't be empty" echo "up_db_password can't be empty"
exit 1 exit 1
fi fi
@ -70,7 +70,7 @@ else
# Check if influxdb container exists, create unifi database if it does, error if it is not. # Check if influxdb container exists, create unifi database if it does, error if it is not.
echo "Checking if the database jail and database exist..." echo "Checking if the database jail and database exist..."
if [[ -d /mnt/"${global_dataset_iocage}"/jails/"${!DB_JAIL}" ]]; then if [[ -d /mnt/"${global_dataset_iocage}"/jails/"${!DB_JAIL}" ]]; then
DB_EXISTING=$(iocage exec "${!DB_JAIL}" curl -G http://localhost:8086/query --data-urlencode 'q=SHOW DATABASES' | jq '.results [] | .series [] | .values []' | grep "$DB_NAME" | sed 's/"//g' | sed 's/^ *//g') DB_EXISTING=$(iocage exec "${!DB_JAIL}" curl -G http://"${DB_IP}":8086/query --data-urlencode 'q=SHOW DATABASES' | jq '.results [] | .series [] | .values []' | grep "$DB_NAME" | sed 's/"//g' | sed 's/^ *//g')
if [[ "$DB_NAME" == "$DB_EXISTING" ]]; then if [[ "$DB_NAME" == "$DB_EXISTING" ]]; then
echo "${!DB_JAIL} jail with database ${DB_NAME} already exists. Skipping database creation... " echo "${!DB_JAIL} jail with database ${DB_NAME} already exists. Skipping database creation... "
else else
@ -79,7 +79,8 @@ else
echo "Database username and password not provided. Cannot create database without credentials. Exiting..." echo "Database username and password not provided. Cannot create database without credentials. Exiting..."
exit 1 exit 1
else else
iocage exec "${!DB_JAIL}" "curl -XPOST -u ${DB_USER}:${!DB_PASS} http://localhost:8086/query --data-urlencode 'q=CREATE DATABASE ${DB_NAME}'" # shellcheck disable=SC2027,2086
iocage exec "${!DB_JAIL}" "curl -XPOST -u ${DB_USER}:${!DB_PASS} http://"${DB_IP}":8086/query --data-urlencode 'q=CREATE DATABASE ${DB_NAME}'"
echo "Database ${DB_NAME} created with username ${DB_USER} with password ${!DB_PASS}." echo "Database ${DB_NAME} created with username ${DB_USER} with password ${!DB_PASS}."
fi fi
fi fi
@ -99,6 +100,7 @@ else
cp "${INCLUDES_PATH}"/up.conf /mnt/"${global_dataset_config}"/"${1}" cp "${INCLUDES_PATH}"/up.conf /mnt/"${global_dataset_config}"/"${1}"
# shellcheck disable=SC2154 # shellcheck disable=SC2154
cp "${INCLUDES_PATH}"/rc/unifi_poller.rc /mnt/"${global_dataset_iocage}"/jails/"${1}"/root/usr/local/etc/rc.d/unifi_poller cp "${INCLUDES_PATH}"/rc/unifi_poller.rc /mnt/"${global_dataset_iocage}"/jails/"${1}"/root/usr/local/etc/rc.d/unifi_poller
chmod +x /mnt/"${global_dataset_iocage}"/jails/"${1}"/root/usr/local/etc/rc.d/unifi_poller
iocage exec "${1}" sed -i '' "s|influxdbuser|${DB_USER}|" /config/up.conf iocage exec "${1}" sed -i '' "s|influxdbuser|${DB_USER}|" /config/up.conf
iocage exec "${1}" sed -i '' "s|influxdbpass|${!DB_PASS}|" /config/up.conf iocage exec "${1}" sed -i '' "s|influxdbpass|${!DB_PASS}|" /config/up.conf
iocage exec "${1}" sed -i '' "s|unifidb|${DB_NAME}|" /config/up.conf iocage exec "${1}" sed -i '' "s|unifidb|${DB_NAME}|" /config/up.conf