2 Commits

Author SHA1 Message Date
bb5b013d31 Remove docker stuff 2025-12-17 21:17:24 +09:00
a366769fb9 Add scripts for setting up and resetting the project 2025-12-17 21:17:24 +09:00
6 changed files with 150 additions and 28 deletions

View File

@@ -1,7 +0,0 @@
# this is a development container, not hardened for hosting
FROM php:7.4-cli
RUN apt-get update && \
apt-get install -y \
sqlite3 \
unzip \
git

View File

@@ -1,21 +0,0 @@
version: "3.9"
# cleanup:
# docker container prune -f && docker volume prune -f
# docker system prune -a
services:
nettside: # https://hub.docker.com/_/php
#image: php:7.4-cli
build: .
volumes:
- .:/usr/src/nettside
working_dir: /usr/src/nettside
command: ./dev.sh
environment:
- DOCKER_HOST=0.0.0.0
- DOCKER_PORT=1080
ports:
- 1080:1080
user: "${DOCKER_USER}"

36
scripts/clean.sh Executable file
View File

@@ -0,0 +1,36 @@
#!/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
)

20
scripts/reset.sh Executable file
View File

@@ -0,0 +1,20 @@
#!/usr/bin/env bash
set -euo pipefail
REQUIRED_COMMANDS=(git)
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)"
"$PROJECT_ROOT/scripts/clean.sh"
"$PROJECT_ROOT/scripts/setup.sh"

37
scripts/run.sh Executable file
View File

@@ -0,0 +1,37 @@
#!/usr/bin/env bash
set -euo pipefail
REQUIRED_COMMANDS=(
php
)
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)"
# Check for hints that our project might not be correctly set up
if [ ! -d "$PROJECT_ROOT/vendor" ] \
|| [ ! -f "$PROJECT_ROOT/config.php" ] \
|| [ ! -d "$PROJECT_ROOT/www/simplesaml" ] \
|| [ ! -d "$PROJECT_ROOT/www/galleri/bilder" ]; then
echo "It looks like the project is not correctly set up." >&2
exit 1
fi
declare -a PHP_ARGS=(
-S localhost:1080
-d error_reporting=E_ALL
-d display_errors=1
-t www/
)
(cd "$PROJECT_ROOT" && php "${PHP_ARGS[@]}")

57
scripts/setup.sh Executable file
View File

@@ -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