mirror of
https://github.com/henrywhitaker3/Speedtest-Tracker.git
synced 2025-12-24 22:39:26 +01:00
138 lines
4.7 KiB
Plaintext
138 lines
4.7 KiB
Plaintext
#!/usr/bin/with-contenv bash
|
|
# # This script sets up the speedtest app
|
|
|
|
function eulaError()
|
|
{
|
|
echo "##################################################################################################################################"
|
|
echo "##################################################################################################################################"
|
|
echo "You haven't accepted the Ookla EULA. Please re-create the container with the environment variable 'OOKLA_EULA_GDPR' set to 'true'."
|
|
echo "##################################################################################################################################"
|
|
echo "##################################################################################################################################"
|
|
exit 1
|
|
}
|
|
|
|
# Do Ookla stuff
|
|
if [ -z ${OOKLA_EULA_GDPR+x} ]; then
|
|
eulaError
|
|
else
|
|
if [ $OOKLA_EULA_GDPR != "true" ]; then
|
|
eulaError
|
|
fi
|
|
|
|
if [ ! -f /config/www/app/Bin/speedtest ]; then
|
|
echo "Ookla GDPR and EULA accepted. Downloading Speedtest CLI."
|
|
cd /tmp
|
|
wget https://install.speedtest.net/app/cli/ookla-speedtest-1.0.0-$arch-linux.tgz -O speedtest.tgz > /dev/null
|
|
tar zxvf speedtest.tgz > /dev/null
|
|
cp speedtest /site/app/Bin/
|
|
|
|
HOME=/config && timeout 5s s6-setuidgid abc /site/app/Bin/speedtest --accept-license --accept-gdpr > /dev/null
|
|
HOME=/root
|
|
else
|
|
HOME=/config && timeout 5s s6-setuidgid abc /config/www/app/Bin/speedtest --accept-license --accept-gdpr > /dev/null
|
|
HOME=/root
|
|
fi
|
|
fi
|
|
|
|
# Copy site files to /config
|
|
echo "Copying latest site files to config"
|
|
cp -rfT /site/ /config/www/
|
|
|
|
# Check for DB
|
|
if [ ! -f /config/speed.db ]; then
|
|
echo "Database file not found! Creating empty database"
|
|
touch /config/speed.db
|
|
else
|
|
echo "Database file exists"
|
|
chown abc:abc /config/speed.db
|
|
fi
|
|
|
|
# Check for .env
|
|
if [ ! -f /config/www/.env ]; then
|
|
echo "Env file not found! Creating .env file"
|
|
cp /site/.env.example /config/www/.env
|
|
else
|
|
echo "Env file exists"
|
|
fi
|
|
|
|
if [ ! -f /config/www/.composer-time ]; then
|
|
echo 'Removing old packages'
|
|
rm -rf /config/www/vendor/
|
|
fi
|
|
|
|
echo 'Updating packages'
|
|
apk add composer
|
|
cd /config/www && composer install && echo date > /config/www/.composer-time
|
|
|
|
sed "s,DB_DATABASE=.*,DB_DATABASE=/config/speed.db," -i.bak /config/www/.env
|
|
|
|
echo "Running database migrations"
|
|
php /config/www/artisan migrate
|
|
|
|
# Check app key exists
|
|
if grep -E "APP_KEY=[0-9A-Za-z:+\/=]{1,}" /config/www/.env > /dev/null; then
|
|
echo "App key exists"
|
|
else
|
|
echo "Generating app key"
|
|
php /config/www/artisan key:generate
|
|
fi
|
|
|
|
# Check JWT secret exists
|
|
if grep -E "JWT_SECRET=[0-9A-Za-z:+\/=]{1,}" /config/www/.env > /dev/null ; then
|
|
echo "JWT secret exists"
|
|
else
|
|
echo "Generating JWT secret"
|
|
php /config/www/artisan jwt:secret
|
|
fi
|
|
|
|
if [ -z ${SLACK_WEBHOOK+x} ]; then
|
|
echo "Slack webhook is unset"
|
|
sed "s,SLACK_WEBHOOK=.*,SLACK_WEBHOOK=," -i.bak /config/www/.env
|
|
else
|
|
echo "Slack webhook set, updating db"
|
|
sed "s,SLACK_WEBHOOK=.*,SLACK_WEBHOOK=$SLACK_WEBHOOK," -i.bak /config/www/.env
|
|
php /config/www/artisan speedtest:slack $SLACK_WEBHOOK
|
|
fi
|
|
|
|
if [ -z ${TELEGRAM_BOT_TOKEN+x} ] && [ -z ${TELEGRAM_CHAT_ID+x} ]; then
|
|
echo "Telegram chat id and bot token unset"
|
|
sed "s,TELEGRAM_BOT_TOKEN=.*,TELEGRAM_BOT_TOKEN=," -i.bak /config/www/.env
|
|
sed "s,TELEGRAM_CHAT_ID=.*,TELEGRAM_CHAT_ID=," -i.bak /config/www/.env
|
|
else
|
|
echo "Telegram chat id and bot token set, updating .env"
|
|
sed "s,TELEGRAM_BOT_TOKEN=.*,TELEGRAM_BOT_TOKEN=$TELEGRAM_BOT_TOKEN," -i.bak /config/www/.env
|
|
sed "s,TELEGRAM_CHAT_ID=.*,TELEGRAM_CHAT_ID=$TELEGRAM_CHAT_ID," -i.bak /config/www/.env
|
|
php /config/www/artisan speedtest:telegram --chat=$TELEGRAM_CHAT_ID --bot=$TELEGRAM_BOT_TOKEN
|
|
fi
|
|
|
|
if [ -z ${BASE_PATH+x} ]; then
|
|
echo "Base path is unset"
|
|
sed "s,BASE_PATH=.*,BASE_PATH=," -i.bak /config/www/.env
|
|
else
|
|
echo "Base path set, updating .env"
|
|
sed "s,BASE_PATH=.*,BASE_PATH=$BASE_PATH," -i.bak /config/www/.env
|
|
fi
|
|
|
|
if [ -z ${AUTH+x} ]; then
|
|
echo "AUTH variable not set. Disabling authentication"
|
|
php /config/www/artisan speedtest:auth --disable
|
|
else
|
|
if [ $AUTH == 'true' ]; then
|
|
echo "AUTH variable set. Enabling authentication"
|
|
php /config/www/artisan speedtest:auth --enable
|
|
else
|
|
echo "AUTH variable set, but not to 'true'. Disabling authentication"
|
|
php /config/www/artisan speedtest:auth --disable
|
|
fi
|
|
fi
|
|
|
|
echo "Clearing old jobs from queue"
|
|
php /config/www/artisan queue:clear
|
|
|
|
mkdir -p /config/log/speedtest
|
|
|
|
cp /defaults/crontab /etc/crontabs/root
|
|
|
|
chown -R abc:abc /config
|
|
chmod +x /config/www/app/Bin/speedtest
|
|
chmod -R 777 /config/www/storage/clockwork |