Changeset 6134 in /cluster/svnroot for bccd-ng/trunk/bin/extract_squashfs


Ignore:
Timestamp:
Jun 5, 2019 6:00:18 PM (18 months ago)
Author:
skylar
Message:

merge addresses #1015

Location:
bccd-ng/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • bccd-ng/trunk

  • bccd-ng/trunk/bin/extract_squashfs

    r4726 r6134  
    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
    7     echo "Extract the KNOPPIX/KNOPPIX squashfs to a directory" >&2
     10    echo -e "$(basename "$0") -i <path-to-bccd-iso> [ -t /path/to/tmp/dir ] \\n" >&2
     11    echo "Extract the KNOPPIX/KNOPPIX squashfs to a temporary directory rooted in the path given in -t" >&2
     12    echo "(defaults to /tmp)" >&2
    813    echo "See http://bccd.net/wiki/index.php/DevelopmentInstructions#Regenerating_KNOPPIX.2FKNOPPIX_squashfs for more details" >&2
    914}
    1015
    1116function 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
     17    local RC="$1"
     18    local ISO_MOUNT="$2"
     19    local SQUASHFS_MOUNT="$3"
     20    local ISO_DIR="$4"
     21    local SQUASHFS_DIR="$5"
    1722
    1823    # Clear trap so we don't get in a loop
     
    2328
    2429    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}
     30        if mount | grep -q "${DIR}" > /dev/null; then
     31            umount "${DIR}"
     32            rmdir "${DIR}"
    2833        fi
    2934    done
     
    3136    # Only delete squashfs on failure
    3237    if [[ ${RC} -ne 0 ]]; then
    33         if [[ ${SQUASHFS_DIR} =~ ^/tmp ]] && [[ -d ${SQUASHFS_DIR} ]]; then
    34             /bin/rm -fr ${SQUASHFS_DIR}
     38        if [[ ${SQUASHFS_DIR} =~ ^/tmp ]] && [[ -d "${SQUASHFS_DIR}" ]]; then
     39            rm -fr "${SQUASHFS_DIR}"
    3540        fi
    36         if [[ ${ISO_DIR} =~ ^/tmp ]] && [[ -d ${ISO_DIR} ]]; then
    37             bin/rm -fr ${ISO_DIR}
     41        if [[ ${ISO_DIR} =~ ^/tmp ]] && [[ -d "${ISO_DIR}" ]]; then
     42            rm -fr "${ISO_DIR}"
    3843        fi
    3944    fi
    4045
    41     exit ${RC}
     46    exit "${RC}"
    4247}
    4348
     
    4651    INT TERM ERR EXIT
    4752
    48 while getopts "hi:" option; do
    49     case ${option} in
    50         h)
     53TMPDIR="/tmp"
     54
     55while getopts "hi:t:" option; do
     56    case "${option}" in
     57        h )
    5158            usage
    5259            exit 1
    5360            ;;
    54         i)
    55             ISO_PATH=${OPTARG}
     61        i )
     62            ISO_PATH="${OPTARG}"
     63            ;;
     64        t )
     65            TMPDIR="${OPTARG}"
     66            ;;
     67        * )
     68            usage
     69            exit 1
    5670            ;;
    5771    esac
    5872done
    5973
    60 if [[ $(whoami) != "root" ]]; then
    61     echo "$(basename $0) must be run as root!" >&2
     74export TMPDIR
     75
     76if [[ "$(whoami)" != "root" ]]; then
     77    echo "$(basename "$0") must be run as root!" >&2
    6278    exit 2
    6379elif [[ -z ${ISO_PATH} ]]; then
     
    6581    usage
    6682    exit 1
    67 elif [[ ! -f ${ISO_PATH} ]] || [[ ! -r ${ISO_PATH} ]]; then
     83elif [[ ! -f "${ISO_PATH}" ]] || [[ ! -r "${ISO_PATH}" ]]; then
    6884    echo "${ISO_PATH} does not exist or is unreadable" >&2
    6985    exit 2
    7086fi
    7187
    72 ISO_MOUNT=$(/bin/mktemp -d -p /tmp bccd_mount.XXXXXX)
    73 SQUASHFS_MOUNT=$(/bin/mktemp -d -p /tmp squashfs_mount.XXXXXX)
    74 ISO_DIR=$(/bin/mktemp -d -p /tmp bccd.XXXXXX)
    75 SQUASHFS_DIR=$(/bin/mktemp -d -p /tmp squashfs.XXXXXX)
    76 SQUASHFS=${ISO_DIR}/KNOPPIX/KNOPPIX
     88ISO_MOUNT=$(mktemp -d -p "${TMPDIR}" bccd_mount.XXXXXX)
     89SQUASHFS_MOUNT=$(mktemp -d -p "${TMPDIR}" squashfs_mount.XXXXXX)
     90ISO_DIR=$(mktemp -d -p "${TMPDIR}" bccd.XXXXXX)
     91SQUASHFS_DIR=$(mktemp -d -p "${TMPDIR}" squashfs.XXXXXX)
     92SQUASHFS="${ISO_DIR}/live/filesystem.squashfs"
    7793
    7894echo "Mounting ${ISO_PATH} to ${ISO_MOUNT}" >&2
    79 /bin/mount ${ISO_PATH} ${ISO_MOUNT} -o loop,ro
     95mount "${ISO_PATH}" "${ISO_MOUNT}" -o loop,ro
    8096
    8197echo "Copying ${ISO_MOUNT} to ${ISO_DIR}" >&2
    82 /bin/tar -C ${ISO_MOUNT} -cf - . | /bin/tar -C ${ISO_DIR} -xf -
     98tar -C "${ISO_MOUNT}" -cf - . | tar -C "${ISO_DIR}" -xf -
    8399
    84 if [[ ! -f ${SQUASHFS} ]]; then
     100if [[ ! -f "${SQUASHFS}" ]]; then
    85101    echo "${SQUASHFS} does not exist, not BCCD ISO?" >&2
    86102    exit 2
     
    88104
    89105echo "Mounting ${SQUASHFS} to ${SQUASHFS_MOUNT}" >&2
    90 /bin/mount ${SQUASHFS} ${SQUASHFS_MOUNT} -o loop,ro
     106mount "${SQUASHFS}" "${SQUASHFS_MOUNT}" -o loop,ro
    91107
    92108echo "Copying ${SQUASHFS_MOUNT} to ${SQUASHFS_DIR}" >&2
    93 /bin/tar -C ${SQUASHFS_MOUNT} -cf - . | /bin/tar -C ${SQUASHFS_DIR} -xf -
     109tar -C "${SQUASHFS_MOUNT}" -cf - . | tar -C "${SQUASHFS_DIR}" -xf -
    94110
    95111echo "ISO: ${ISO_DIR}"
Note: See TracChangeset for help on using the changeset viewer.