mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-08-30 16:53:31 +02:00
Fix wger startup permissions and nginx init
This commit is contained in:
@@ -1,5 +1,37 @@
|
|||||||
#!/usr/bin/env bashio
|
#!/usr/bin/env bashio
|
||||||
|
|
||||||
|
set -u
|
||||||
|
|
||||||
|
prepare_data_root() {
|
||||||
|
mkdir -p /data
|
||||||
|
chown wger /data || bashio::log.warning "Unable to set /data ownership to wger"
|
||||||
|
chmod a+rwx /data || bashio::log.warning "Unable to make /data writable"
|
||||||
|
}
|
||||||
|
|
||||||
|
prepare_writable_dir() {
|
||||||
|
local path="$1"
|
||||||
|
|
||||||
|
mkdir -p "$path"
|
||||||
|
chown -R wger "$path" || bashio::log.warning "Unable to set $path ownership to wger"
|
||||||
|
chmod -R a+rwX "$path" || bashio::log.warning "Unable to make $path writable"
|
||||||
|
}
|
||||||
|
|
||||||
|
move_persistent_dir() {
|
||||||
|
local source="$1"
|
||||||
|
local target="$2"
|
||||||
|
|
||||||
|
prepare_writable_dir "$target"
|
||||||
|
|
||||||
|
if [ -d "$source" ] && [ ! -L "$source" ]; then
|
||||||
|
if [ -n "$(ls -A "$source" 2> /dev/null)" ]; then
|
||||||
|
cp -rnf "$source"/. "$target"/
|
||||||
|
fi
|
||||||
|
rm -rf "$source"
|
||||||
|
fi
|
||||||
|
|
||||||
|
ln -sfn "$target" "$source"
|
||||||
|
}
|
||||||
|
|
||||||
############################
|
############################
|
||||||
# Change database location #
|
# Change database location #
|
||||||
############################
|
############################
|
||||||
@@ -11,56 +43,56 @@ if [ "${#SETTINGS_FILES[@]}" -gt 0 ]; then
|
|||||||
sed -i "s|/home/wger/db/database.sqlite|/data/database.sqlite|g" "$settings_file"
|
sed -i "s|/home/wger/db/database.sqlite|/data/database.sqlite|g" "$settings_file"
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
bashio::log.warning "Unable to find settings.py containing database path under /home, skipping rewrite"
|
bashio::log.warning "Unable to find Python settings containing database path under /home, skipping rewrite"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#####################
|
#####################
|
||||||
# Adapt directories #
|
# Adapt directories #
|
||||||
#####################
|
#####################
|
||||||
echo "... create directories"
|
echo "... create directories"
|
||||||
mkdir -p /data/static
|
prepare_data_root
|
||||||
if [ -d /home/wger/static ] && [ ! -L /home/wger/static ]; then
|
move_persistent_dir /home/wger/static /data/static
|
||||||
if [ -n "$(ls -A /home/wger/static 2> /dev/null)" ]; then
|
move_persistent_dir /home/wger/media /data/media
|
||||||
cp -rnf /home/wger/static/* /data/static/
|
|
||||||
fi
|
|
||||||
rm -r /home/wger/static
|
|
||||||
fi
|
|
||||||
ln -sf /data/static /home/wger
|
|
||||||
|
|
||||||
mkdir -p /data/media
|
|
||||||
if [ -d /home/wger/media ] && [ ! -L /home/wger/media ]; then
|
|
||||||
if [ -n "$(ls -A /home/wger/media 2> /dev/null)" ]; then
|
|
||||||
cp -rnf /home/wger/media/* /data/media/
|
|
||||||
fi
|
|
||||||
rm -r /home/wger/media
|
|
||||||
fi
|
|
||||||
ln -sf /data/media /home/wger
|
|
||||||
|
|
||||||
#####################
|
#####################
|
||||||
# Align permissions #
|
# Align permissions #
|
||||||
#####################
|
#####################
|
||||||
echo "... align permissions"
|
echo "... align permissions"
|
||||||
chown -R wger /data
|
prepare_writable_dir /data/static
|
||||||
chown -R wger /home/wger
|
prepare_writable_dir /data/media
|
||||||
chmod -R 777 /data
|
if [ -f /data/database.sqlite ]; then
|
||||||
|
chown wger /data/database.sqlite || bashio::log.warning "Unable to set /data/database.sqlite ownership to wger"
|
||||||
|
chmod a+rw /data/database.sqlite || bashio::log.warning "Unable to make /data/database.sqlite writable"
|
||||||
|
fi
|
||||||
|
|
||||||
echo "... add env variables"
|
echo "... add env variables"
|
||||||
(
|
(
|
||||||
set -o posix
|
set -o posix
|
||||||
export -p
|
export -p
|
||||||
) > /data/env.sh
|
) > /data/env.sh
|
||||||
while IFS= read -r line; do
|
|
||||||
[[ -z "$line" || "$line" =~ ^[[:space:]]*# ]] && continue
|
|
||||||
var="${line%%=*}"
|
|
||||||
sed -i "/^export[[:space:]]\+$var=/d" /data/env.sh
|
|
||||||
echo "export $line" >> /data/env.sh
|
|
||||||
done < /.env
|
|
||||||
|
|
||||||
chown wger /data/env.sh
|
if [ -f /.env ]; then
|
||||||
chmod +x /data/env.sh
|
while IFS= read -r line; do
|
||||||
|
[[ -z "$line" || "$line" =~ ^[[:space:]]*# ]] && continue
|
||||||
|
var="${line%%=*}"
|
||||||
|
[[ "$var" =~ ^[A-Za-z_][A-Za-z0-9_]*$ ]] || continue
|
||||||
|
sed -i "/^export[[:space:]]\+$var=/d" /data/env.sh
|
||||||
|
echo "export $line" >> /data/env.sh
|
||||||
|
done < /.env
|
||||||
|
fi
|
||||||
|
|
||||||
|
chown wger /data/env.sh || bashio::log.warning "Unable to set /data/env.sh ownership to wger"
|
||||||
|
chmod 0644 /data/env.sh || bashio::log.warning "Unable to make /data/env.sh readable"
|
||||||
|
|
||||||
bashio::log.info "Starting nginx"
|
bashio::log.info "Starting nginx"
|
||||||
nginx || true &
|
mkdir -p /run/nginx /var/log/nginx
|
||||||
true
|
if [ -f /run/nginx.pid ] && kill -0 "$(cat /run/nginx.pid)" 2> /dev/null; then
|
||||||
|
bashio::log.info "nginx is already running"
|
||||||
|
elif nginx -t; then
|
||||||
|
nginx
|
||||||
|
else
|
||||||
|
bashio::log.error "nginx configuration test failed"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
bashio::log.info "Starting entrypoint"
|
bashio::log.info "Starting entrypoint"
|
||||||
|
|||||||
Reference in New Issue
Block a user