Files
Nick Stokoe 7c4f1091b4 * - use "docker compose" not "docker-compose"
Latter is obsolete now
2025-05-26 13:09:19 +01:00

107 lines
1.9 KiB
Bash
Executable File

#!/bin/sh
dc_dir={{ docker_compose_base_dir }}
nextcloud_base_dir=/var/www/html
nextcloud_data_dir=/var/www/data
postgres_db_user={{ postgres_db_user }}
nextcloud_db_user={{ nextcloud_db_user }}
nextcloud_db={{ nextcloud_db }}
DOCKER_EXE() {
( cd $dc_dir; docker compose exec "$@" )
}
ON_POSTGRES() {
DOCKER_EXE -T -u postgres postgres "$@"
}
ON_POSTGRESi() {
DOCKER_EXE -u postgres postgres "$@"
}
ON_NEXTCLOUD() {
DOCKER_EXE -T -u www-data nextcloud "$@"
}
ON_NEXTCLOUDi() {
DOCKER_EXE -u www-data nextcloud "$@"
}
PSQL() {
ON_POSTGRES /usr/local/bin/psql "$@"
}
PGDUMP() {
ON_POSTGRES /usr/local/bin/pg_dump "$@"
}
PSQLi() {
ON_POSTGRESi /usr/local/bin/psql "$@"
}
PHP() {
ON_NEXTCLOUD /usr/local/bin/php "$@"
}
TEE() {
ON_NEXTCLOUD /usr/bin/tee "$1"
}
CAT() {
ON_NEXTCLOUD /bin/cat "$1"
}
DUMP() {
ON_NEXTCLOUD /bin/sh -c "for d in $*; do /usr/bin/tar -C \$d -c . ; done"
}
UNDUMP() {
ON_NEXTCLOUD /bin/sh -c "for d in $*; do /usr/bin/tar -C \$d -x ; done"
}
_gen_config() {
local config=$nextcloud_base_dir/config/config.php
script=$( cat <<EOF )
require("$config");
\$CONFIG["password"] = "password";
// FIXME more here
file_put_contents("$config.2", "<?php\\n\\\$CONFIG = ". var_export(\$CONFIG, true) .";\\n");
EOF
PHP -r "$script"
}
unpack_db() {
tar t >/dev/null && tar t >/dev/null && cat
}
# FIXME override selected config settings
restore() {
( UNDUMP $nextcloud_base_dir $nextcloud_data_dir
#FIXME [ -n "$config" ] && gen_config <<<'$config' | WRITE $nextcloud_base_dir/config/config.php
PSQL -U $postgres_db_user < $dc_dir/postgres/init.sql
cat | PSQL -U $postgres_db_user -d $nextcloud_db )
}
backup() {
( DUMP $nextcloud_base_dir $nextcloud_data_dir
PGDUMP -U $postgres_db_user $nextcloud_db )
}
prune() {
docker system prune -a --volumes
}
OCC() {
ON_NEXTCLOUD ./occ "$@"
}
NSH() {
ON_NEXTCLOUDi sh "$@"
}
set -vx
set -e
"$@"