Files
docker-heimdall/root/etc/cont-init.d/50-config

67 lines
1.9 KiB
Plaintext

#!/usr/bin/with-contenv bash
# make our folders
mkdir -p \
/config/www/{backgrounds,icons,avatars,SupportedApps} \
/var/www/localhost/heimdall
# install heimdall if necessary
[[ -f /heimdall/heimdall.tar.gz ]] && \
echo "New container detected, installing Heimdall" && \
tar xf \
/heimdall/heimdall.tar.gz -C \
/var/www/localhost/heimdall --strip-components=1 && \
echo -e '\n# Heimdall user authorization\nfastcgi_param PHP_AUTH_USER $remote_user;\nfastcgi_param PHP_AUTH_PW $http_authorization;' >> \
/etc/nginx/fastcgi_params && \
rm -rf /heimdall
# create symlinks
symlinks=( \
/var/www/localhost/heimdall/storage/app/public/avatars \
/var/www/localhost/heimdall/storage/app/public/backgrounds \
/var/www/localhost/heimdall/storage/app/public/icons \
/var/www/localhost/heimdall/app/SupportedApps \
/var/www/localhost/heimdall/database/app.sqlite \
/var/www/localhost/heimdall/.env )
for i in "${symlinks[@]}"
do
[[ -e "$i" && ! -L "$i" ]] && rm -rf "$i"
[[ ! -L "$i" ]] && ln -s /config/www/"$(basename "$i")" "$i"
done
# copy .env if not exists
[[ ! -f /config/www/.env ]] && \
cp /var/www/localhost/heimdall/.env.example /config/www/.env && \
echo "Creating app key. This may take a while on slower systems" && \
php /var/www/localhost/heimdall/artisan key:generate
# set queue driver to database
sed -i 's/QUEUE_DRIVER=sync/QUEUE_DRIVER=database/' /config/www/.env
# function to randomly sample 5 files for their owner and only chown if not abc
chowner () {
files=(${1}/*)
for i in {1..5}; do
user=$(stat -c '%U' $(printf "%s\n" "${files[RANDOM % ${#files[@]}]}"))
if [ "${user}" != "abc" ]; then
chown -R abc:abc ${1}
break
fi
done
}
# permissions
echo "Setting permissions"
abc_dirs=( \
/config \
/var/www/localhost/heimdall \
)
for i in "${abc_dirs[@]}"; do
if [ "$(ls -A ${i})" ]; then
chowner ${i}
else
chown -R abc:abc ${i}
fi
done