#!/bin/bash # ------------------------------------------ # llxcfg-setdirs (aka "The Script of Shame") # ------------------------------------------ # # Creacion de los directorios de variables para llxcfg "compatibles" con cddt-runtime # Escrito por Luis Garcia Gisbert para LliureX (Abril 2006) # set -e PATH="/usr/sbin:/usr/bin:/sbin:/bin" # VARIABLES # mantenemos compatibildad con CDDT ? CDDT_COMP="Y" # rutas VAR_PATHS="/etc /usr/share /var/lib" LLXCFG_DIR="llxcfg/vars" CDDT_DIR="cddt/vars" # funciones # --------- get_files(){ find "$1" -maxdepth 1 -xtype f } dir_to_link(){ ORIGIN_DIR="$1" TARGET_DIR="$2" if [ -d "${ORIGIN_DIR}" ]; then # si ya son la misma ruta no tenemos nada que hacer [ "`readlink -f ${ORIGIN_DIR}`" = "`readlink -f ${TARGET_DIR}`" ] && return 0 VAR_FILES="`get_files ${ORIGIN_DIR}`" for f in ${VAR_FILES}; do cp -a ${f} ${TARGET_DIR} done rm -fr ${ORIGIN_DIR} else mkdir -p `dirname ${ORIGIN_DIR}` fi ln -s ${TARGET_DIR} ${ORIGIN_DIR} return 0 } usage(){ echo "$0 {create|delete}" >&2 exit 1 } # MAIN PROGRAM case "$1" in create) for d in ${VAR_PATHS}; do if [ "${CDDT_COMP}" = "Y" ]; then mkdir -p ${d}/${CDDT_DIR} dir_to_link ${d}/${LLXCFG_DIR} ${d}/${CDDT_DIR} else mkdir -p ${d}/${LLXCFG_DIR} fi done ;; delete) for d in ${VAR_PATHS}; do if [ "${CDDT_COMP}" = "Y" ]; then rm -f ${d}/${LLXCFG_DIR} else rmdir --ignore-fail-on-non-empty ${d}/${LLXCFG_DIR} fi done ;; *) usage ;; esac exit 0