2023-12-09 10:28:33 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
2024-02-12 11:39:14 +01:00
|
|
|
services=(coturn element etebase nginx-www searxng send synapse syncthing vw)
|
2023-12-22 10:58:26 +01:00
|
|
|
needs_backup=(etebase synapse vw)
|
2023-12-09 10:28:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
rel_path="$(dirname "$0")"
|
|
|
|
|
|
|
|
|
2023-12-22 10:58:26 +01:00
|
|
|
function pull {
|
|
|
|
[[ "$1" == "coturn" ]] && local sudo="sudo"
|
|
|
|
$sudo docker-compose -f "$rel_path/$1/docker-compose.yaml" pull
|
2023-12-09 10:28:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-22 10:58:26 +01:00
|
|
|
# Runs compose up & eventually make a backup before
|
|
|
|
# $1 = project name
|
|
|
|
function up {
|
|
|
|
if echo "${needs_backup[*]}" | grep -qP "\b$1\b" && has_update "$1"; then
|
|
|
|
sudo "$rel_path/backup.sh" "$1" --norestart
|
2023-12-09 10:28:33 +01:00
|
|
|
fi
|
|
|
|
|
2023-12-22 10:58:26 +01:00
|
|
|
[[ "$1" == "coturn" ]] && local sudo="sudo"
|
|
|
|
$sudo docker-compose -f "$rel_path/$1/docker-compose.yaml" up -d
|
2023-12-09 10:28:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-22 10:58:26 +01:00
|
|
|
# To use after pulling latest images of project
|
|
|
|
# Checks if at least one container can be updated
|
|
|
|
# $1 = project name
|
|
|
|
function has_update {
|
2024-01-09 08:36:48 +01:00
|
|
|
readarray -t cont_list < <(docker-compose -f "$rel_path/$1/docker-compose.yaml" ps -a | tail -n+3 | cut -d ' ' -f 1)
|
2023-12-22 10:58:26 +01:00
|
|
|
for cont in "${cont_list[@]}"; do
|
|
|
|
# Return true if container doesn't exist
|
|
|
|
if ! docker ps -a --format='{{.Names}}' | grep -q "$cont"; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
cont_image_id="$(docker inspect "$cont" --format='{{.Image}}')"
|
|
|
|
repo_url="$(docker inspect "$cont" --format='{{.Config.Image}}')"
|
|
|
|
repo_image_id="$(docker image inspect "$repo_url" --format='{{.Id}}')"
|
|
|
|
if [[ "$cont_image_id" != "$repo_image_id" ]]; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
return 1
|
2023-12-09 10:28:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-22 10:58:26 +01:00
|
|
|
service="$(echo "$2" | sed -E 's/[/ ]//g')"
|
|
|
|
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
pull)
|
|
|
|
if [[ -z "$service" ]]; then
|
|
|
|
for serv in "${services[@]}"; do
|
|
|
|
pull "$serv"
|
|
|
|
done
|
|
|
|
elif echo "${services[*]}" | grep -qP "\b$service\b"; then
|
|
|
|
pull "$service"
|
|
|
|
else
|
|
|
|
echo "invalid project name. it should be one of: ${services[*]}."
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
|
|
|
|
up)
|
|
|
|
if [[ -z "$service" ]]; then
|
|
|
|
for serv in "${services[@]}"; do
|
|
|
|
pull "$serv"
|
|
|
|
up "$serv"
|
|
|
|
done
|
|
|
|
elif echo "${services[*]}" | grep -qP "\b$service\b"; then
|
|
|
|
pull "$service"
|
|
|
|
up "$service"
|
|
|
|
else
|
|
|
|
echo "Invalid project name. It should be one of: ${services[*]}."
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
echo "Invalid action. It should be one of: pull, up."
|
|
|
|
;;
|
|
|
|
esac
|