entrypoint.postgres.sh 1.3 KB

12345678910111213141516171819202122232425262728293031
  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. su postgres -c 'psql invidious kemal < config/sql/playlists.sql'
  22. su postgres -c 'psql invidious kemal < config/sql/playlist_videos.sql'
  23. touch /var/lib/postgresql/data/setupFinished
  24. echo "### invidious database setup finished"
  25. exit
  26. fi
  27. echo "running postgres /usr/local/bin/docker-entrypoint.sh $CMD"
  28. exec /usr/local/bin/docker-entrypoint.sh $CMD