mirror of https://github.com/sipwise/ngcpcfg.git
102 lines
3.0 KiB
102 lines
3.0 KiB
#!/bin/bash
|
|
# Purpose: commit pending changes
|
|
################################################################################
|
|
|
|
set -e
|
|
set -u
|
|
set -o pipefail
|
|
|
|
# support testsuite
|
|
FUNCTIONS="${FUNCTIONS:-/usr/share/ngcp-ngcpcfg/functions/}"
|
|
HELPER="${HELPER:-/usr/share/ngcp-ngcpcfg/helper/}"
|
|
HOOKS="${HOOKS:-/usr/share/ngcp-ngcpcfg/hooks/}"
|
|
SCRIPTS="${SCRIPTS:-/usr/share/ngcp-ngcpcfg/scripts/}"
|
|
NGCP_HOSTNAME="$(ngcp-hostname)"
|
|
|
|
if ! [ -r "${FUNCTIONS}"/main ] ; then
|
|
printf "Error: %s/main could not be read. Exiting.\n" "${FUNCTIONS}">&2
|
|
exit 1
|
|
fi
|
|
|
|
timestamp_replacementchars=''
|
|
# shellcheck disable=SC1090
|
|
. "${FUNCTIONS}"/main
|
|
|
|
# main script
|
|
|
|
# ensure that existing hooks are up2date
|
|
hook_setup "${NGCPCTL_MAIN}/.git/hooks"
|
|
|
|
if [ -x "${NGCPCTL_MAIN}/.git/hooks/pre-commit" ] ; then
|
|
"${NGCPCTL_MAIN}/.git/hooks/pre-commit"
|
|
fi
|
|
|
|
# Apply configured file ownership and permissions
|
|
chown_configs
|
|
|
|
cd "$NGCPCTL_MAIN"
|
|
|
|
if [ -z "${NO_DB_SYNC:-}" ] ; then
|
|
if [ -f "${RTP_INTERFACES_CONFIG}" ] ; then
|
|
log_info "Executing sync-db: "
|
|
"${HELPER}/sync-db" "$NGCPCTL_CONFIG" "$CONSTANTS_CONFIG" "$RTP_INTERFACES_CONFIG" 2>&1 | \
|
|
sed "s/^/$timestamp_replacementchars/" 2>&1 | \
|
|
tee >(logger -t ngcpcfg --id="${NGCPCFG_PID}") || true
|
|
else
|
|
log_info "Executing sync-db: "
|
|
"${HELPER}/sync-db" "$NGCPCTL_CONFIG" "$CONSTANTS_CONFIG" 2>&1 | \
|
|
sed "s/^/$timestamp_replacementchars/" 2>&1 | \
|
|
tee >(logger -t ngcpcfg --id="${NGCPCFG_PID}") || true
|
|
fi
|
|
else
|
|
log_debug "no-db-sync: skipping 'sync-db'"
|
|
fi
|
|
|
|
if ! git config user.name >/dev/null ; then
|
|
log_debug 'git config user.name ngcp-config'
|
|
git config user.name "ngcp-config"
|
|
fi
|
|
if ! git config user.email >/dev/null ; then
|
|
log_debug "git config user.email \"root@\${NGCP_HOSTNAME}\""
|
|
git config user.email "root@${NGCP_HOSTNAME}"
|
|
fi
|
|
|
|
if ! git config --global user.name >/dev/null ; then
|
|
log_debug "git config --global user.name \"git user on \${NGCP_HOSTNAME}\""
|
|
git config --global user.name "git user on ${NGCP_HOSTNAME}"
|
|
fi
|
|
if ! git config --global user.email >/dev/null ; then
|
|
log_debug "git config --global user.email \"root@\${NGCP_HOSTNAME}\""
|
|
git config --global user.email "root@${NGCP_HOSTNAME}"
|
|
fi
|
|
|
|
# commit message
|
|
if [ -z "${1:-}" ] ; then
|
|
msg="committing uncommented changes"
|
|
else
|
|
msg="$*"
|
|
fi
|
|
|
|
if is_git_clean ; then
|
|
log_info "OK: nothing to commit."
|
|
else
|
|
log_debug "msg:\"$msg\""
|
|
log_debug "git add . ; git commit -a -m \"\$msg [\$(date --rfc-3339=ns)]\""
|
|
git add .
|
|
git commit -a -m "$msg [$(date --rfc-3339=ns)]" >/dev/null
|
|
log_info "OK"
|
|
fi
|
|
|
|
log_debug "${SCRIPTS}/etckeeper"
|
|
"${SCRIPTS}"/etckeeper >/dev/null
|
|
|
|
if [ -z "${NO_DB_SYNC:-}" ] ; then
|
|
log_info "Synchronizing MySQL grants/credentials"
|
|
ngcp-sync-grants | sed "s/^/$timestamp_replacementchars/"
|
|
ngcp-sync-constants | sed "s/^/$timestamp_replacementchars/"
|
|
else
|
|
log_debug "no-db-sync: skipping 'ngcp-sync-grants' + 'ngcp-sync-constants'"
|
|
fi
|
|
|
|
## END OF FILE #################################################################
|