#!/bin/bash # ------- # File: llxcfg-install # Description: Simple script to install (cfg) files # # Oct 2006, Luis Garcia # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA # -------- set -e PATH="/usr/sbin:/usr/bin:/sbin:/bin" # VARIABLES BACKUP="" MODE="" OWNER="" GROUP="" END_PARAM="" DIR_MODE="" LOG_FILE="" ACTION_CMD="cat" TEXT_ONLY="" LIB_FILE="/usr/share/lliurex/llxcfg-runtime/llxcfg-installfuncs.sh" [ -f ${LIB_FILE} ] || error_msg "Library file \"${LIB_FILE}\" not found" . ${LIB_FILE} usage(){ error_msg "Usage (file mode): $0 [--backup-dir=DIR] [--copy-dir=DIR] [--mode=MODE] [--owner=OWNER] [--group=GROUP] [--cmd=CMD] [--log=LOG] [--text] SOURCE DEST\n\ Usage (dir mode): $0 --dir [--backup-dir=DIR] [--copy-dir=DIR] [--mode=MODE] [--owner=OWNER] [--group=GROUP] [--cmd=CMD] [--log=LOG] SOURCE_DIR DEST_DIR" } # MAIN PROGRAM while [ -z "${END_PARAM}" ]; do case "$1" in --dir) DIR_MODE="Y" shift ;; --backup-dir=*) BACKUPDIR="`get_parameter --backup-dir $1`" shift ;; --copy-dir=*) COPYDIR="`get_parameter --copy-dir $1`" shift ;; --mode=*) MODE="`get_parameter --mode $1`" shift ;; --owner=*) OWNER="`get_parameter --owner $1`" shift ;; --group=*) GROUP="`get_parameter --group $1`" shift ;; --cmd=*) TMP_ACTION_CMD="`get_parameter --cmd $1`" shift type "$TMP_ACTION_CMD" &>/dev/null && ACTION_CMD="$TMP_ACTION_CMD" ;; --log=*) LOG_FILE="`get_parameter --log $1`" shift ;; --text) TEXT_ONLY="Y" shift ;; --binary) # default mode shift ;; *) END_PARAM="YES" ;; esac done [ -z "$1" -o -z "$2" ] && usage SOURCE="$1" TARGET="$2" if [ -z "${DIR_MODE}" ]; then # file mode, test source if [ "${SOURCE}" != "-" ] ; then if [ -d "${SOURCE}" ] ; then # try dir-mode DIR_MODE="Y" else [ -f "${SOURCE}" ] || error_msg "Source file \"${SOURCE}\" not found" fi fi fi if [ "${DIR_MODE}" = "Y" ]; then # dir mode [ -d "${SOURCE}" ] || error_msg "Source \"${SOURCE}\" is not a directory" [ -f "${TARGET}" ] && error_msg "Target \"${TARGET}\" is a file" if [ ! -d "${TARGET}" ] ; then # try to create destination dir mkdir -p "${TARGET}" &> /dev/null || true fi [ -d "${TARGET}" ] || error_msg "Source \"${TARGET}\" is not a directory" llxcfg_install_dir "${SOURCE}" "${TARGET}" else # file mode llxcfg_install "${SOURCE}" "${TARGET}" || exit 1 fi exit 0