This repository has been archived by the owner on Oct 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
update-env.sh
executable file
·72 lines (62 loc) · 2.09 KB
/
update-env.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
set -e # Stop on error
CWD=`pwd`
BASEDIR=`dirname $0`
function error_exit {
echo "${1}"
cd ${CWD}
exit 1
}
function realpath {
if [ ! -d ${1} ]; then
return 1
fi
current_dir=`pwd`
cd ${1}
res=$?
if [ $? -eq "0" ]; then
path=`pwd`
cd $current_dir
echo $path
fi
return $res
}
BASEDIR=`realpath ${BASEDIR}`
ENVIRONMENT_DIR="${BASEDIR}/environment"
# Ask to continue
echo "This script is used only for development, so be careful when using this file. Old configuration files will be"
echo "removed, so make sure you have a backup of the ${ENVIRONMENT_DIR} in case you want to revert the changes."
echo "Are you sure you want to continue?"
read -p "Do you want to (E)xit (recommended) or (C)ontinue? " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Cc]$ ]]; then
exit 0
fi
# Remove old environment.conf so it could be replaced
ENVIRONMENT_CONF="${ENVIRONMENT_DIR}/environment.conf"
if [ -f "${ENVIRONMENT_CONF}" ]; then
rm -r "${ENVIRONMENT_CONF}"
else
echo "Skipping removal of ${ENVIRONMENT_CONF} config file because it does not exist"
fi
# Remove old directories from the template to initialize a new environment
directories=("group_vars" "handlers" "tasks" "templates" "files")
for directory in "${directories[@]}"; do
if [ -e "${ENVIRONMENT_DIR}/${directory}" ]; then
echo "Removing ${directory} directory"
rm -r "${ENVIRONMENT_DIR}/${directory}"
if [ $? -ne "0" ]; then
error_exit "Error removing ${directory} directory"
fi
else
echo "Skipping removal of ${directory} directory because it does not exist"
fi
done
# Rerun create new environment script to update the configuration
echo "./deploy/scripts/create_new_environment.sh ./environment/"
./deploy/scripts/create_new_environment.sh ./environment/
echo ""
echo "=================================================================================="
echo "The Deploy configuration is updated and you can now rerun the Ansible tasks"
echo "=================================================================================="
echo ""