Changeset 6129 in /cluster/svnroot


Ignore:
Timestamp:
Jun 5, 2019 5:31:45 PM (17 months ago)
Author:
skylar
Message:

style re #1015

File:
1 edited

Legend:

Unmodified
Added
Removed
  • bccd-ng/branches/skylar/bccd-3.3.4/bin/extract_squashfs

    r4726 r6129  
    1 #!/bin/bash
     1#!/usr/bin/env bash
     2
     3# $Id$
    24
    35set -eo pipefail
    46
     7PATH=/bin:/sbin:/usr/bin:/usr/sbin
     8
    59function usage() {
    6     echo -e "$(basename $0) -i <path-to-bccd-iso>\n" >&2
     10    echo -e "$(basename "$0") -i <path-to-bccd-iso>\\n" >&2
    711    echo "Extract the KNOPPIX/KNOPPIX squashfs to a directory" >&2
    812    echo "See http://bccd.net/wiki/index.php/DevelopmentInstructions#Regenerating_KNOPPIX.2FKNOPPIX_squashfs for more details" >&2
     
    1014
    1115function cleanup() {
    12     local RC=$1
    13     local ISO_MOUNT=$2
    14     local SQUASHFS_MOUNT=$3
    15     local ISO_DIR=$4
    16     local SQUASHFS_DIR=$5
     16    local RC="$1"
     17    local ISO_MOUNT="$2"
     18    local SQUASHFS_MOUNT="$3"
     19    local ISO_DIR="$4"
     20    local SQUASHFS_DIR="$5"
    1721
    1822    # Clear trap so we don't get in a loop
     
    2327
    2428    for DIR in ${ISO_MOUNT} ${SQUASHFS_MOUNT}; do
    25         if mount | grep -q ${DIR} > /dev/null; then
    26             /bin/umount ${DIR}
    27             /bin/rmdir ${DIR}
     29        if mount | grep -q "${DIR}" > /dev/null; then
     30            umount "${DIR}"
     31            rmdir "${DIR}"
    2832        fi
    2933    done
     
    3135    # Only delete squashfs on failure
    3236    if [[ ${RC} -ne 0 ]]; then
    33         if [[ ${SQUASHFS_DIR} =~ ^/tmp ]] && [[ -d ${SQUASHFS_DIR} ]]; then
    34             /bin/rm -fr ${SQUASHFS_DIR}
     37        if [[ ${SQUASHFS_DIR} =~ ^/tmp ]] && [[ -d "${SQUASHFS_DIR}" ]]; then
     38            rm -fr "${SQUASHFS_DIR}"
    3539        fi
    36         if [[ ${ISO_DIR} =~ ^/tmp ]] && [[ -d ${ISO_DIR} ]]; then
    37             bin/rm -fr ${ISO_DIR}
     40        if [[ ${ISO_DIR} =~ ^/tmp ]] && [[ -d "${ISO_DIR}" ]]; then
     41            rm -fr "${ISO_DIR}"
    3842        fi
    3943    fi
    4044
    41     exit ${RC}
     45    exit "${RC}"
    4246}
    4347
     
    4751
    4852while getopts "hi:" option; do
    49     case ${option} in
    50         h)
     53    case "${option}" in
     54        h )
    5155            usage
    5256            exit 1
    5357            ;;
    54         i)
    55             ISO_PATH=${OPTARG}
     58        i )
     59            ISO_PATH="${OPTARG}"
     60            ;;
     61        * )
     62            usage
     63            exit 1
    5664            ;;
    5765    esac
    5866done
    5967
    60 if [[ $(whoami) != "root" ]]; then
    61     echo "$(basename $0) must be run as root!" >&2
     68if [[ "$(whoami)" != "root" ]]; then
     69    echo "$(basename "$0") must be run as root!" >&2
    6270    exit 2
    6371elif [[ -z ${ISO_PATH} ]]; then
     
    6573    usage
    6674    exit 1
    67 elif [[ ! -f ${ISO_PATH} ]] || [[ ! -r ${ISO_PATH} ]]; then
     75elif [[ ! -f "${ISO_PATH}" ]] || [[ ! -r "${ISO_PATH}" ]]; then
    6876    echo "${ISO_PATH} does not exist or is unreadable" >&2
    6977    exit 2
     
    7482ISO_DIR=$(/bin/mktemp -d -p /tmp bccd.XXXXXX)
    7583SQUASHFS_DIR=$(/bin/mktemp -d -p /tmp squashfs.XXXXXX)
    76 SQUASHFS=${ISO_DIR}/KNOPPIX/KNOPPIX
     84SQUASHFS="${ISO_DIR}/KNOPPIX/KNOPPIX"
    7785
    7886echo "Mounting ${ISO_PATH} to ${ISO_MOUNT}" >&2
    79 /bin/mount ${ISO_PATH} ${ISO_MOUNT} -o loop,ro
     87mount "${ISO_PATH}" "${ISO_MOUNT}" -o loop,ro
    8088
    8189echo "Copying ${ISO_MOUNT} to ${ISO_DIR}" >&2
    82 /bin/tar -C ${ISO_MOUNT} -cf - . | /bin/tar -C ${ISO_DIR} -xf -
     90tar -C "${ISO_MOUNT}" -cf - . | tar -C "${ISO_DIR}" -xf -
    8391
    84 if [[ ! -f ${SQUASHFS} ]]; then
     92if [[ ! -f "${SQUASHFS}" ]]; then
    8593    echo "${SQUASHFS} does not exist, not BCCD ISO?" >&2
    8694    exit 2
     
    8896
    8997echo "Mounting ${SQUASHFS} to ${SQUASHFS_MOUNT}" >&2
    90 /bin/mount ${SQUASHFS} ${SQUASHFS_MOUNT} -o loop,ro
     98mount "${SQUASHFS}" "${SQUASHFS_MOUNT}" -o loop,ro
    9199
    92100echo "Copying ${SQUASHFS_MOUNT} to ${SQUASHFS_DIR}" >&2
    93 /bin/tar -C ${SQUASHFS_MOUNT} -cf - . | /bin/tar -C ${SQUASHFS_DIR} -xf -
     101tar -C "${SQUASHFS_MOUNT}" -cf - . | tar -C "${SQUASHFS_DIR}" -xf -
    94102
    95103echo "ISO: ${ISO_DIR}"
Note: See TracChangeset for help on using the changeset viewer.