#!/bin/bash # ------- # netconfig-srv cpkg preconfig # (c) 2008 Luis Garcia # -------- set -e # PATH y variables PATH="$PATH:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" LLX_GETVAR="/usr/sbin/llxcfg-showvars" PROXY_VARS="PROXY_HOST PROXY_HTTP_PORT PROXY_PATH" VAR_LIST="${PROXY_VARS} SRV_DOMAIN" URL_REGEXP="^\([^\:]*\)\://\([^\/]*\)\/\(.*\)\$" TMP_CONF_DIR="./tmpconfig" # funciones exit_message() { echo $1 >&2 exit 0 } test_proxy(){ # comprobamos PROXY_VARS: [ -z "${PROXY_HOST}" ] && return 1 [ -z "${PROXY_HTTP_PORT}" ] && return 1 [ -z "${PROXY_PATH}" ] && return 1 # comprobar que el servicio está activo [ -x ${PROXY_SCRIPT} ] || return 1 return 0 } #test_smbldap() { # [ -z "$LIB_SMBLDAP" ] && return 1 # llxcfg_smbldap_get_LDAP_BASEDN # [ -z "$LDAP_BASEDN" ] && return 1 # llxcfg_smbldap_get_LDAP_LOCAL_URI # [ -z "$LDAP_LOCAL_URI" ] && return 1 # return 0 #} #test_samba(){ # [ -z "$LIB_SMBLDAP" ] && return 1 # llxcfg_smbldap_get_SAMBA_DN # [ -z "$SAMBA_DN" ] && return 1 # return 0 #} get_local_vars() { if [ -d "${NETCFG_VARS}" ]; then LOCAL_VAR_FILES="$(find ${NETCFG_VARS} -xtype f)" for f in ${LOCAL_VAR_FILES}; do cat ${f} done fi } get_local_confs() { if [ -d "${NETCFG_CONFS}" ]; then find ${NETCFG_CONFS} -type f -printf "%P\n" fi } ######## # main # ######## # lee variables y comprueba [ -x ${LLX_GETVAR} ] && eval `${LLX_GETVAR} ${VAR_LIST}` [ "${NETCFG_URL_BASE}" ] || exit_message "Undefined variable NETCFG_URL_BASE" [ "${NETCFG_VARIABLES}" ] || exit_message "Undefined variable NETCFG_VARIABLES" [ "${NETCFG_CONFFILES}" ] || exit_message "Undefined variable NETCFG_CONFFILES" # libs LIB_FILE="/usr/share/lliurex/llxcfg-netconfig/llxcfg-netconfig.sh" [ -e ${LIB_FILE} ] || exit_message "Missing variable library file ${LIB_FILE}!!" . ${LIB_FILE} VAR_FILE="${NETCFG_WWW_PATH}/${NETCFG_VARIABLES}" CONF_FILE="${NETCFG_WWW_PATH}/${NETCFG_CONFFILES}" # generamos el fichero, aunque sea vacío echo "# llxcfg-netconfig generated variable file" |skel-install "${VAR_FILE}" VAR_FILE="./skel/${VAR_FILE}" echo "LLIUREX_MA=ma3" >> ${VAR_FILE} echo "SRV_DOMAIN=${SRV_DOMAIN}" >> ${VAR_FILE} # # comprobamos LDAP # if test_smbldap ; then # # Establecemos variables de LDAP: LDAP_BASEDN, LDAP_SERVER_URI # echo "LDAP_BASEDN=\"${LDAP_BASEDN}\"" >> ${VAR_FILE} # echo "LDAP_SERVER_URI=${LDAP_LOCAL_URI}" >> ${VAR_FILE} # fi # # comprobamos samba # if test_samba ; then # echo "SMBSERVER_NAME=samba" >> ${VAR_FILE} # fi if test_proxy ; then # Establecemos variables del proxy: PROXY_HOST PROXY_HTTP_PORT PROXY_PATH echo "PROXY_HOST=${PROXY_HOST}" >> ${VAR_FILE} echo "PROXY_HTTP_PORT=${PROXY_HTTP_PORT}" >> ${VAR_FILE} echo "PROXY_PATH=${PROXY_PATH}" >> ${VAR_FILE} # de momento no se usa pero la establecemos echo "PROXY_PROTOCOLS=http ftp" >> ${VAR_FILE} fi # cupsys echo "CUPS_SERVER=cups" >> ${VAR_FILE} # ntpd echo "NTP_SERVER=ntp" >> ${VAR_FILE} get_local_vars >> ${VAR_FILE} rm -fr "$TMP_CONF_DIR" mkdir -p "$TMP_CONF_DIR" # local conffiles find ${NETCFG_CONFS} -type f -printf "%P\n" |while read f ; do llxcfg-install "${NETCFG_CONFS}/${f}" "${TMP_CONF_DIR}/${f}" done # do tar.gz tar -C "${TMP_CONF_DIR}" -czf "./skel/${CONF_FILE}" ./ exit 0