feat: merge nc scripts into ncm.sh
Some checks failed
Some checks failed
This commit is contained in:
parent
0f239f98cd
commit
9a270e02f6
5 changed files with 35 additions and 149 deletions
|
|
@ -1,134 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
print_usage() {
|
|
||||||
echo "Usage:"
|
|
||||||
echo " $0 <up|down> <service_name|all> [-d|--daemon]"
|
|
||||||
echo " $0 sh <service_name> <subservice_name> [--shell <shell_name>]"
|
|
||||||
echo " $0 logs <service_name> [<subservice_name>] [-f|--follow]"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# Check if correct number of arguments is provided
|
|
||||||
if [ $# -lt 2 ]; then
|
|
||||||
print_usage
|
|
||||||
fi
|
|
||||||
|
|
||||||
action=$1
|
|
||||||
service=$2
|
|
||||||
daemon_flag=""
|
|
||||||
shell="sh"
|
|
||||||
follow_flag=""
|
|
||||||
|
|
||||||
case "$action" in
|
|
||||||
up|down)
|
|
||||||
if [ $# -gt 3 ]; then
|
|
||||||
print_usage
|
|
||||||
fi
|
|
||||||
if [ $# -eq 3 ]; then
|
|
||||||
if [ "$3" = "-d" ] || [ "$3" = "--daemon" ]; then
|
|
||||||
daemon_flag="-d"
|
|
||||||
else
|
|
||||||
echo "Invalid flag. Use '-d' or '--daemon' for detached mode."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
sh)
|
|
||||||
if [ $# -lt 3 ]; then
|
|
||||||
print_usage
|
|
||||||
fi
|
|
||||||
subservice=$3
|
|
||||||
shift 3
|
|
||||||
while [ $# -gt 0 ]; do
|
|
||||||
case "$1" in
|
|
||||||
--shell)
|
|
||||||
if [ -z "$2" ]; then
|
|
||||||
echo "Shell name is missing after --shell flag."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
shell="$2"
|
|
||||||
shift 2
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "Unknown option: $1"
|
|
||||||
print_usage
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
;;
|
|
||||||
logs)
|
|
||||||
subservice=""
|
|
||||||
shift 2
|
|
||||||
while [ $# -gt 0 ]; do
|
|
||||||
case "$1" in
|
|
||||||
-f|--follow)
|
|
||||||
follow_flag="--follow"
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
if [ -z "$subservice" ]; then
|
|
||||||
subservice="$1"
|
|
||||||
else
|
|
||||||
echo "Unknown option: $1"
|
|
||||||
print_usage
|
|
||||||
fi
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "Invalid action. Use 'up', 'down', 'sh', or 'logs'."
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
execute_docker_compose() {
|
|
||||||
dir=$1
|
|
||||||
cmd=$2
|
|
||||||
echo "Executing in $dir: docker compose $cmd $daemon_flag"
|
|
||||||
cd "$dir" && docker compose "$cmd" $daemon_flag
|
|
||||||
cd - > /dev/null || exit
|
|
||||||
}
|
|
||||||
|
|
||||||
execute_docker_shell() {
|
|
||||||
dir=$1
|
|
||||||
subservice=$2
|
|
||||||
echo "Executing in $dir: docker compose exec $subservice $shell"
|
|
||||||
cd "$dir" && docker compose exec "$subservice" "$shell"
|
|
||||||
cd - > /dev/null || exit
|
|
||||||
}
|
|
||||||
|
|
||||||
execute_docker_logs() {
|
|
||||||
dir=$1
|
|
||||||
subservice=$2
|
|
||||||
echo "Executing in $dir: docker compose logs $follow_flag $subservice"
|
|
||||||
cd "$dir" && docker compose logs $follow_flag "$subservice"
|
|
||||||
cd - > /dev/null || exit
|
|
||||||
}
|
|
||||||
|
|
||||||
if [ "$action" = "sh" ]; then
|
|
||||||
if [ ! -d "$service" ]; then
|
|
||||||
echo "Service directory '$service' not found."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
execute_docker_shell "$service" "$subservice"
|
|
||||||
elif [ "$action" = "logs" ]; then
|
|
||||||
if [ ! -d "$service" ]; then
|
|
||||||
echo "Service directory '$service' not found."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
execute_docker_logs "$service" "$subservice"
|
|
||||||
elif [ "$service" = "all" ]; then
|
|
||||||
for dir in */; do
|
|
||||||
if [ -f "${dir}docker-compose.yml" ] || [ -f "${dir}docker-compose.yaml" ]; then
|
|
||||||
execute_docker_compose "$dir" "$action"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
else
|
|
||||||
if [ ! -d "$service" ]; then
|
|
||||||
echo "Service directory '$service' not found."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
execute_docker_compose "$service" "$action"
|
|
||||||
fi
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
#!/usr/bin/env sh
|
|
||||||
|
|
||||||
script_dir=$(dirname "$(readlink -f "$0")")
|
|
||||||
cd "$script_dir/../docker/nextcloud" || exit 1
|
|
||||||
docker compose exec nextcloud sudo -u www-data php occ db:add-missing-indices
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
#!/usr/bin/env sh
|
|
||||||
|
|
||||||
script_dir=$(dirname "$(readlink -f "$0")")
|
|
||||||
cd "$script_dir/../docker/nextcloud" || exit 1
|
|
||||||
docker compose exec nextcloud sudo -u www-data php occ maintenance:update:htaccess
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
#!/usr/bin/env sh
|
|
||||||
|
|
||||||
script_dir=$(dirname "$(readlink -f "$0")")
|
|
||||||
cd "$script_dir/../docker/nextcloud" || exit 1
|
|
||||||
docker compose exec nextcloud sudo -u www-data php occ upgrade
|
|
||||||
35
scripts/ncm.sh
Executable file
35
scripts/ncm.sh
Executable file
|
|
@ -0,0 +1,35 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
||||||
|
|
||||||
|
cd "$SCRIPT_DIR/../docker/nextcloud" || exit
|
||||||
|
|
||||||
|
docker_exec() {
|
||||||
|
docker compose exec nextcloud "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
occ_exec() {
|
||||||
|
docker_exec sudo -E -u www-data php occ "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
upgrade)
|
||||||
|
occ_exec upgrade
|
||||||
|
;;
|
||||||
|
htaccess)
|
||||||
|
occ_exec maintenance:update:htaccess
|
||||||
|
;;
|
||||||
|
indices)
|
||||||
|
occ_exec db:add-missing-indices
|
||||||
|
;;
|
||||||
|
occ)
|
||||||
|
occ_exec "$@"
|
||||||
|
;;
|
||||||
|
exec)
|
||||||
|
docker_exec "$@"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Usage: $0 {upgrade|htaccess|indices|occ <custom occ command>|exec <custom command>}"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
Loading…
Add table
Add a link
Reference in a new issue