Skip to content

Commit

Permalink
Reformatted code to pass linter
Browse files Browse the repository at this point in the history
Reformatted code so it passes linter from
https://www.shellcheck.net/

This closes Issue #20
  • Loading branch information
altmannmarcelo committed Mar 29, 2019
1 parent db8fab1 commit be92147
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 135 deletions.
56 changes: 28 additions & 28 deletions lxc/create_proxysql.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,49 +49,49 @@ do
;;
esac
done


if [[ -z "$NUMBER_OF_NODES" ]] ; then NUMBER_OF_NODES=1; fi
if [[ -z "$NAME" ]] ;
then
if [[ -z "$NAME" ]] ;
then
echo "You need to specify a name"
exit 1
fi
for (( i=1; i<=$NUMBER_OF_NODES; i++ ))do
for (( i=1; i<=NUMBER_OF_NODES; i++ ))do
NODE_NAME="$NAME-$i"
lxc init centos-7 $NODE_NAME -s $(whoami)
lxc config set $NODE_NAME security.privileged true
lxc start $NODE_NAME
lxc init centos-7 "$NODE_NAME" -s "$(whoami)"
lxc config set "$NODE_NAME" security.privileged true
lxc start "$NODE_NAME"
for (( c=1; c<=20; c++ ))do
NODE_IP=$(lxc exec $NODE_NAME -- ip addr | grep inet | grep eth0 | awk '{print $2}' | awk -F'/' '{print $1}')
NODE_IP=$(lxc exec "$NODE_NAME" -- ip addr | grep inet | grep eth0 | awk '{print $2}' | awk -F'/' '{print $1}')
#echo "NODEIP: $NODE_IP"
if [[ -n $NODE_IP ]] ; then
break;
fi
sleep 1
done
lxc exec $NODE_NAME -- yum -y install https://repo.percona.com/yum/percona-release-latest.noarch.rpm
lxc exec $NODE_NAME -- yum -y install proxysql Percona-Server-client-57 which
lxc exec $NODE_NAME -- systemctl start proxysql
lxc exec "$NODE_NAME" -- yum -y install https://repo.percona.com/yum/percona-release-latest.noarch.rpm
lxc exec "$NODE_NAME" -- yum -y install proxysql Percona-Server-client-57 which
lxc exec "$NODE_NAME" -- systemctl start proxysql
sleep 2
if [[ ! -z "$PXC_NODE" ]]; then
PXC_IP=$(lxc exec $PXC_NODE -- ip addr | grep inet | grep eth0 | awk '{print $2}' | awk -F'/' '{print $1}')
lxc exec $NODE_NAME -- sed "s/CLUSTER_HOSTNAME='localhost'/CLUSTER_HOSTNAME='$PXC_IP'/g" -i /etc/proxysql-admin.cnf
lxc exec $NODE_NAME -- sed "s/CLUSTER_USERNAME='admin'/CLUSTER_USERNAME='root'/g" -i /etc/proxysql-admin.cnf
lxc exec $NODE_NAME -- sed "s/CLUSTER_PASSWORD='admin'/CLUSTER_PASSWORD='sekret'/g" -i /etc/proxysql-admin.cnf
lxc exec $NODE_NAME -- proxysql-admin --config-file=/etc/proxysql-admin.cnf --use-existing-monitor-password --without-cluster-app-user --syncusers --enable
elif [[ ! -z "$REPLICATION_PREFIX" ]]; then
for node_ip in $( $(dirname "$0")/deploy_lxc --list | grep $REPLICATION_PREFIX | awk '{print $6}');
if [[ -n "$PXC_NODE" ]]; then
PXC_IP=$(lxc exec "$PXC_NODE" -- ip addr | grep inet | grep eth0 | awk '{print $2}' | awk -F'/' '{print $1}')
lxc exec "$NODE_NAME" -- sed "s/CLUSTER_HOSTNAME='localhost'/CLUSTER_HOSTNAME='$PXC_IP'/g" -i /etc/proxysql-admin.cnf
lxc exec "$NODE_NAME" -- sed "s/CLUSTER_USERNAME='admin'/CLUSTER_USERNAME='root'/g" -i /etc/proxysql-admin.cnf
lxc exec "$NODE_NAME" -- sed "s/CLUSTER_PASSWORD='admin'/CLUSTER_PASSWORD='sekret'/g" -i /etc/proxysql-admin.cnf
lxc exec "$NODE_NAME" -- proxysql-admin --config-file=/etc/proxysql-admin.cnf --use-existing-monitor-password --without-cluster-app-user --syncusers --enable
elif [[ -n "$REPLICATION_PREFIX" ]]; then
for node_ip in $( "$(dirname "$0")"/deploy_lxc --list | grep "$REPLICATION_PREFIX" | awk '{print $6}');
do
lxc exec $NODE_NAME -- mysql -uadmin -padmin -h 127.0.0.1 -P 6032 -e "INSERT INTO mysql_servers (hostgroup_id, hostname) VALUES (11, '$node_ip');"
lxc exec "$NODE_NAME" -- mysql -uadmin -padmin -h 127.0.0.1 -P 6032 -e "INSERT INTO mysql_servers (hostgroup_id, hostname) VALUES (11, '$node_ip');"
done
lxc exec $NODE_NAME -- mysql -uadmin -padmin -h 127.0.0.1 -P 6032 -e "INSERT INTO mysql_replication_hostgroups (writer_hostgroup, reader_hostgroup) VALUES (10, 11); LOAD MYSQL SERVERS TO RUNTIME; SAVE MYSQL SERVERS TO DISK;"
lxc exec $NODE_NAME -- mysql -uadmin -padmin -h 127.0.0.1 -P 6032 -e "UPDATE global_variables SET variable_value='root' WHERE variable_name='mysql-monitor_username'"
lxc exec $NODE_NAME -- mysql -uadmin -padmin -h 127.0.0.1 -P 6032 -e "UPDATE global_variables SET variable_value='sekret' WHERE variable_name='mysql-monitor_password'"
lxc exec $NODE_NAME -- mysql -uadmin -padmin -h 127.0.0.1 -P 6032 -e "LOAD MYSQL VARIABLES TO RUNTIME; SAVE MYSQL VARIABLES TO DISK"
lxc exec $NODE_NAME -- sed "s/CLUSTER_HOSTNAME='localhost'/CLUSTER_HOSTNAME='$node_ip'/g" -i /etc/proxysql-admin.cnf
lxc exec $NODE_NAME -- sed "s/CLUSTER_USERNAME='admin'/CLUSTER_USERNAME='root'/g" -i /etc/proxysql-admin.cnf
lxc exec $NODE_NAME -- sed "s/CLUSTER_PASSWORD='admin'/CLUSTER_PASSWORD='sekret'/g" -i /etc/proxysql-admin.cnf
lxc exec $NODE_NAME -- proxysql-admin --config-file=/etc/proxysql-admin.cnf --syncusers
lxc exec "$NODE_NAME" -- mysql -uadmin -padmin -h 127.0.0.1 -P 6032 -e "INSERT INTO mysql_replication_hostgroups (writer_hostgroup, reader_hostgroup) VALUES (10, 11); LOAD MYSQL SERVERS TO RUNTIME; SAVE MYSQL SERVERS TO DISK;"
lxc exec "$NODE_NAME" -- mysql -uadmin -padmin -h 127.0.0.1 -P 6032 -e "UPDATE global_variables SET variable_value='root' WHERE variable_name='mysql-monitor_username'"
lxc exec "$NODE_NAME" -- mysql -uadmin -padmin -h 127.0.0.1 -P 6032 -e "UPDATE global_variables SET variable_value='sekret' WHERE variable_name='mysql-monitor_password'"
lxc exec "$NODE_NAME" -- mysql -uadmin -padmin -h 127.0.0.1 -P 6032 -e "LOAD MYSQL VARIABLES TO RUNTIME; SAVE MYSQL VARIABLES TO DISK"
lxc exec "$NODE_NAME" -- sed "s/CLUSTER_HOSTNAME='localhost'/CLUSTER_HOSTNAME='$node_ip'/g" -i /etc/proxysql-admin.cnf
lxc exec "$NODE_NAME" -- sed "s/CLUSTER_USERNAME='admin'/CLUSTER_USERNAME='root'/g" -i /etc/proxysql-admin.cnf
lxc exec "$NODE_NAME" -- sed "s/CLUSTER_PASSWORD='admin'/CLUSTER_PASSWORD='sekret'/g" -i /etc/proxysql-admin.cnf
lxc exec "$NODE_NAME" -- proxysql-admin --config-file=/etc/proxysql-admin.cnf --syncusers
fi
done
46 changes: 23 additions & 23 deletions lxc/create_pxc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,46 +45,46 @@ do
esac
done

for (( i=1; i<=$NUMBER_OF_NODES; i++ ))do
for (( i=1; i<=NUMBER_OF_NODES; i++ ))do
NODE_NAME="$NAME-$i"
lxc init centos-7 $NODE_NAME -s $(whoami)
lxc config set $NODE_NAME security.privileged true
lxc start $NODE_NAME
lxc init centos-7 "$NODE_NAME" -s "$(whoami)"
lxc config set "$NODE_NAME" security.privileged true
lxc start "$NODE_NAME"
for (( c=1; c<=20; c++ ))do
NODE_IP=$(lxc exec $NODE_NAME -- ip addr | grep inet | grep eth0 | awk '{print $2}' | awk -F'/' '{print $1}')
NODE_IP=$(lxc exec "$NODE_NAME" -- ip addr | grep inet | grep eth0 | awk '{print $2}' | awk -F'/' '{print $1}')
#echo "NODEIP: $NODE_IP"
if [[ -n $NODE_IP ]] ; then
break;
fi
sleep 1
done
lxc exec $NODE_NAME -- yum -y install https://repo.percona.com/yum/percona-release-latest.noarch.rpm
if [[ ! -z "$VERSION" ]]; then
lxc exec $NODE_NAME -- yum -y install tar gdb strace vim qpress socat $VERSION
VERSION_ACRONYM=$( echo ${VERSION} | awk -F'-' '{print $4}') #55, 56, 57, 80
lxc exec "$NODE_NAME" -- yum -y install https://repo.percona.com/yum/percona-release-latest.noarch.rpm
if [[ -n "$VERSION" ]]; then
lxc exec "$NODE_NAME" -- yum -y install tar gdb strace vim qpress socat "$VERSION"
VERSION_ACRONYM=$( echo "${VERSION}" | awk -F'-' '{print $4}') #55, 56, 57, 80
else
lxc exec $NODE_NAME -- yum -y install tar gdb strace vim qpress socat Percona-XtraDB-Cluster-57
lxc exec "$NODE_NAME" -- yum -y install tar gdb strace vim qpress socat Percona-XtraDB-Cluster-57
VERSION_ACRONYM="57"
fi
lxc exec $NODE_NAME -- iptables -F
lxc exec $NODE_NAME -- setenforce 0
lxc exec "$NODE_NAME" -- iptables -F
lxc exec "$NODE_NAME" -- setenforce 0
if [[ ${VERSION_ACRONYM} == "56" ]] || [[ ${VERSION_ACRONYM} == "55" ]]; then
lxc exec $NODE_NAME -- mysql_install_db --user=mysql
lxc exec "$NODE_NAME" -- mysql_install_db --user=mysql
else
lxc exec $NODE_NAME -- mysqld --initialize-insecure --user=mysql
lxc exec "$NODE_NAME" -- mysqld --initialize-insecure --user=mysql
fi
if [[ ! -z $IPS ]] ; then
if [[ -n $IPS ]] ; then
IPS="$IPS,$NODE_IP"
else
IPS="$NODE_IP"
fi
done


for (( i=1; i<=$NUMBER_OF_NODES; i++ ))do
for (( i=1; i<=NUMBER_OF_NODES; i++ ))do
NODE_NAME="$NAME-$i"
NODE_IP=$(lxc exec $NODE_NAME -- ip addr | grep inet | grep eth0 | awk '{print $2}' | awk -F'/' '{print $1}')
lxc exec $NODE_NAME -- sh -c "cat << EOF > /etc/my.cnf
NODE_IP=$(lxc exec "$NODE_NAME" -- ip addr | grep inet | grep eth0 | awk '{print $2}' | awk -F'/' '{print $1}')
lxc exec "$NODE_NAME" -- sh -c "cat << EOF > /etc/my.cnf
[mysql]
port = 3306
socket = /var/lib/mysql/mysql.sock
Expand Down Expand Up @@ -141,13 +141,13 @@ EOF"

if [[ $i -eq 1 ]]
then
lxc exec $NODE_NAME -- systemctl start mysql@bootstrap
lxc exec "$NODE_NAME" -- systemctl start mysql@bootstrap

lxc exec $NODE_NAME -- mysql -e "grant all privileges on *.* to 'root'@'%' identified by 'sekret';"
lxc exec $NODE_NAME -- mysql -e "grant all privileges on *.* to 'root'@'127.0.0.1' identified by 'sekret';"
lxc exec $NODE_NAME -- mysql -e "grant all privileges on *.* to 'root'@'localhost' identified by 'sekret';"
lxc exec "$NODE_NAME" -- mysql -e "grant all privileges on *.* to 'root'@'%' identified by 'sekret';"
lxc exec "$NODE_NAME" -- mysql -e "grant all privileges on *.* to 'root'@'127.0.0.1' identified by 'sekret';"
lxc exec "$NODE_NAME" -- mysql -e "grant all privileges on *.* to 'root'@'localhost' identified by 'sekret';"
else
lxc exec $NODE_NAME -- systemctl start mysql
lxc exec "$NODE_NAME" -- systemctl start mysql
fi
done

Expand Down
16 changes: 8 additions & 8 deletions lxc/create_replication.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,28 @@ then
FLAVOR="ps"
fi

for (( i=1; i<=$NUMBER_OF_NODES; i++ ))do
for (( i=1; i<=NUMBER_OF_NODES; i++ ))do
NODE_NAME="$NAME-$i"
NODE_IP=$(lxc exec $NODE_NAME -- ip addr | grep inet | grep eth0 | awk '{print $2}' | awk -F'/' '{print $1}')
lxc exec $NODE_NAME -- sh -c "cat << EOF >> /etc/my.cnf
NODE_IP=$(lxc exec "$NODE_NAME" -- ip addr | grep inet | grep eth0 | awk '{print $2}' | awk -F'/' '{print $1}')
lxc exec "$NODE_NAME" -- sh -c "cat << EOF >> /etc/my.cnf
log-bin
server-id=$i
report_host=$NODE_IP
EOF"
if [[ $i -ne "1" ]] ; then
lxc exec $NODE_NAME -- sh -c "cat << EOF >> /etc/my.cnf
lxc exec "$NODE_NAME" -- sh -c "cat << EOF >> /etc/my.cnf
read_only
EOF"
fi
if [[ $FLAVOR -eq "mysql" ]]; then
lxc exec $NODE_NAME -- systemctl restart mysqld
if [[ $FLAVOR == "mysql" ]]; then
lxc exec "$NODE_NAME" -- systemctl restart mysqld
else
lxc exec $NODE_NAME -- systemctl restart mysql
lxc exec "$NODE_NAME" -- systemctl restart mysql
fi
if [[ $i -eq "1" ]] ; then
MASTER_IP=$NODE_IP
else
lxc exec $NODE_NAME -- mysql -u root -psekret -e "CHANGE MASTER TO MASTER_HOST='$MASTER_IP', MASTER_USER='root', MASTER_PASSWORD='sekret'; START SLAVE"
lxc exec "$NODE_NAME" -- mysql -u root -psekret -e "CHANGE MASTER TO MASTER_HOST='$MASTER_IP', MASTER_USER='root', MASTER_PASSWORD='sekret'; START SLAVE"
fi
done

Expand Down
73 changes: 36 additions & 37 deletions lxc/create_standalone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ then
FLAVOR="ps"
fi

for (( i=1; i<=$NUMBER_OF_NODES; i++ ))do
for (( i=1; i<=NUMBER_OF_NODES; i++ ))do
NODE_NAME="$NAME-$i"
lxc init centos-7 $NODE_NAME -s $(whoami)
lxc config set $NODE_NAME security.privileged true
lxc start $NODE_NAME
lxc init centos-7 "$NODE_NAME" -s "$(whoami)"
lxc config set "$NODE_NAME" security.privileged true
lxc start "$NODE_NAME"
for (( c=1; c<=20; c++ ))do
NODE_IP=$(lxc exec $NODE_NAME -- ip addr | grep inet | grep eth0 | awk '{print $2}' | awk -F'/' '{print $1}')
NODE_IP=$(lxc exec "$NODE_NAME" -- ip addr | grep inet | grep eth0 | awk '{print $2}' | awk -F'/' '{print $1}')
#echo "NODEIP: $NODE_IP"
if [[ -n $NODE_IP ]] ; then
break;
Expand All @@ -75,45 +75,44 @@ for (( i=1; i<=$NUMBER_OF_NODES; i++ ))do
done

if [[ $FLAVOR == "ps" ]]; then
lxc exec $NODE_NAME -- yum -y install https://repo.percona.com/yum/percona-release-latest.noarch.rpm
if [[ ! -z "$VERSION" ]]; then
lxc exec $NODE_NAME -- yum -y install ${VERSION}
VERSION_ACRONYM=$( echo ${VERSION} | awk -F'-' '{print $4}') #55, 56, 57, 80
lxc exec "$NODE_NAME" -- yum -y install https://repo.percona.com/yum/percona-release-latest.noarch.rpm
if [[ -n "$VERSION" ]]; then
lxc exec "$NODE_NAME" -- yum -y install "${VERSION}"
VERSION_ACRONYM=$( echo "${VERSION}" | awk -F'-' '{print $4}') #55, 56, 57, 80
else
lxc exec $NODE_NAME -- yum -y install Percona-Server-server-57
lxc exec "$NODE_NAME" -- yum -y install Percona-Server-server-57
VERSION_ACRONYM="57"
fi
fi
elif [[ $FLAVOR == "mysql" ]]; then
lxc exec $NODE_NAME -- yum -y install https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
if [[ ! -z "$VERSION" ]]; then
VERSION_ACRONYM=$( echo ${VERSION} | awk -F'-' '{print $4}' | awk -F'.' '{print $1$2}' ) #55, 56, 57, 80
lxc exec $NODE_NAME -- yum -y --disablerepo=mysql80-community --enablerepo=mysql${VERSION_ACRONYM}-community install ${VERSION}
lxc exec "$NODE_NAME" -- yum -y install https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
if [[ -n "$VERSION" ]]; then
VERSION_ACRONYM=$( echo "${VERSION}" | awk -F'-' '{print $4}' | awk -F'.' '{print $1$2}' ) #55, 56, 57, 80
lxc exec "$NODE_NAME" -- yum -y --disablerepo=mysql80-community --enablerepo=mysql"${VERSION_ACRONYM}"-community install "${VERSION}"
else
lxc exec $NODE_NAME -- yum -y install mysql-community-server
lxc exec "$NODE_NAME" -- yum -y install mysql-community-server
VERSION_ACRONYM=80
fi
fi

lxc exec $NODE_NAME -- yum -y install tar gdb strace vim qpress socat
lxc exec $NODE_NAME -- iptables -F
lxc exec $NODE_NAME -- setenforce 0
lxc exec "$NODE_NAME" -- yum -y install tar gdb strace vim qpress socat
lxc exec "$NODE_NAME" -- iptables -F
lxc exec "$NODE_NAME" -- setenforce 0



echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ acronimo ${VERSION_ACRONYM}"
if [[ ${VERSION_ACRONYM} == "56" ]] || [[ ${VERSION_ACRONYM} == "55" ]]; then
lxc exec $NODE_NAME -- mysql_install_db --user=mysql
lxc exec "$NODE_NAME" -- mysql_install_db --user=mysql
else
lxc exec $NODE_NAME -- mysqld --initialize-insecure --user=mysql
fi
lxc exec "$NODE_NAME" -- mysqld --initialize-insecure --user=mysql
fi

if [[ $FLAVOR -eq "mysql" ]]; then
lxc exec $NODE_NAME -- systemctl start mysqld
if [[ $FLAVOR == "mysql" ]]; then
lxc exec "$NODE_NAME" -- systemctl start mysqld
else
lxc exec $NODE_NAME -- systemctl start mysql
lxc exec "$NODE_NAME" -- systemctl start mysql
fi

lxc exec $NODE_NAME -- sh -c "cat << EOF > /etc/my.cnf
lxc exec "$NODE_NAME" -- sh -c "cat << EOF > /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
Expand All @@ -126,17 +125,17 @@ pid-file=/var/run/mysqld/mysqld.pid
EOF"

if [[ $VERSION_ACRONYM == "80" ]]; then #Mysql 8 does not support GRANT with IDENTIFIED
lxc exec $NODE_NAME -- mysql -e "CREATE USER 'root'@'%' IDENTIFIED BY 'sekret';"
lxc exec $NODE_NAME -- mysql -e "SET PASSWORD FOR 'root'@'%' = 'sekret';"
lxc exec $NODE_NAME -- mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';"
lxc exec $NODE_NAME -- mysql -e "CREATE USER 'root'@'127.0.0.1' IDENTIFIED BY 'sekret';"
lxc exec $NODE_NAME -- mysql -e "SET PASSWORD FOR 'root'@'127.0.0.1' = 'sekret';"
lxc exec $NODE_NAME -- mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1';"
lxc exec $NODE_NAME -- mysql -e "SET PASSWORD FOR 'root'@'localhost' = 'sekret';"
lxc exec "$NODE_NAME" -- mysql -e "CREATE USER 'root'@'%' IDENTIFIED BY 'sekret';"
lxc exec "$NODE_NAME" -- mysql -e "SET PASSWORD FOR 'root'@'%' = 'sekret';"
lxc exec "$NODE_NAME" -- mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';"
lxc exec "$NODE_NAME" -- mysql -e "CREATE USER 'root'@'127.0.0.1' IDENTIFIED BY 'sekret';"
lxc exec "$NODE_NAME" -- mysql -e "SET PASSWORD FOR 'root'@'127.0.0.1' = 'sekret';"
lxc exec "$NODE_NAME" -- mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1';"
lxc exec "$NODE_NAME" -- mysql -e "SET PASSWORD FOR 'root'@'localhost' = 'sekret';"
else
lxc exec $NODE_NAME -- mysql -e "grant all privileges on *.* to 'root'@'%' identified by 'sekret';"
lxc exec $NODE_NAME -- mysql -e "grant all privileges on *.* to 'root'@'127.0.0.1' identified by 'sekret';"
lxc exec $NODE_NAME -- mysql -e "grant all privileges on *.* to 'root'@'localhost' identified by 'sekret';"
lxc exec "$NODE_NAME" -- mysql -e "grant all privileges on *.* to 'root'@'%' identified by 'sekret';"
lxc exec "$NODE_NAME" -- mysql -e "grant all privileges on *.* to 'root'@'127.0.0.1' identified by 'sekret';"
lxc exec "$NODE_NAME" -- mysql -e "grant all privileges on *.* to 'root'@'localhost' identified by 'sekret';"
fi
done

Expand Down
Loading

0 comments on commit be92147

Please sign in to comment.