This commit is contained in:
Alexandre
2025-01-05 10:57:55 +01:00
parent 9a1e4e8118
commit 3de9696b9c
4 changed files with 135 additions and 115 deletions

View File

@@ -27,15 +27,27 @@ ENV S6_CMD_WAIT_FOR_SERVICES=1 \
S6_CMD_WAIT_FOR_SERVICES_MAXTIME=0 \
S6_SERVICES_GRACETIME=0
ENV APACHE_RUN_USER=www-data \
APACHE_RUN_GROUP=www-data \
APACHE_PID_FILE=/var/run/apache2/apache2$SUFFIX.pid \
APACHE_RUN_DIR=/var/run/apache2$SUFFIX \
APACHE_LOCK_DIR=/var/lock/apache2$SUFFIX \
APACHE_LOG_DIR=/var/log/apache2$SUFFIX \
LANG=C \
APACHE_CONFDIR=/etc/apache2 \
APACHE_ENVVARS=/etc/apache2/envvars
# Global variables
ENV WEBTREES_HOME="/data/webtrees"
ENV WEBTREES_HOME="/var2/www/webtrees"
WORKDIR $WEBTREES_HOME
# hadolint ignore=DL4006
RUN \
# Change data location
grep -rl "/var/www/webtrees" /etc | xargs sed -i 's|/var/www/webtrees|/data/webtrees|g' \
&& sed -i 's|/var/www/webtrees|/data/webtrees|g' /docker-entrypoint.py
grep -rl "/var/www/webtrees" /etc | xargs sed -i 's|/var/www/webtrees|/var2/www/webtrees|g' \
&& sed -i 's|/var/www/webtrees|/var2/www/webtrees|g' /docker-entrypoint.py \
&& mkdir -p /var2 \
&& cp -rf /var/* /var2/ \
&& chown -R www-data:www-data /var2/www/webtrees
# Add end script
# && sed -i '$ d' /docker-entrypoint.py
@@ -61,7 +73,7 @@ RUN chmod 744 /ha_automodules.sh && /ha_automodules.sh "$MODULES" && rm /ha_auto
# Manual apps
ENV PACKAGES="jq \
curl \
yamllint"
yamllint nginx"
# Automatic apps & bashio
ADD "https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/ha_autoapps.sh" "/ha_autoapps.sh"
@@ -79,7 +91,6 @@ ADD "https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templat
ADD "https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/ha_entrypoint_modif.sh" "/ha_entrypoint_modif.sh"
RUN chmod 777 /ha_entrypoint.sh /ha_entrypoint_modif.sh && /ha_entrypoint_modif.sh && rm /ha_entrypoint_modif.sh
ENTRYPOINT [ "/usr/bin/env" ]
CMD [ "/ha_entrypoint.sh" ]

View File

@@ -76,24 +76,22 @@
"LANG": "en-US",
"PORT": "80",
"PRETTY_URLS": "1",
"WEBTREES_HOME": "/data/webtrees",
"WT_EMAIL": "me@example.com",
"WT_NAME": "Full Name",
"WT_PASS": "mybadpassword",
"WT_USER": "admin"
"PUID": "1000",
"PGID": "1000",
"WEBTREES_HOME": "/var2/www/webtrees"
},
"image": "ghcr.io/alexbelgium/webtrees-{arch}",
"init": false,
"map": [
"config:rw",
"addon_config:rw",
"homeassistant_config:rw",
"share:rw",
"ssl"
],
"name": "Webtrees",
"options": {
"BASE_URL": "http://192.168.178.23",
"CONFIG_LOCATION": "/config/addons_config/webtrees/config.yaml",
"DB_TYPE": "sqlite",
"DATA_LOCATION": "/config/data",
"certfile": "fullchain.pem",
"keyfile": "privkey.pem",
"ssl": false
@@ -112,8 +110,7 @@
],
"schema": {
"BASE_URL": "url",
"CONFIG_LOCATION": "str",
"DB_TYPE": "list(sqlite|external|mariadb_addon)",
"DATA_LOCATION": "str",
"base_url_portless": "bool?",
"certfile": "str",
"cifsdomain": "str?",
@@ -131,6 +128,6 @@
"slug": "webtrees",
"udev": true,
"url": "https://github.com/alexbelgium/hassio-addons",
"version": "2.2.1-2",
"version": "2.2.1-2_test",
"webui": "[PROTO:ssl]://[HOST]:[PORT:80]"
}

View File

@@ -0,0 +1,16 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
set -e
if bashio::services.available 'mysql'; then
bashio::log.green "---"
bashio::log.yellow "MariaDB addon was found! If you want to use it, you need to use those values when doing the initial startup wizard, or modify manually the config.ini.php file in /config/data (mapped to /addon_configs/xxx-webtrees/data when accessing using a third party tool)"
bashio::log.blue "Database user : $(bashio::services "mysql" "username")"
bashio::log.blue "Database password : $(bashio::services "mysql" "password")"
bashio::log.blue "Database name : webtrees"
bashio::log.blue "Host-name : $(bashio::services "mysql" "host")"
bashio::log.blue "Port : $(bashio::services "mysql" "port")"
bashio::log.green "---"
fi

View File

@@ -1,65 +1,72 @@
#!/usr/bin/env bashio
# shellcheck shell=bash
# shellcheck disable=SC2155
set -e
##############
# CLOUDFLARE #
##############
#############
# STRUCTURE #
#############
if bashio::config.true "base_url_portless"; then
export BASE_URL=$(bashio::config 'BASE_URL')
# Define variables
DATA_LOCATION="$(bashio::config "DATA_LOCATION")"
DATA_LOCATION="${DATA_LOCATION%/}"
DATA_LOCATION_FILE="/data/oldwebtreeshome"
# Create folders
mkdir -p "$DATA_LOCATION"
mkdir -p /config/modules_v4
cp -rn /var2/www/webtrees/data/* "$DATA_LOCATION"/ &>/dev/null || true
cp -rn /var2/www/webtrees/data/.* "$DATA_LOCATION"/ &>/dev/null || true
cp -rn /var2/www/webtrees/modules_v4/* /config/modules_v4/ &>/dev/null || true
# Check if a migration is needed
if bashio::fs.file_exists "$DATA_LOCATION_FILE"; then
DATA_LOCATION_CURRENT="$(cat "$DATA_LOCATION_FILE")"
DATA_LOCATION_CURRENT="${DATA_LOCATION_CURRENT%/}"
elif [[ -d /share/webtrees ]] && [[ "$(ls -A /share/webtrees)" ]]; then
DATA_LOCATION_CURRENT="/share/webtrees"
else
DATA_LOCATION_CURRENT="$DATA_LOCATION"
fi
###################
# Define database #
###################
# Migrate files
if [[ "$DATA_LOCATION_CURRENT" != "$DATA_LOCATION" ]] && [[ "$(ls -A "$DATA_LOCATION_CURRENT")" ]]; then
bashio::log.warning "Data location was changed from $DATA_LOCATION_CURRENT to $DATA_LOCATION, migrating files"
cp -rnf "$DATA_LOCATION_CURRENT"/* "$DATA_LOCATION"/ &>/dev/null || true
echo "Files moved to $DATA_LOCATION" > "$DATA_LOCATION_CURRENT"/migrated
mv "$DATA_LOCATION_CURRENT" "${DATA_LOCATION_CURRENT}_migrated"
fi
bashio::log.info "Defining database"
export DB_TYPE=$(bashio::config 'DB_TYPE')
case $(bashio::config 'DB_TYPE') in
# Saving data location
echo "... using data folder $DATA_LOCATION"
echo -n "$DATA_LOCATION" > "$DATA_LOCATION_FILE"
# Use sqlite
sqlite)
bashio::log.info "Using a local sqlite database $WEBTREES_HOME/$DB_NAME"
;;
# Update entrypoint
sed -i "s|DATA_DIR = os.path.join(ROOT, \"data\")|DATA_DIR = \"$DATA_LOCATION\"|" /docker-entrypoint.py
mariadb_addon)
bashio::log.info "Using MariaDB addon. Requirements : running MariaDB addon. Discovering values..."
if ! bashio::services.available 'mysql'; then
bashio::log.fatal \
"Local database access should be provided by the MariaDB addon"
bashio::exit.nok \
"Please ensure it is installed and started"
fi
# Use values
export DB_TYPE=mysql
export DB_HOST=$(bashio::services "mysql" "host") && bashio::log.blue "DB_HOST=$DB_HOST"
export DB_PORT=$(bashio::services "mysql" "port") && bashio::log.blue "DB_PORT=$DB_PORT"
export DB_NAME=webtrees && bashio::log.blue "DB_NAME=$DB_NAME"
export DB_USER=$(bashio::services "mysql" "username") && bashio::log.blue "DB_USER=$DB_USER"
export DB_PASS=$(bashio::services "mysql" "password") && bashio::log.blue "DB_PASS=$DB_PASS"
bashio::log.warning "Webtrees is using the Maria DB addon"
bashio::log.warning "Please ensure this is included in your backups"
bashio::log.warning "Uninstalling the MariaDB addon will remove any data"
# Create database
mysql --host="$(bashio::services 'mysql' 'host')" --port="$(bashio::services 'mysql' 'port')" --user="$(bashio::services "mysql" "username")" --password="$(bashio::services "mysql" "password")" -e"CREATE DATABASE IF NOT EXISTS webtrees;"
;;
external)
bashio::log.info "Using an external database, please populate all required fields in the config.yaml according to documentation"
;;
esac
# Creating symlinks
echo "... creating symlinks"
rm -r /var2/www/webtrees/data
ln -sf "$DATA_LOCATION" /var2/www/webtrees/data
rm -r /var2/www/webtrees/modules_v4
ln -sf "/config/modules_v4" /var2/www/webtrees/modules_v4
# Update permissions on target directories
echo "... update permissions"
chown -R www-data:www-data "$DATA_LOCATION"
chmod -R 755 "$DATA_LOCATION"
chown -R www-data:www-data "/config"
chmod -R 755 "/config"
################
# SSL CONFIG #
################
BASE_URL=$(bashio::config 'BASE_URL')
# Remove the http
BASE_URL="${BASE_URL#*//}"
# Remove the port
BASE_URL="${BASE_URL%%:*}"
bashio::config.require.ssl
if bashio::config.true 'ssl'; then
@@ -75,90 +82,79 @@ if bashio::config.true 'ssl'; then
export HTTPS=true
export SSL=true
export HTTPS_REDIRECT=true
BASE_URL=$(bashio::config 'BASE_URL'):$(bashio::addon.port 443)
export BASE_URL="${BASE_URL/http:/https:}"
BASE_URL_PORT=":$(bashio::addon.port 443)"
if [[ "$BASE_URL_PORT" == ":443" ]]; then BASE_URL_PORT=""; fi
BASE_URL_PROTO="https"
#Communication
bashio::log.info "Ssl enabled. If webui don't work, disable ssl or check your certificate paths"
bashio::log.info "Ssl enabled. If webui don't work, check if the port 443 was opened in the addon options, disable ssl or check your certificate paths"
else
export HTTPS=false
export SSL=false
export HTTPS_REDIRECT=false
BASE_URL=$(bashio::config 'BASE_URL'):$(bashio::addon.port 80)
export BASE_URL="${BASE_URL/https:/http:}"
BASE_URL_PORT=":$(bashio::addon.port 80)"
if [[ "$BASE_URL_PORT" == ":80" ]]; then BASE_URL_PORT=""; fi
BASE_URL_PROTO="http"
fi
if [[ "$BASE_URL_PORT" == ":" ]]; then
bashio::log.fatal "Your $BASE_URL_PROTO port is not set in the addon options, please check your configuration and restart"
bashio::addon.stop
fi
BASE_URL="${BASE_URL_PROTO}://${BASE_URL}${BASE_URL_PORT}"
export BASE_URL
# CLOUDFLARE
if bashio::config.true "base_url_portless"; then
export BASE_URL=$(bashio::config 'BASE_URL')
fi
# Correct base url if needed
echo "... align base url with latest addon value"
if [ -f "$DATA_LOCATION"/config.ini.php ]; then
echo "Aligning base_url addon config"
LINE=$(sed -n '/base_url/=' "$DATA_LOCATION"/config.ini.php)
sed -i "$LINE a base_url=\"$BASE_URL\"" "$DATA_LOCATION"/config.ini.php
sed -i "$LINE d" "$DATA_LOCATION"/config.ini.php
fi || true
##############
# LAUNCH APP #
##############
bashio::log.info "Launching app, please wait"
# Change data location
echo "... update data with image"
OLD_WEBTREES_HOME="$WEBTREES_HOME"
export WEBTREES_HOME="/share/webtrees"
cp -rn /var/www/webtrees "$(dirname "$OLD_WEBTREES_HOME")" &>/dev/null || true
mkdir -p "$WEBTREES_HOME"
echo "... update permissions"
chown -R www-data:www-data "$OLD_WEBTREES_HOME"
chown -R www-data:www-data "$WEBTREES_HOME"
# Make links with share
echo "... make links with data in /share"
for VOL in "data" "modules_v4"; do
mkdir -p "$OLD_WEBTREES_HOME"/"$VOL"
cp -rn "$OLD_WEBTREES_HOME"/"$VOL" "$WEBTREES_HOME" || true
# shellcheck disable=SC2115
rm -r "$OLD_WEBTREES_HOME"/"$VOL" || true
echo "... linking $VOL"
ln -s "$WEBTREES_HOME"/"$VOL" "$OLD_WEBTREES_HOME"
done
chown -R www-data:www-data "$WEBTREES_HOME"
# Correct base url if needed
echo "... align base url with latest addon value"
if [ -f "$WEBTREES_HOME"/data/config.ini.php ]; then
echo "Aligning base_url addon config"
LINE=$(sed -n '/base_url/=' "$WEBTREES_HOME"/data/config.ini.php)
sed -i "$LINE a base_url=\"$BASE_URL\"" "$WEBTREES_HOME"/data/config.ini.php
sed -i "$LINE d" "$WEBTREES_HOME"/data/config.ini.php
fi || true
###################
# TRUSTED HEADERS #
###################
if bashio::config.has_value "trusted_headers" && [ -f "$WEBTREES_HOME"/data/config.ini.php ]; then
if bashio::config.has_value "trusted_headers" && [ -f "$DATA_LOCATION"/config.ini.php ]; then
bashio::log.info "Aligning trusted_headers addon config (use single address, or a range of addresses in CIDR format)"
sed -i "/trusted_headers/ d" "$WEBTREES_HOME"/data/config.ini.php
sed -i "1a trusted_headers=\"$(bashio::config 'trusted_headers')\"" "$WEBTREES_HOME"/data/config.ini.php
elif [ -f "$WEBTREES_HOME"/data/config.ini.php ]; then
sed -i "/trusted_headers/ d" "$DATA_LOCATION"/config.ini.php
sed -i "1a trusted_headers=\"$(bashio::config 'trusted_headers')\"" "$DATA_LOCATION"/config.ini.php
elif [ -f "$DATA_LOCATION"/config.ini.php ]; then
bashio::log.info "Aligning trusted_headers addon config with cf-connecting-ip"
sed -i "/trusted_headers/ d" "$WEBTREES_HOME"/data/config.ini.php
sed -i "1a trusted_headers=\"cf-connecting-ip\"" "$WEBTREES_HOME"/data/config.ini.php
sed -i "/trusted_headers/ d" "$DATA_LOCATION"/config.ini.php
sed -i "1a trusted_headers=\"cf-connecting-ip\"" "$DATA_LOCATION"/config.ini.php
fi
############
# END INFO #
############
DB_NAME=$(echo "$DB_NAME" | tr -d '"')
bashio::log.info "Data is stored in $DATA_LOCATION"
bashio::log.info "Data is stored in $WEBTREES_HOME"
bashio::log.info "Webui can be accessed at : $BASE_URL"
bashio::log.info "If it is your first boot, the start-up wizard will open"
echo "... Starting nginx"
nginx & true
# Execute main script
source /etc/apache2/envvars
echo "python3 /docker-entrypoint.py"
cd /
python3 /docker-entrypoint.py
cd /var2/www/webtrees
if [ ! -f "${DATA_LOCATION}/config.ini.php" ]; then
bashio::log.info "First boot : open the UI at $BASE_URL to access the start-up wizard"
python3 /docker-entrypoint.py
else
bashio::log.info "Webtrees started. You can access your webui at : $BASE_URL"
python3 /docker-entrypoint.py
fi