mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-12-11 22:24:21 +01:00
87 lines
1.7 KiB
Bash
87 lines
1.7 KiB
Bash
|
#!/usr/bin/env bash
|
||
|
|
||
|
config()
|
||
|
{
|
||
|
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."
|
||
|
read -rp "Continue anyway? (Y/n) " confirm </dev/tty
|
||
|
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"
|
||
|
read -rp "Is Fab-manager installed at \"$FM_PATH\"? (y/N) " confirm </dev/tty
|
||
|
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" mikefarah/yq yq "$@"
|
||
|
}
|
||
|
|
||
|
|
||
|
docker_down()
|
||
|
{
|
||
|
docker-compose down
|
||
|
}
|
||
|
|
||
|
proceed_upgrade()
|
||
|
{
|
||
|
yq w -i docker-compose.yml services.redis.image redis:6-alpine
|
||
|
}
|
||
|
|
||
|
|
||
|
docker_up()
|
||
|
{
|
||
|
docker-compose pull redis
|
||
|
docker-compose up -d
|
||
|
}
|
||
|
|
||
|
function trap_ctrlc()
|
||
|
{
|
||
|
echo "Ctrl^C, exiting..."
|
||
|
exit 2
|
||
|
}
|
||
|
|
||
|
upgrade_redis()
|
||
|
{
|
||
|
config
|
||
|
read -rp "Continue with upgrading? (y/N) " confirm </dev/tty
|
||
|
if [[ "$confirm" = "y" ]]; then
|
||
|
trap "trap_ctrlc" 2 # SIGINT
|
||
|
docker_down
|
||
|
proceed_upgrade
|
||
|
docker_up
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
upgrade_redis "$@"
|