entrypoint.sh 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #!/bin/bash
  2. set -e
  3. set -x
  4. is_alpine() {
  5. [ -f /etc/alpine-release ]
  6. }
  7. # Cleanup
  8. rm -rf /var/www/html/*
  9. # Copy frontend files
  10. cp /speedtest/*.js /var/www/html/
  11. # Copy favicon
  12. cp /speedtest/favicon.ico /var/www/html/
  13. # Set custom webroot on alpine
  14. if is_alpine; then
  15. echo "ALPINE IMAGE"
  16. sed -i "s#\"/var/www/localhost/htdocs\"#\"/var/www/html\"#g" /etc/apache2/httpd.conf
  17. else
  18. echo "DEBIAN IMAGE"
  19. fi
  20. # Set up backend side for standlone modes
  21. if [[ "$MODE" == "standalone" || "$MODE" == "dual" ]]; then
  22. cp -r /speedtest/backend/ /var/www/html/backend
  23. if [ ! -z "$IPINFO_APIKEY" ]; then
  24. sed -i s/\$IPINFO_APIKEY\ =\ \'\'/\$IPINFO_APIKEY\ =\ \'$IPINFO_APIKEY\'/g /var/www/html/backend/getIP_ipInfo_apikey.php
  25. fi
  26. fi
  27. if [ "$MODE" == "backend" ]; then
  28. cp -r /speedtest/backend/* /var/www/html
  29. if [ ! -z "$IPINFO_APIKEY" ]; then
  30. sed -i s/\$IPINFO_APIKEY\ =\ \'\'/\$IPINFO_APIKEY\ =\ \'$IPINFO_APIKEY\'/g /var/www/html/getIP_ipInfo_apikey.php
  31. fi
  32. fi
  33. # Set up unified index.php
  34. if [ "$MODE" != "backend" ]; then
  35. cp /speedtest/ui.php /var/www/html/index.php
  36. fi
  37. # Apply Telemetry settings when running in standalone or frontend mode and telemetry is enabled
  38. if [[ "$TELEMETRY" == "true" && ("$MODE" == "frontend" || "$MODE" == "standalone" || "$MODE" == "dual") ]]; then
  39. cp -r /speedtest/results /var/www/html/results
  40. if [ "$MODE" == "frontend" ]; then
  41. mkdir /var/www/html/backend
  42. cp /speedtest/backend/getIP_util.php /var/www/html/backend
  43. fi
  44. if [ "$DB_TYPE" == "mysql" ]; then
  45. sed -i 's/$db_type = '\''.*'\''/$db_type = '\'$DB_TYPE\''/g' /var/www/html/results/telemetry_settings.php
  46. sed -i 's/$MySql_username = '\''.*'\''/$MySql_username = '\'$DB_USERNAME\''/g' /var/www/html/results/telemetry_settings.php
  47. sed -i 's/$MySql_password = '\''.*'\''/$MySql_password = '\'$DB_PASSWORD\''/g' /var/www/html/results/telemetry_settings.php
  48. sed -i 's/$MySql_hostname = '\''.*'\''/$MySql_hostname = '\'$DB_HOSTNAME\''/g' /var/www/html/results/telemetry_settings.php
  49. sed -i 's/$MySql_databasename = '\''.*'\''/$MySql_databasename = '\'$DB_NAME\''/g' /var/www/html/results/telemetry_settings.php
  50. if [ "$DB_PORT" != "" ]; then
  51. sed -i 's/$MySql_port = '\''.*'\''/$MySql_port = '\'$DB_PORT\''/g' /var/www/html/results/telemetry_settings.php
  52. fi
  53. elif [ "$DB_TYPE" == "postgresql" ]; then
  54. sed -i 's/$db_type = '\''.*'\''/$db_type = '\'$DB_TYPE\''/g' /var/www/html/results/telemetry_settings.php
  55. sed -i 's/$PostgreSql_username = '\''.*'\''/$PostgreSql_username = '\'$DB_USERNAME\''/g' /var/www/html/results/telemetry_settings.php
  56. sed -i 's/$PostgreSql_password = '\''.*'\''/$PostgreSql_password = '\'$DB_PASSWORD\''/g' /var/www/html/results/telemetry_settings.php
  57. sed -i 's/$PostgreSql_hostname = '\''.*'\''/$PostgreSql_hostname = '\'$DB_HOSTNAME\''/g' /var/www/html/results/telemetry_settings.php
  58. sed -i 's/$PostgreSql_databasename = '\''.*'\''/$PostgreSql_databasename = '\'$DB_NAME\''/g' /var/www/html/results/telemetry_settings.php
  59. else
  60. sed -i s/\$db_type\ =\ \'.*\'/\$db_type\ =\ \'sqlite\'\/g /var/www/html/results/telemetry_settings.php
  61. fi
  62. sed -i s/\$Sqlite_db_file\ =\ \'.*\'/\$Sqlite_db_file=\'\\\/database\\\/db.sql\'/g /var/www/html/results/telemetry_settings.php
  63. sed -i s/\$stats_password\ =\ \'.*\'/\$stats_password\ =\ \'$PASSWORD\'/g /var/www/html/results/telemetry_settings.php
  64. if [ "$ENABLE_ID_OBFUSCATION" == "true" ]; then
  65. sed -i s/\$enable_id_obfuscation\ =\ .*\;/\$enable_id_obfuscation\ =\ true\;/g /var/www/html/results/telemetry_settings.php
  66. if [ ! -z "$OBFUSCATION_SALT" ]; then
  67. if [[ "$OBFUSCATION_SALT" =~ ^0x[0-9a-fA-F]+$ ]]; then
  68. echo "<?php" > /var/www/html/results/idObfuscation_salt.php
  69. echo "\$OBFUSCATION_SALT = $OBFUSCATION_SALT;" >> /var/www/html/results/idObfuscation_salt.php
  70. else
  71. echo "WARNING: Invalid OBFUSCATION_SALT format. It must be a hex string (e.g., 0x1234abcd). Using random salt." >&2
  72. fi
  73. fi
  74. fi
  75. if [ "$REDACT_IP_ADDRESSES" == "true" ]; then
  76. sed -i s/\$redact_ip_addresses\ =\ .*\;/\$redact_ip_addresses\ =\ true\;/g /var/www/html/results/telemetry_settings.php
  77. fi
  78. mkdir -p /database/
  79. if is_alpine; then
  80. chown -R apache /database/
  81. else
  82. chown -R www-data /database/
  83. fi
  84. fi
  85. if is_alpine; then
  86. chown -R apache /var/www/html/*
  87. else
  88. chown -R www-data /var/www/html/*
  89. fi
  90. # Allow selection of Apache port for network_mode: host
  91. if [ "$WEBPORT" != "80" ]; then
  92. if is_alpine; then
  93. sed -i "s/^Listen 80\$/Listen $WEBPORT/g" /etc/apache2/httpd.conf
  94. else
  95. sed -i "s/^Listen 80\$/Listen $WEBPORT/g" /etc/apache2/ports.conf
  96. sed -i "s/*:80>/*:$WEBPORT>/g" /etc/apache2/sites-available/000-default.conf
  97. fi
  98. fi
  99. echo "Done, Starting APACHE"
  100. # This runs apache
  101. if is_alpine; then
  102. exec httpd -DFOREGROUND
  103. else
  104. exec apache2-foreground
  105. fi