Skip to content

Commit

Permalink
Merge pull request #13 from linuxserver/db
Browse files Browse the repository at this point in the history
fix db settings, make sure index.html is recreated
  • Loading branch information
Roxedus authored Mar 1, 2021
2 parents fe1df05 + ccccc42 commit 57f0af4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,13 @@ services:
- PGID=1000
- TZ=Europe/London
- PASSWORD=PASSWORD
- CUSTOM_RESULTS=true #optional
- CUSTOM_RESULTS=false #optional
- DB_TYPE=sqlite #optional
- DB_NAME=DB_NAME #optional
- DB_HOSTNAME=DB_HOSTNAME #optional
- DB_USERNAME=DB_USERNAME #optional
- DB_PASSWORD=DB_PASSWORD #optional
- DB_PORT=DB_PORT #optional
volumes:
- /path/to/appdata/config:/config
ports:
Expand All @@ -100,12 +101,13 @@ docker run -d \
-e PGID=1000 \
-e TZ=Europe/London \
-e PASSWORD=PASSWORD \
-e CUSTOM_RESULTS=true `#optional` \
-e CUSTOM_RESULTS=false `#optional` \
-e DB_TYPE=sqlite `#optional` \
-e DB_NAME=DB_NAME `#optional` \
-e DB_HOSTNAME=DB_HOSTNAME `#optional` \
-e DB_USERNAME=DB_USERNAME `#optional` \
-e DB_PASSWORD=DB_PASSWORD `#optional` \
-e DB_PORT=DB_PORT `#optional` \
-p 80:80 \
-v /path/to/appdata/config:/config \
--restart unless-stopped \
Expand All @@ -124,12 +126,13 @@ Container images are configured using parameters passed at runtime (such as thos
| `-e PGID=1000` | for GroupID - see below for explanation |
| `-e TZ=Europe/London` | Specify a timezone to use EG Europe/London |
| `-e PASSWORD=PASSWORD` | Set the password for the results database. |
| `-e CUSTOM_RESULTS=true` | (optional) enables custom results page in `/config/www/results/index.php`. |
| `-e CUSTOM_RESULTS=false` | (optional) set to `true` to enable custom results page in `/config/www/results/index.php`. |
| `-e DB_TYPE=sqlite` | Defaults to `sqlite`, can also be set to `mysql` or `postgresql`. |
| `-e DB_NAME=DB_NAME` | Database name. Required for mysql and pgsql. |
| `-e DB_HOSTNAME=DB_HOSTNAME` | Database address. Required for mysql and pgsql. |
| `-e DB_USERNAME=DB_USERNAME` | Database username. Required for mysql and pgsql. |
| `-e DB_PASSWORD=DB_PASSWORD` | Database password. Required for mysql and pgsql. |
| `-e DB_PORT=DB_PORT` | Database port. Required for mysql. |
| `-v /config` | Contains all relevant configuration files. |

## Environment variables from files (Docker secrets)
Expand Down Expand Up @@ -248,6 +251,7 @@ Once registered you can define the dockerfile to use with `-f Dockerfile.aarch64

## Versions

* **01.03.21:** - Fix up database settings. Make sure `index.html` is recreated.
* **28.02.21:** - Added php7-ctype.
* **23.01.21:** - Rebasing to alpine 3.13.
* **01.06.20:** - Rebasing to alpine 3.12.
Expand Down
4 changes: 3 additions & 1 deletion readme-vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ param_env_vars:
# optional container parameters
opt_param_usage_include_env: true
opt_param_env_vars:
- { env_var: "CUSTOM_RESULTS", env_value: "true", desc: "(optional) enables custom results page in `/config/www/results/index.php`."}
- { env_var: "CUSTOM_RESULTS", env_value: "false", desc: "(optional) set to `true` to enable custom results page in `/config/www/results/index.php`."}
- { env_var: "DB_TYPE", env_value: "sqlite", desc: "Defaults to `sqlite`, can also be set to `mysql` or `postgresql`."}
- { env_var: "DB_NAME", env_value: "DB_NAME", desc: "Database name. Required for mysql and pgsql."}
- { env_var: "DB_HOSTNAME", env_value: "DB_HOSTNAME", desc: "Database address. Required for mysql and pgsql."}
- { env_var: "DB_USERNAME", env_value: "DB_USERNAME", desc: "Database username. Required for mysql and pgsql."}
- { env_var: "DB_PASSWORD", env_value: "DB_PASSWORD", desc: "Database password. Required for mysql and pgsql."}
- { env_var: "DB_PORT", env_value: "DB_PORT", desc: "Database port. Required for mysql."}

optional_block_1: false
optional_block_1_items: ""
Expand All @@ -62,6 +63,7 @@ app_setup_block: |
# changelog
changelogs:
- { date: "01.03.21:", desc: "Fix up database settings. Make sure `index.html` is recreated." }
- { date: "28.02.21:", desc: "Added php7-ctype." }
- { date: "23.01.21:", desc: "Rebasing to alpine 3.13." }
- { date: "01.06.20:", desc: "Rebasing to alpine 3.12." }
Expand Down
31 changes: 17 additions & 14 deletions root/etc/cont-init.d/50-config
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ mkdir -p \
# create symlink to index.html
[[ ! -L /usr/share/webapps/librespeed/index.html ]] && \
ln -s /config/www/index.html /usr/share/webapps/librespeed/index.html
[[ ! -f /config/www/index.html ]] && \
cp /defaults/index.html /config/www/index.html

# update templates
cp /usr/share/webapps/librespeed/example*.html /config/www/
Expand All @@ -19,7 +21,7 @@ cp /usr/share/webapps/librespeed/example*.html /config/www/
cp /config/www/speedtest_worker.js /usr/share/webapps/librespeed/speedtest_worker.js

# enables custom results page
if "$CUSTOM_RESULTS"; then
if [ "$CUSTOM_RESULTS" == "true" ]; then
echo "custom results"
[[ ! -e "/config/www/results/index.php" ]] && \
mkdir -p /config/www/results/ && \
Expand All @@ -29,28 +31,29 @@ fi

# configure app settings
sed -i "\
s|\$Sqlite_db_file = \"../../speedtest_telemetry.sql\";|\$Sqlite_db_file = \"/config/speedtest_telemetry.sql\";|g; \
s|\$enable_id_obfuscation=false;|\$enable_id_obfuscation=true;|g;
s|\$stats_password=\"PASSWORD\";|\$stats_password=\"${PASSWORD}\";|g" \
s|\$Sqlite_db_file.*|\$Sqlite_db_file = \'/config/speedtest_telemetry.sql\';|g; \
s|\$enable_id_obfuscation.*|\$enable_id_obfuscation = true;|g;
s|\$stats_password.*|\$stats_password = \'${PASSWORD}\';|g" \
/usr/share/webapps/librespeed/results/telemetry_settings.php
if [ "$DB_TYPE" = "postgresql" ]; then
sed -i "\
s|\$db_type=\"mysql\";|\$db_type=\"${DB_TYPE}\";|g \
s|\$PostgreSql_username=\"USERNAME\";|\$PostgreSql_username=\"${DB_USERNAME}\";|g; \
s|\$PostgreSql_password=\"PASSWORD\";|\$PostgreSql_password=\"${DB_PASSWORD}\";|g; \
s|\$PostgreSql_hostname=\"DB_HOSTNAME\";|\$PostgreSql_hostname=\"${DB_HOSTNAME}\";|g; \
s|\$PostgreSql_databasename=\"DB_NAME\";|\$PostgreSql_databasename=\"${DB_NAME}\";|g" \
s|\$db_type.*|\$db_type = \'${DB_TYPE}\';|g; \
s|\$PostgreSql_username.*|\$PostgreSql_username = \'${DB_USERNAME}\';|g; \
s|\$PostgreSql_password.*|\$PostgreSql_password = \'${DB_PASSWORD}\';|g; \
s|\$PostgreSql_hostname.*|\$PostgreSql_hostname = \'${DB_HOSTNAME}\';|g; \
s|\$PostgreSql_databasename.*|\$PostgreSql_databasename = \'${DB_NAME}\';|g" \
/usr/share/webapps/librespeed/results/telemetry_settings.php
elif [ "$DB_TYPE" = "mysql" ]; then
sed -i "\
s|\$MySql_username=\"USERNAME\";|\$MySql_username=\"${DB_USERNAME}\";|g; \
s|\$MySql_password=\"PASSWORD\";|\$MySql_password=\"${DB_PASSWORD}\";|g; \
s|\$MySql_hostname=\"DB_HOSTNAME\";|\$MySql_hostname=\"${DB_HOSTNAME}\";|g; \
s|\$MySql_databasename=\"DB_NAME\";|\$MySql_databasename=\"${DB_NAME}\";|g" \
s|\$MySql_username.*|\$MySql_username = \'${DB_USERNAME}\';|g; \
s|\$MySql_password.*|\$MySql_password = \'${DB_PASSWORD}\';|g; \
s|\$MySql_hostname.*|\$MySql_hostname = \'${DB_HOSTNAME}\';|g; \
s|\$MySql_databasename.*|\$MySql_databasename = \'${DB_NAME}\';|g; \
s|\$MySql_port.*|\$MySql_port = \'${DB_PORT:-3306}\';|g" \
/usr/share/webapps/librespeed/results/telemetry_settings.php
else
sed -i \
"s|\$db_type=\"mysql\";|\$db_type=\"sqlite\";|g" \
"s|\$db_type.*|\$db_type = \'sqlite\';|g" \
/usr/share/webapps/librespeed/results/telemetry_settings.php
fi

Expand Down

0 comments on commit 57f0af4

Please sign in to comment.