1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-12 23:09:03 +01:00
fab-manager/scripts/redis-upgrade.sh

113 lines
2.3 KiB
Bash
Raw Normal View History

2020-06-09 16:23:07 +02:00
#!/usr/bin/env bash
2020-07-01 10:52:43 +02:00
parseparams()
{
while getopts "hy" opt; do
case "${opt}" in
y)
Y=true
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
}
2020-06-09 16:23:07 +02:00
config()
{
2020-07-01 10:52:43 +02:00
YES_ALL=${Y:-false}
2020-06-09 16:23:07 +02:00
if [ "$(whoami)" = "root" ]
then
echo "It is not recommended to run this script as root. As a normal user, elevation will be prompted if needed."
2020-07-01 10:52:43 +02:00
[[ "$YES_ALL" = "true" ]] && confirm="y" || read -rp "Continue anyway? (Y/n) " confirm </dev/tty
2020-06-09 16:23:07 +02:00
if [[ "$confirm" = "n" ]]; then exit 1; fi
else
if ! groups | grep docker; then
echo "Please add your current user to the docker group."
echo "You can run the following as root: \"usermod -aG docker $(whoami)\", then logout and login again"
echo "current user is not allowed to use docker, exiting..."
exit 1
fi
fi
FM_PATH=$(pwd)
TYPE="NOT-FOUND"
2020-07-01 10:52:43 +02:00
[[ "$YES_ALL" = "true" ]] && confirm="y" || read -rp "Is Fab-manager installed at \"$FM_PATH\"? (y/N) " confirm </dev/tty
2020-06-09 16:23:07 +02:00
if [ "$confirm" = "y" ]; then
test_docker_compose
if [[ "$TYPE" = "NOT-FOUND" ]]
then
echo "Redis was not found on the current system, exiting..."
exit 2
fi
else
echo "Please run this script from the Fab-manager's installation folder"
exit 1
fi
}
test_docker_compose()
{
if [[ -f "$FM_PATH/docker-compose.yml" ]]
then
docker-compose ps | grep redis
if [[ $? = 0 ]]
then
TYPE="DOCKER-COMPOSE"
fi
fi
}
yq() {
docker run --rm -i -v "${FM_PATH}:/workdir" --user "$UID" mikefarah/yq:4 "$@"
2020-06-09 16:23:07 +02:00
}
docker_down()
{
docker-compose down
}
proceed_upgrade()
{
2021-03-01 11:34:02 +01:00
yq -i eval '.services.redis.image = "redis:6-alpine"' docker-compose.yml
2020-06-09 16:23:07 +02:00
}
docker_up()
{
docker-compose pull redis
docker-compose up -d
}
2020-07-01 10:52:43 +02:00
usage()
{
printf "Usage: %s [OPTIONS]
Options:
-h Print this message and quit
-y Answer yes to all questions\n" "$(basename "$0")" 1>&2
exit 1
}
2020-06-09 16:23:07 +02:00
function trap_ctrlc()
{
echo "Ctrl^C, exiting..."
exit 2
}
upgrade_redis()
{
2020-07-01 10:52:43 +02:00
parseparams "$@"
2020-06-09 16:23:07 +02:00
config
2020-07-01 10:52:43 +02:00
[[ "$YES_ALL" = "true" ]] && confirm="y" || read -rp "Continue with upgrading? (y/N) " confirm </dev/tty
2020-06-09 16:23:07 +02:00
if [[ "$confirm" = "y" ]]; then
trap "trap_ctrlc" 2 # SIGINT
docker_down
proceed_upgrade
docker_up
fi
}
upgrade_redis "$@"