#!/bin/bash # ------- # netconfig-server update script # (c) 2008 Luis Garcia # -------- set -e # PATH y variables PATH="$PATH:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" # funciones exit_message() { echo $1 >&2 exit 0 } get_var_list(){ VAR_LIST="$(llxcfg-config dump "$NETCFG_CONFDIR_VARS")" [ -z "$VAR_LIST" ] || llxcfg-showvars "$VAR_LIST" } get_conf_list(){ llxcfg-config dump "$NETCFG_CONFDIR_CONFS" } gen_md5sum(){ while [ "$1" ] ; do if [ -d "$1" ] ; then ( cd "$1" ; find -xtype f -exec md5sum {} \; ) fi shift done } add_dir_to_tar(){ local D d D="$1" if [ -d "$D" ] ; then find "$D" -maxdepth 1 -mindepth 1 -type d -printf "%P\n" |while read d ; do tar -C "$D" -uf "$SKEL_TARBALL" "$d" done fi } delete_tmp(){ rm -fr "$npkg" rm -f "$SKEL_TARBALL" rm -f "$SKEL_LIST" rm -f "${TMP_LIST}" } ######## # main # ######## # libs LIB_FILE="/usr/share/lliurex/llxcfg-netconfig/llxcfg-netconfig.sh" [ -e ${LIB_FILE} ] || exit_message "Missing variable library file ${LIB_FILE}!!" . ${LIB_FILE} # generate the server's own npkg npkg="$(mktemp -d)" mkdir -p "$npkg/${NETCFG_VARDIR}" mkdir -p "$npkg/${NETCFG_CONFDIR}" mkdir -p "$npkg/${NETCFG_INSTDIR}" # var lists get_var_list > "$npkg/${NETCFG_VARDIR}/${NETCFG_SRV_ID}" # var(files) llxcfg-config dump "$NETCFG_CONFDIR_VARFILES" >> "$npkg/${NETCFG_VARDIR}/${NETCFG_SRV_ID}" # conffiles lists get_conf_list |while read f ; do rc=0 F="$(llxcfg-config filename "$f" 2>/dev/null)" || rc=$? if [ $rc -eq 0 ] ; then llxcfg-install "$F" "$npkg/${NETCFG_CONFDIR}/${f}" fi done # conffiles llxcfg-config list "$NETCFG_CONFDIR_CONFFILES" |while read f ; do llxcfg-install "$(llxcfg-config filename "${NETCFG_CONFDIR_CONFFILES}/${f}")" "$npkg/${NETCFG_CONFDIR}/${f}" done # install dirs llxcfg-config dump "$NETCFG_CONFDIR_INSTALL" |while read d ; do if [ -d "$d" ] ; then find "$d" -xtype f -printf "%P\n" |while read f ; do llxcfg-install "${d}/${f}" "$npkg/${NETCFG_INSTDIR}/$f" done fi done REAL_TARBALL="/${NETCFG_WWW_PATH}/${NETCFG_TARBALL}" SKEL_TARBALL="$(tempfile)" REAL_LIST="${REAL_TARBALL}.list" SKEL_LIST="$(tempfile)" # generate md5 TMP_LIST="$(tempfile)" gen_md5sum "$npkg" > "${TMP_LIST}" # general files (dirs) llxcfg-config dump "$NETCFG_CONFDIR_DIRS" |while read d ; do gen_md5sum "$d" >> "${TMP_LIST}" done sort "${TMP_LIST}" > "${SKEL_LIST}" # dirty trick to avoid tarball md5 nightmare ... if [ -r "$REAL_LIST" -a -r "$REAL_TARBALL" ] && diff -q "$REAL_LIST" "$SKEL_LIST" &>/dev/null ; then delete_tmp exit 0 fi # create tar file add_dir_to_tar "$npkg" llxcfg-config dump "$NETCFG_CONFDIR_DIRS" |while read d ; do add_dir_to_tar "$d" done llxcfg-install --mode=644 "$SKEL_TARBALL" "$REAL_TARBALL" llxcfg-install --mode=644 "$SKEL_LIST" "$REAL_LIST" delete_tmp zero-net-boot --check-isos || true exit 0