Subversion Repositories ALCASAR

Rev

Rev 3321 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 3321 Rev 3322
Line 23... Line 23...
23
REPL_PWD="$(tr -dc "a-zA-Z0-9" < /dev/random | head -c "$REPL_PWD_LENGTH")"
23
REPL_PWD="$(tr -dc "a-zA-Z0-9" < /dev/random | head -c "$REPL_PWD_LENGTH")"
24
readonly REPL_PWD
24
readonly REPL_PWD
25
REPL_DB_PWD="$(tr -dc "a-zA-Z0-9" < /dev/random | head -c "$REPL_DB_PWD_LENGTH")"
25
REPL_DB_PWD="$(tr -dc "a-zA-Z0-9" < /dev/random | head -c "$REPL_DB_PWD_LENGTH")"
26
readonly REPL_DB_PWD
26
readonly REPL_DB_PWD
27
 
27
 
-
 
28
# Variables
-
 
29
role=""
-
 
30
 
-
 
31
# Check script args
-
 
32
# $@: script args
-
 
33
check_args() {
-
 
34
	# Parse args
-
 
35
	args="$(getopt --longoptions "primary,secondary,help" --options "p,s,h" -- "$@")"
-
 
36
	# Reset script args list
-
 
37
	eval set -- "$args"
-
 
38
	# Print help
-
 
39
	if [ "$#" -eq 1 ]
-
 
40
	then
-
 
41
		usage
-
 
42
		return 1
-
 
43
	fi
-
 
44
	# Loop over all args
-
 
45
	while true
-
 
46
	do
-
 
47
		case "$1" in
-
 
48
			--primary | -p)
-
 
49
				role="primary"
-
 
50
				break
-
 
51
				;;
-
 
52
			--secondary | -s)
-
 
53
				role="secondary"
-
 
54
				break
-
 
55
				;;
-
 
56
			--help | -h)
-
 
57
				usage
-
 
58
				return 2
-
 
59
				;;
-
 
60
			--)
-
 
61
				# End of args
-
 
62
				break
-
 
63
				;;
-
 
64
			*)
-
 
65
				echo "error: unknown $1" >&2
-
 
66
				return 3
-
 
67
				break
-
 
68
				;;
-
 
69
		esac
-
 
70
	done
-
 
71
}
-
 
72
 
28
# Execute SQL queries on local server
73
# Execute SQL queries on local server
29
exec_query() {
74
exec_query() {
30
	if [ $# -ne 1 ]
75
	if [ $# -ne 1 ]
31
	then
76
	then
32
		echo "A SQL query must be given." >&2
77
		echo "A SQL query must be given." >&2
Line 34... Line 79...
34
	fi
79
	fi
35
	# Execute the query
80
	# Execute the query
36
	/usr/bin/mariadb --user=root --password="$DB_ROOT_PWD" --execute="$1"
81
	/usr/bin/mariadb --user=root --password="$DB_ROOT_PWD" --execute="$1"
37
}
82
}
38
 
83
 
-
 
84
# Print help message
-
 
85
usage() {
-
 
86
	echo "usage: $0 OPTIONS"
-
 
87
	echo
-
 
88
	echo "OPTIONS"
-
 
89
	echo "	--primary, -p"
-
 
90
	echo "		Install replication as primary"
-
 
91
	echo "	--secandary, -s"
-
 
92
	echo "		Install replication as secondary"
-
 
93
	echo "	--help, -h"
-
 
94
	echo "		print this help message"
-
 
95
}
-
 
96
 
-
 
97
# Main
-
 
98
check_args "$@" || exit
-
 
99
 
39
if grep -q "REPLICATION=on" "$ALCASAR_CONF"
100
if grep -q "REPLICATION=primary" "$ALCASAR_CONF" || grep -q "REPLICATION=secondary" "$ALCASAR_CONF"
40
then
101
then
41
	echo "error: replication is already installed" >&2
102
	echo "error: replication is already installed" >&2
42
	exit 2
103
	exit 2
43
fi
104
fi
44
 
105
 
Line 112... Line 173...
112
	echo "Generating SSH key..."
173
	echo "Generating SSH key..."
113
	mkdir ~/.ssh
174
	mkdir ~/.ssh
114
	/usr/bin/ssh-keygen -t rsa -b 4096 -N "" -f ~/.ssh/id_rsa
175
	/usr/bin/ssh-keygen -t rsa -b 4096 -N "" -f ~/.ssh/id_rsa
115
fi
176
fi
116
 
177
 
117
echo "Setting replication state to 'on'..."
178
echo "Setting replication state to $role"
118
sed -i "/^REPLICATION=/s/off/on/" "$ALCASAR_CONF"
179
sed -i "/^REPLICATION=/s/=.*/=$role/" "$ALCASAR_CONF"
119
 
180
 
120
echo "Database replication succesfully installed."
181
echo "Database replication succesfully installed."
-
 
182