#!/bin/bash MOUNT_PATH="/media/znb" TCOS_PATH="/var/lib/tcos/tftp/modelo-" SQUASH_PATH="/var/lib/tcos/tftp/" MANIFEST_FILE="casper/filesystem.manifest" MANIFEST_SERVER="casper/server.manifest" MANIFEST_CLIENT="casper/client.manifest" MANIFEST_CENTRO="casper/centro.manifest" MANIFEST_BIBLIO="casper/biblioteca.manifest" PACKAGES_FILE="casper/packages.txt" _die() { echo "$1" exit 1 } _usage() { echo "/usr/sbin/znb-mounter mount ISO_PATH" echo "/usr/sbin/znb_mounter update-nfs" echo "/usr/sbin/znb_mounter unsquashfs SQUASHFILE" exit 1 } _sanity_checks() { # Sanity checks. [ -r "$ISO_PATH" ] || _usage "Not found ISO on : $ISO_PATH" # Check mountpoint mkdir -p "$MOUNT_PATH" umount -f -l "$MOUNT_PATH" 2>/dev/null || true } _mount_iso() { mount -o loop "$ISO_PATH" "$MOUNT_PATH" } _umount_iso() { umount -f -l "$MOUNT_PATH" 2>/dev/null || true } _do_unsquashfs() { # Unsquashfs file [ $1 ] || _die "Model type not found" FLAVOUR_DIR="${SQUASH_PATH}$1" [ -d $FLAVOUR_DIR ] || _die "File $FLAVOUR_DIR not found" for SQUASHFSFILE in $(ls $FLAVOUR_DIR/casper/*.squashfs); do SQUASHFSFILE="$1" SQUASHFSDIR="$(dirname $SQUASHFSFILE)/$(basename $SQUASHFSFILE '.squashfs').dir" logger -t "znb_mounter" "Ready to extract squashfile on $SQUASHFSDIR" unsquashfs $SQUASHFSFILE -d $SQUASHFSDIR done } _get_manifest_of_iso() { if [ -r "$MOUNT_PATH"/"$MANIFEST_SERVER" ] && [ -r "$MOUNT_PATH"/"$MANIFEST_CLIENT" ]; then MANIFEST="$MOUNT_PATH"/"$MANIFEST_CENTRO" elif [ -r "$MOUNT_PATH"/"$MANIFEST_CLIENT" ] ; then MANIFEST="$MOUNT_PATH"/"$MANIFEST_CLIENT" elif [ -r "$MOUNT_PATH"/"$MANIFEST_SERVER" ] ; then version=$(cat "$MOUNT_PATH"/"$PACKAGES_FILE" | grep llxcfg-biblioteca | tr -s " " | cut -d " " -f3| head -1) if [ -z $version ]; then MANIFEST="$MOUNT_PATH"/"$MANIFEST_SERVER" else MANIFEST="$MOUNT_PATH"/"$MANIFEST_BIBLIO" fi elif [ -r "$MOUNT_PATH"/"$MANIFEST_FILE" ] ; then MANIFEST="$MOUNT_PATH"/"$MANIFEST_FILE" else echo "Mount path: $MOUNT_PATH not contains manifest file" fi } _get_version_of_iso() { if [ -r "$MOUNT_PATH"/"$PACKAGES_FILE" ] ; then CDD_VERSION=$(cat "$MOUNT_PATH"/"$PACKAGES_FILE" | grep lliurex-cdd | tr -s " " | cut -d " " -f3| head -1) fi } _show_results() { echo "MOUNT_PATH=$MOUNT_PATH" echo "MANIFEST=$MANIFEST" echo "CDD_VERSION=$CDD_VERSION" } _update_nfs() { llxcfg-nfs update } _update_pxe() { gentcos -parse-pxelinuxcfg 2>/dev/null } # MAIN ACTION="$1" shift ISO_PATH="$1" case "$ACTION" in mount) _sanity_checks _mount_iso _get_manifest_of_iso _get_version_of_iso _show_results exit 0 ;; umount) _umount_iso exit 0 ;; update-nfs) _update_nfs exit 0 ;; unsquashfs) echo "DEBUG: unsquashfs called" _do_unsquashfs $1 exit 0 ;; update-pxe) _update_pxe exit 0 ;; *) _usage ;; esac exit 0