entrypoint logic

This commit is contained in:
Alexandre
2021-11-13 13:02:39 +01:00
parent 2acb25daf8
commit 11b402cb10
16 changed files with 144 additions and 76 deletions

View File

@@ -8,7 +8,6 @@ COPY rootfs /
ARG BASHIO_VERSION=0.13.1
ENV WEBTREES_HOME="/data/webtrees"
WORKDIR $WEBTREES_HOME
ENTRYPOINT ["/run.sh"]
VOLUME ["/data"]
RUN \
@@ -36,14 +35,16 @@ RUN \
# Modify image #
################
# Change data location
&& grep -rl "/var/www/webtrees" /etc/ | xargs sed -i 's|/var/www/webtrees|/data/webtrees|g' \
\
# Add entry script
&& chown root:root /run.sh \
&& chmod a+x /run.sh \
&& grep -rl "/var/www/webtrees" /etc/ | xargs sed -i 's|/var/www/webtrees|/data/webtrees|g' || true
# Add entry script
RUN chown root:root /entrypoint.sh \
&& chmod 777 /entrypoint.sh \
# Add end script
&& sed -i '$ d' /docker-entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
### LABELS
ARG BUILD_ARCH
ARG BUILD_DATE

View File

@@ -0,0 +1,15 @@
#!/bin/bash
echo "Starting"
if [ ! -f /data/config.json ]; then
echo "building userdir"
freqtrade create-userdir --userdir /data
echo "building initial config"
freqtrade new-config --config /data/config.json
fi
pause 36000000000
echo "Starting app"
freqtrade trade --logfile /data/logs/freqtrade.log --db-url sqlite://///data/tradesv3.sqlite --config /data/config.json --strategy SampleStrategy

View File

@@ -0,0 +1,33 @@
#!/bin/bash
if [ ! -f "/usr/bin/bashio" ]; then
echo "Bashio does not exist, executing script"
################
# Install apps #
################
apt-get clean &&
apt-get update &&
apt-get install -y \
jq \
curl &&
apt-get clean
################
# Modify image #
################
# Change data location
grep -rl "/var/www/webtrees" /etc/ | xargs sed -i 's|/var/www/webtrees|/data/webtrees|g'
###################
# Install bashio #
##################
BASHIO_VERSION=0.13.1
mkdir -p /tmp/bashio
curl -L -f -s "https://github.com/hassio-addons/bashio/archive/v${BASHIO_VERSION}.tar.gz" |
tar -xzf - --strip 1 -C /tmp/bashio
mv /tmp/bashio/lib /usr/lib/bashio
ln -s /usr/lib/bashio/bashio /usr/bin/bashio
rm -rf /tmp/bashio
echo "Bashio installed"
fi

View File

@@ -1,18 +1,5 @@
#!/usr/bin/env bashio
###########
# SCRIPTS #
###########
for SCRIPTS in "/00-banner.sh"; do
echo $SCRIPTS
chown $(id -u):$(id -g) $SCRIPTS
chmod a+x $SCRIPTS
sed -i 's|/usr/bin/with-contenv bashio|/usr/bin/env bashio|g' $SCRIPTS
/.$SCRIPTS &&
true # Prevents script crash on failure
done
####################
# GLOBAL VARIABLES #
####################
@@ -28,25 +15,25 @@ export DB_TYPE=$(bashio::config 'DB_TYPE')
bashio::config.require.ssl
if bashio::config.true 'ssl'; then
#set variables
CERTFILE=$(bashio::config 'certfile')
KEYFILE=$(bashio::config 'keyfile')
#Replace variables
sed -i "s|/certs/webtrees.crt|/ssl/$CERTFILE|g" /etc/apache2/sites-available/default-ssl.conf
sed -i "s|/certs/webtrees.key|/ssl/$KEYFILE|g" /etc/apache2/sites-available/default-ssl.conf
sed -i "s|/certs/webtrees.crt|/ssl/$CERTFILE|g" /etc/apache2/sites-available/webtrees-ssl.conf
sed -i "s|/certs/webtrees.key|/ssl/$KEYFILE|g" /etc/apache2/sites-available/webtrees-ssl.conf
#Send env variables
export HTTPS=true
export SSL=true
BASE_URL=$BASE_URL:$(bashio::addon.port 443)
export BASE_URL="${BASE_URL/http:/https:}"
#Communication
bashio::log.info "Ssl enabled. If webui don't work, disable ssl or check your certificate paths"
#set variables
CERTFILE=$(bashio::config 'certfile')
KEYFILE=$(bashio::config 'keyfile')
#Replace variables
sed -i "s|/certs/webtrees.crt|/ssl/$CERTFILE|g" /etc/apache2/sites-available/default-ssl.conf
sed -i "s|/certs/webtrees.key|/ssl/$KEYFILE|g" /etc/apache2/sites-available/default-ssl.conf
sed -i "s|/certs/webtrees.crt|/ssl/$CERTFILE|g" /etc/apache2/sites-available/webtrees-ssl.conf
sed -i "s|/certs/webtrees.key|/ssl/$KEYFILE|g" /etc/apache2/sites-available/webtrees-ssl.conf
#Send env variables
export HTTPS=true
export SSL=true
BASE_URL=$BASE_URL:$(bashio::addon.port 443)
export BASE_URL="${BASE_URL/http:/https:}"
#Communication
bashio::log.info "Ssl enabled. If webui don't work, disable ssl or check your certificate paths"
fi
##############
@@ -69,20 +56,20 @@ chown -R www-data:www-data $WEBTREES_HOME
# Make links with share
echo "... make links with data in /share"
for VOL in "data" "media" "modules_v4"; do
mkdir -p $OLD_WEBTREES_HOME/$VOL
cp -rn $OLD_WEBTREES_HOME/$VOL $WEBTREES_HOME || true
rm -r $OLD_WEBTREES_HOME/$VOL || true
ln -s $WEBTREES_HOME/$VOL $OLD_WEBTREES_HOME || true
mkdir -p $OLD_WEBTREES_HOME/$VOL
cp -rn $OLD_WEBTREES_HOME/$VOL $WEBTREES_HOME || true
rm -r $OLD_WEBTREES_HOME/$VOL || true
ln -s $WEBTREES_HOME/$VOL $OLD_WEBTREES_HOME || true
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
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
# Execute main script