From 38e2cbffc91b81e714795ea2fa76a1e952901874 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Wed, 17 Dec 2025 20:48:09 +0900 Subject: [PATCH] Add scripts for setting up and resetting the project --- scripts/reset.sh | 38 ++++++++++++++++++++++++++++++++ scripts/setup.sh | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100755 scripts/reset.sh create mode 100755 scripts/setup.sh diff --git a/scripts/reset.sh b/scripts/reset.sh new file mode 100755 index 0000000..3d87f94 --- /dev/null +++ b/scripts/reset.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +set -euo pipefail + +REQUIRED_COMMANDS=(git grep) +MISSING_COMMANDS=false +for cmd in "${REQUIRED_COMMANDS[@]}"; do + if ! command -v "$cmd" &> /dev/null; then + echo "$cmd could not be found" >&2 + MISSING_COMMANDS=true + fi +done +if [ "$MISSING_COMMANDS" = true ]; then + exit 1 +fi + +declare -r GIT_TREE_IS_DIRTY="$( + if ! git diff --quiet --ignore-submodules \ + || git ls-files --others --exclude-standard | grep -q .; then + echo 1 + else + echo 0 + fi +)" + +if [ "$GIT_TREE_IS_DIRTY" == "1" ]; then + echo "Git working tree is dirty, refusing to reset" >&2 + exit 1 +fi + +declare -r PROJECT_ROOT="$(git rev-parse --show-toplevel)" + +( + cd "$PROJECT_ROOT" + git clean -fdx +) + +"$PROJECT_ROOT/scripts/setup.sh" diff --git a/scripts/setup.sh b/scripts/setup.sh new file mode 100755 index 0000000..b9755b7 --- /dev/null +++ b/scripts/setup.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash + +set -euo pipefail + +REQUIRED_COMMANDS=( + git + composer + sqlite3 + openssl + install +) +MISSING_COMMANDS=false +for cmd in "${REQUIRED_COMMANDS[@]}"; do + if ! command -v "$cmd" &> /dev/null; then + echo "$cmd could not be found" >&2 + MISSING_COMMANDS=true + fi +done +if [ "$MISSING_COMMANDS" = true ]; then + exit 1 +fi + +declare -r PROJECT_ROOT="$(git rev-parse --show-toplevel)" + +mkdir -p "$PROJECT_ROOT/www/galleri/bilder/slideshow" +test -e "$PROJECT_ROOT/pvv.sqlite" || sqlite3 "$PROJECT_ROOT/pvv.sqlite" < "$PROJECT_ROOT/dist/sql/pvv_sqlite.sql" +test -e "$PROJECT_ROOT/config.php" || cp -v "$PROJECT_ROOT/dist/config.local.php" "$PROJECT_ROOT/config.php" + +if [ ! -d "$PROJECT_ROOT/vendor" ] ; then + pushd "$PROJECT_ROOT" + composer install || exit $? + + # Set up SimpleSAMLphp identity provider (for local testing) + install -m644 dist/simplesaml-dev/authsources.php -t vendor/simplesamlphp/simplesamlphp/config/ + install -m644 dist/simplesaml-dev/config.php -t vendor/simplesamlphp/simplesamlphp/config/ + install -m644 dist/simplesaml-dev/saml20-idp-remote.php -t vendor/simplesamlphp/simplesamlphp/metadata/ + install -m644 dist/simplesaml-dev/saml20-idp-hosted.php -t vendor/simplesamlphp/simplesamlphp/metadata/ + install -m644 dist/simplesaml-dev/saml20-sp-remote.php -t vendor/simplesamlphp/simplesamlphp/metadata/ + + # See session.phpsession.savepath in config.php + mkdir -p vendor/simplesamlphp/simplesamlphp/sessions/ + + openssl req \ + -newkey rsa:4096 \ + -new \ + -x509 \ + -days 3652 \ + -nodes \ + -out vendor/simplesamlphp/simplesamlphp/cert/localhost.crt \ + -keyout vendor/simplesamlphp/simplesamlphp/cert/localhost.pem \ + -subj "/C=NO/ST=Trondheim/L=Trondheim/O=Programvareverkstedet/CN=localhost" + + cp dist/config.local.php config.php + + ln -s ../vendor/simplesamlphp/simplesamlphp/public/ www/simplesaml + popd +fi