You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ngcpcfg/scripts/decrypt

89 lines
2.1 KiB

#!/bin/bash
# Purpose: decrypt ngcp configuration archive
################################################################################
set -e
set -u
# helper functions {{{
# sadly we can't source ${FUNCTIONS}/main as we are missing a bunch of
# configuration files that are supposed to be available, therefore
# provide the main functions we need for successfull execution of the
# decrypt function
log_info() {
logger -t ngcpcfg -- "$*"
echo "$*"
}
# info without ending newline
log_info_n() {
logger -t ngcpcfg -- "$*"
printf -- "$*"
}
log_debug() {
if [ -n "${DEBUG:-}" ] ; then
logger -t ngcpcfg -- "Debug: $*"
echo ; echo "DEBUG: $*" ; echo # newlines to avoid messup with cmdline output
fi
}
log_warn() {
logger -t ngcpcfg -- "Warning: $*"
echo "Warning: $*"
}
log_error() {
logger -t ngcpcfg -- "Error: $*"
echo "Error: $*" >&2
}
# }}}
# main script
if ! type -p gpg &>/dev/null ; then
log_error "gpg binary not found, exiting."
exit 1
fi
RC=0
TARGZ=/etc/ngcp-config-crypted.tgz
if ! gpg -d "$TARGZ".gpg > "$TARGZ" ; then
log_error "Error while decrypting ${TARGZ}.gpg"
RC=1
else
cd / # important to extract files at according place
if tar zxf "$TARGZ" ; then
log_info "Successfully restored configuration archive ${TARGZ}.gpg"
log_info "Now you should be able to run 'ngcpcfg apply' again."
else
log_error "Error while restoring ${TARGZ}.gpg"
RC=1
fi
fi
if ! [ -d /mnt/glusterfs/shared_config ] ; then
log_warn "Looks like glusterfs is not running, can not install it automatically.
Please execute the following command on one node
as soon as glusterfs share is mounted again:
git clone --bare /etc/ngcp-config /mnt/glusterfs/ngcpcfg-share
"
else
if [ -d /mnt/glusterfs/ngcpcfg-share ] ; then
log_info "Shared storage exists already, ignoring request to (re)install it."
else
log_info "Copying git repository to shared storage."
git clone --bare /etc/ngcp-config /mnt/glusterfs/ngcpcfg-share
fi
fi
# don't leave the unencrypted archive behind
rm -f "$TARGZ"
exit "$RC"
## END OF FILE #################################################################