Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shell: add devops.sh #212

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 127 additions & 0 deletions devops.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# /bin/bash

KATZENMINT=0
MIX=0
PROVIDER=0
ERROR=0
CONFIGDIR=$(pwd)
BINARYDIR=$(pwd)

while [ $# -gt 0 ]; do
case "$1" in
--katzenmint)
KATZENMINT=1
;;
--mix)
MIX=1
;;
--provider)
PROVIDER=1
;;
--configdir)
CONFIGDIR="$2"
shift
;;
--binarydir)
BINARYDIR="$2"
shift
;;
*)
echo "Illegal option $1"
ERROR=1
;;
esac
shift $(( $# > 0 ? 1 : 0 ))
done

usage () {
cat <<EOF

Usage:
sh devops.sh [options]
example: sh devops --katzenmint

Available options:
--katzenmint update katzenmint
--mix update mix
--provider update provider
--configdir config directory
--binarydir binary directory
EOF
exit 1
}

stopRemoteService () {
echo "stop $1..."
ansible-playbook -i testnet/remote/ansible/inventory/digital_ocean.py -l $1 testnet/remote/ansible/stop.yml
if [ $? -ne 0 ]; then
echo "failed to stop $1"
exit 1
fi
}

main () {
if [ ! -d "$CONFIGDIR" ]; then
echo "config directory not existed"
exit 1
fi
if [ ! -d "$BINARYDIR" ]; then
echo "binary directory not existed"
exit 1
fi
if [ $KATZENMINT = 1 ]; then
echo "update katzenmints..."

stopRemoteService "mixnet"
stopRemoteService "providernet"
stopRemoteService "sentrynet"

echo "upload binary files"
ansible-playbook -i testnet/remote/ansible/inventory/digital_ocean.py -l sentrynet testnet/remote/ansible/config.yml -e CONFIGDIR=$CONFIGDIR -e BINARY=$BINARYDIR/katzenmint
if [ $? -ne 0 ]; then
echo "failed to upload"
fi

ansible-playbook -i testnet/remote/ansible/inventory/digital_ocean.py -l sentrynet testnet/remote/ansible/status.yml
fi

if [ $MIX = 1 ]; then
if [ $KATZENMINT = 0 ]; then
stopRemoteService "mixnet"
fi

echo "upload binary files"
ansible-playbook -i testnet/remote/ansible/inventory/digital_ocean.py -l mixnet testnet/remote/ansible/config.yml -e CONFIGDIR=$CONFIGDIR -e BINARY=$BINARYDIR/meson-server
if [ $? -ne 0 ]; then
echo "failed to upload"
fi

ansible-playbook -i testnet/remote/ansible/inventory/digital_ocean.py -l mixnet testnet/remote/ansible/status.yml
fi

if [ $PROVIDER = 1 ]; then
if [ $KATZENMINT = 0 ]; then
stopRemoteService "providernet"
fi

echo "upload binary files"
ansible-playbook -i testnet/remote/ansible/inventory/digital_ocean.py -l providernet testnet/remote/ansible/config.yml -e CONFIGDIR=$CONFIGDIR -e BINARY=$BINARYDIR
if [ $? -ne 0 ]; then
echo "failed to upload"
fi

ansible-playbook -i testnet/remote/ansible/inventory/digital_ocean.py -l providernet testnet/remote/ansible/status.yml
fi
}

if [ $KATZENMINT = 0 ] && [ $MIX = 0 ] && [ $PROVIDER = 0 ]; then
usage
fi

if [ $ERROR = 1 ]; then
usage
fi



main