entrypoint.postgres.sh 1.2 KB

1234567891011121314151617181920212223242526272829
  1. #!/usr/bin/env bash
  2. CMD="$@"
  3. if [ ! -f /var/lib/postgresql/data/setupFinished ]; then
  4. echo "### first run - setting up invidious database"
  5. /usr/local/bin/docker-entrypoint.sh postgres &
  6. sleep 10
  7. until runuser -l postgres -c 'pg_isready' 2>/dev/null; do
  8. >&2 echo "### Postgres is unavailable - waiting"
  9. sleep 5
  10. done
  11. >&2 echo "### importing table schemas"
  12. su postgres -c 'createdb invidious'
  13. su postgres -c 'psql -c "CREATE USER kemal WITH PASSWORD '"'kemal'"'"'
  14. su postgres -c 'psql invidious kemal < config/sql/channels.sql'
  15. su postgres -c 'psql invidious kemal < config/sql/videos.sql'
  16. su postgres -c 'psql invidious kemal < config/sql/channel_videos.sql'
  17. su postgres -c 'psql invidious kemal < config/sql/users.sql'
  18. su postgres -c 'psql invidious kemal < config/sql/session_ids.sql'
  19. su postgres -c 'psql invidious kemal < config/sql/nonces.sql'
  20. su postgres -c 'psql invidious kemal < config/sql/annotations.sql'
  21. touch /var/lib/postgresql/data/setupFinished
  22. echo "### invidious database setup finished"
  23. exit
  24. fi
  25. echo "running postgres /usr/local/bin/docker-entrypoint.sh $CMD"
  26. exec /usr/local/bin/docker-entrypoint.sh $CMD