5 CONFIGFILE="/etc/rbm/ssh-keysync-server.conf"
6 CONFIG_OLD="${CONFIGFILE}.oldsave"
8 function upgrade_config() {
11 echo "Upgrading Configuration file ${CONFIGFILE}... "
13 if ! grep -q '\[general\]' "${CONFIGFILE}"; then
15 echo -n " * Moving old file to ${CONFIG_OLD}... "
16 mv "${CONFIGFILE}" "${CONFIG_OLD}" && echo "done." || echo "Failed!"
18 if [ -f ${CONFIGOLD} -a -r ${CONFIG_OLD} ]; then
19 if ! source "${CONFIG_OLD}" ; then
20 echo "Failed to load config file \"${CONFIG_OLD}\", exiting." >&2
24 echo "Unable to load config file \"${CONFIG_OLD}\". File does not exist or is not accessable, exiting." >&2
28 # Default values if not there
29 [ "${BASE_DIR}" ] || BASE_DIR="/var/cache/ssh-keysync"
30 [ "${VALID_USER}" ] || VALID_USER="skeysync"
33 if [ "${DOMAIN_LIST}" ]; then
34 export DOMAIN="`echo ${DOMAIN_LIST} | cut -d, -f1`"
35 ALT_DOMAINS="`echo ${DOMAIN_LIST} | cut -d, -f2-`"
37 echo "Warning: No domain specification found in the old configuration."
38 echo "You have to specify one manually to let ssh-keysync-merge work."
42 EXPR_USER="s|^user.*|user = ${VALID_USER}|"
43 EXPR_BASEDIR="s|^base_dir.*|base_dir = ${BASE_DIR}|"
45 echo -n "Writing new config... "
46 cat << EOF | sed -e "${EXPR_USER}" -e "${EXPR_BASEDIR}" > "${CONFIGFILE}" && echo "done." || echo "Failed!"
48 # /etc/rbm/ssh-keysync-server.conf
52 # General configuration options
54 base_dir="/var/cache/ssh-keysnc"
58 # The domains managed by RBM::sshKeySync::Merge
61 # alt_domains = alt.rnateiv.dom.ain.name, another.dom.ain.name
62 # separate_outfile = yes (default)
63 # common_outfile = no (default)
67 # To merge all hostkeys in the domain 'sourceforge.net' into
68 # a separate known_host file for this domain and into a global
69 # known_host file and adding \$hostname.sf.net to each entry,
70 # you could specify the following:
73 # alt_domains = sf.net
74 # separate_outfile =no
75 # common_outfile = yes
81 if [ "${DOMAIN}" ]; then
82 echo "[$DOMAIN]" >> "${CONFIGFILE}"
83 [ "${ALT_DOMAINS}" ] && echo "alt_domains = ${ALT_DOMAINS}" >> "${CONFIGFILE}"
84 echo "separate_outfile = yes" >> "${CONFIGFILE}"
85 echo "common_outfile = yes" >> "${CONFIGFILE}"
89 echo " Configuration file ${CONFIGFILE} is up to date."
95 # Upgrade the filesystem structure
96 function upgrade_dirs() {
97 # Check for old style config
98 if ! grep -q '\[general\]' "${CONFIGFILE}"; then
100 if [ -f ${CONFIG_FILE} -a -r ${CONFIG_FILE} ]; then
101 if ! source "${CONFIGFILE}" ; then
102 echo "Failed to load config file \"${CONFIGFILE}\", exiting." >&2
106 echo "Unable to load config file \"${CONFIGFILE}\". File does not exist or is not accessable, exiting." >&2
110 DOMAIN=`echo $( grep '^\[' "${CONFIGFILE}" | grep -v 'general' ) | sed -e 's/\[\(.\+\)\].*/\1/'`
111 BASE_DIR=`grep '^base_dir' "${CONFIGFILE}" | sed -e 's|.*= *\(.*\)$|\1|'`
115 if [ -z "${BASE_DIR}" ]; then
116 export BASE_DIR="/var/cache/ssh-keync"
117 echo "Warning: BASE_DIR is undefined, defaulting to ${BASE_DIR}">&2
120 [ "${DOMAIN_LIST}" ] && DOMAIN=`echo ${DOMAIN_LIST} | cut -d, -f1`
121 if [ -z "${DOMAIN}" ]; then
122 echo "Error: No domain specified in configuration, cannot continue automagic update." >&2
129 echo "Upgrade file system structure:"
130 if [ -d "${BASE_DIR}/keys" ]; then
131 echo -n " * Creating domain directory: ${BASE_DIR}/${DOMAIN} ... "
132 mkdir -p "${BASE_DIR}/${DOMAIN}" && echo "done." || echo "Failed!"
134 echo -n " * Moving ${BASE_DIR}/keys to ${BASE_DIR}/${DOMAIN}/keys... "
135 mv "${BASE_DIR}/keys" "${BASE_DIR}/${DOMAIN}" && echo "done." || echo "Failed!"
137 echo " No old style key dir found. Nothing to do for me."