From 0aea72533f832d9026137fc475d358799289942d Mon Sep 17 00:00:00 2001 From: lars Date: Thu, 1 Jun 2006 23:48:10 +0000 Subject: [PATCH] removed some bashisms --- bin/cbox-manage.sh | 48 ++++++++++++++++---------------- bin/cbox-root-actions.sh | 59 ++++++++++++++++++++-------------------- templates/show_volume.cs | 43 +++++++++++++++-------------- 3 files changed, 75 insertions(+), 75 deletions(-) diff --git a/bin/cbox-manage.sh b/bin/cbox-manage.sh index 8a11ff1..30a82a6 100755 --- a/bin/cbox-manage.sh +++ b/bin/cbox-manage.sh @@ -30,20 +30,20 @@ LIB_DIR=$(dirname "$0") DEVICE_NAME_PREFIX="Disk #" # read the default setting file, if it exists -[ -e /etc/default/cryptobox ] && . /etc/default/cryptobox +test -e /etc/default/cryptobox && . /etc/default/cryptobox -[ ! -e "$CONF_FILE" ] && echo "Could not find the configuration file: $CONF_FILE" >&2 && exit 1 +test ! -e "$CONF_FILE" && echo "Could not find the configuration file: $CONF_FILE" >&2 && exit 1 # parse config file . "$CONF_FILE" -[ ! -e "$CONF_FILE" ] && echo "Could not find the distribution specific configuration file: $CONF_FILE" >&2 && exit 1 +test ! -e "$CONF_FILE" && echo "Could not find the distribution specific configuration file: $CONF_FILE" >&2 && exit 1 # parse the distribution specific file . "$DISTRIBUTION_CONF" # check for writable log file -[ -w "$LOG_FILE" ] || LOG_FILE=/tmp/$(basename "$LOG_FILE") +test -w "$LOG_FILE" || LOG_FILE=/tmp/$(basename "$LOG_FILE") # retrieve configuration directory CONFIG_DIR="$(getent passwd $CRYPTOBOX_USER | cut -d ':' -f 6)/config" @@ -65,7 +65,7 @@ function log_msg() { # the log file is (maybe) not writable during boot - try # before writing ... - [ -w "$LOG_FILE" ] || return 0 + test -w "$LOG_FILE" || return 0 echo >>"$LOG_FILE" echo "##### `date` #####" >>"$LOG_FILE" echo "$1" >>"$LOG_FILE" @@ -104,7 +104,7 @@ function config_set_value() # parameters: SettingName [SettingValue] # read from stdin if SettingValue is not defined { - if [ $# -gt 1 ] + if test $# -gt 1 then echo "$2" > "$CONFIG_DIR/$1" else cat - >"$CONFIG_DIR/$1" fi @@ -275,23 +275,21 @@ function is_encrypted() { } -function get_available_disks() -# looks which allowed disks are at the moment connected with the cbox -{ +# list which allowed disks are at the moment connected with the cbox +function get_available_disks() { for scan in $SCAN_DEVICES do for avail in $ALL_PARTITIONS - do echo "$avail" | grep -q "^$scan[0-9]*" && echo "/dev/$avail" + do echo "$avail" | grep -q "^$scan[^/]*" && echo "/dev/$avail" done done return 0 } -function mount_crypto() # Parameter: DEVICE -{ +function mount_crypto() { local device=$1 - [ -z "$device" ] && error_msg 4 'No valid harddisk found!' + test -z "$device" && error_msg 4 'No valid harddisk found!' is_mounted "$device" && echo "The crypto filesystem is already active!" && return # passphrase is read from stdin log_msg "Mounting a crypto partition from $device" @@ -332,16 +330,16 @@ export PATH=/usr/sbin:/usr/bin:/sbin:/bin ACTION=help -[ $# -gt 0 ] && ACTION=$1 && shift +test $# -gt 0 && ACTION=$1 && shift case "$ACTION" in crypto-up ) - [ $# -ne 1 ] && error_msg 10 "invalid number of parameters for 'crypto-up'" + test $# -ne 1 && error_msg 10 "invalid number of parameters for 'crypto-up'" is_device_allowed "$1" || error_msg 12 "invalid device: $1" mount_crypto "$1" ;; crypto-down ) - [ $# -ne 1 ] && error_msg 10 "invalid number of parameters for 'crypto-down'" + test $# -ne 1 && error_msg 10 "invalid number of parameters for 'crypto-down'" is_device_allowed "$1" || error_msg 12 "invalid device: $1" umount_partition "$1" ;; @@ -349,7 +347,7 @@ case "$ACTION" in init_cryptobox >"$LOG_FILE" 2>&1 ;; list_container ) - [ $# -ne 1 ] && error_msg 10 "invalid number of parameters for 'list_container'" + test $# -ne 1 && error_msg 10 "invalid number of parameters for 'list_container'" case "$1" in config | unused | plaindata | crypto ) list_partitions_of_type "$1" @@ -362,13 +360,13 @@ case "$ACTION" in ;; get_device_name ) # Parameter: DEVICE - [ $# -ne 1 ] && error_msg 10 "invalid number of parameters for 'get_device_name'" + test $# -ne 1 && error_msg 10 "invalid number of parameters for 'get_device_name'" is_device_allowed "$1" || error_msg 12 "invalid device: $1" get_device_name "$1" ;; set_device_name ) # Parameter: DEVICE NAME - [ $# -ne 2 ] && error_msg 10 "invalid number of parameters for 'set_device_name'" + test $# -ne 2 && error_msg 10 "invalid number of parameters for 'set_device_name'" is_device_allowed "$1" || error_msg 12 "invalid device: $1" set_device_name "$1" "$2" ;; @@ -387,17 +385,17 @@ case "$ACTION" in true ;; is_mounted ) - [ $# -ne 1 ] && error_msg 10 "invalid number of parameters for 'is_mounted'" + test $# -ne 1 && error_msg 10 "invalid number of parameters for 'is_mounted'" is_device_allowed "$1" || error_msg 12 "invalid device: $1" is_mounted "$1" ;; is_encrypted ) - [ $# -ne 1 ] && error_msg 10 "invalid number of parameters for 'is_encrypted'" + test $# -ne 1 && error_msg 10 "invalid number of parameters for 'is_encrypted'" is_device_allowed "$1" || error_msg 12 "invalid device: $1" is_encrypted "$1" ;; is_plain ) - [ $# -ne 1 ] && error_msg 10 "invalid number of parameters for 'is_plain'" + test $# -ne 1 && error_msg 10 "invalid number of parameters for 'is_plain'" is_device_allowed "$1" || error_msg 12 "invalid device: $1" is_plain "$1" ;; @@ -408,15 +406,15 @@ case "$ACTION" in get_available_disks ;; set_config ) - [ $# -ne 2 ] && error_msg 7 "'set_config' requires two parameters" + test $# -ne 2 && error_msg 7 "'set_config' requires two parameters" config_set_value "$1" "$2" ;; get_config ) - [ $# -ne 1 ] && error_msg 6 "'get_config' requires exactly one parameter" + test $# -ne 1 && error_msg 6 "'get_config' requires exactly one parameter" config_get_value "$1" ;; get_capacity_info ) - [ $# -ne 1 ] && error_msg 6 "'get_capacity_info' requires exactly one parameter" + test $# -ne 1 && error_msg 6 "'get_capacity_info' requires exactly one parameter" is_device_allowed "$1" || error_msg 12 "invalid device: $1" is_mounted "$1" || error_msg 13 "the device is not mounted: $1" name=$(get_device_mnt_name "$1") diff --git a/bin/cbox-root-actions.sh b/bin/cbox-root-actions.sh index 600a2b9..9e25d7d 100755 --- a/bin/cbox-root-actions.sh +++ b/bin/cbox-root-actions.sh @@ -20,10 +20,10 @@ set -eu LIB_DIR=$(dirname "$0") LIB_DIR=$(cd "$LIB_DIR"; pwd) -[ "$(id -u)" -ne 0 ] && echo "$(basename $0) - only root may call this script" >&2 && exit 100 +test "$(id -u)" -ne 0 && echo "$(basename $0) - only root may call this script" >&2 && exit 100 # read the default setting file, if it exists -[ -e /etc/default/cryptobox ] && . /etc/default/cryptobox +test -e /etc/default/cryptobox && . /etc/default/cryptobox # set CONF_FILE to default value, if not configured in /etc/default/cryptobox CONF_FILE=${CONF_FILE:-/etc/cryptobox/cryptobox.conf} @@ -39,14 +39,14 @@ CONFIG_MARKER=cryptobox.marker ############ some useful functions ############### # check if the given device is part of the SCAN_DEVICE list -# every entry in SCAN_DEVICES is matched as "^/dev/${SCAN_DEVICE}[0-9]*$" against +# every entry in SCAN_DEVICES is matched as "^/dev/${SCAN_DEVICE}[^/]*$" against # the given device # other devices may not be touched function is_device_allowed() # parameter: device { for a in $SCAN_DEVICES - do [[ "$1" =~ "^/dev/${a}[0-9]*$" ]] && return 0 + do echo "$1" | grep -q "^/dev/${a}[^/]*$" && return 0 done return 1 } @@ -59,7 +59,7 @@ function get_device_uuid() { # check for luksUUID or ext2/3-uuid if is_luks_device "$1" then UUID=$("$CRYPTSETUP" luksUUID "$1") - else [ -x "$BLKID" ] && UUID=$("$BLKID" -s UUID -o value -c /dev/null -w /dev/null "$1" 2>/dev/null) + else test -x "$BLKID" && UUID=$("$BLKID" -s UUID -o value -c /dev/null -w /dev/null "$1" 2>/dev/null) fi if test -z "$UUID" then get_device_flat_name "$1" @@ -84,8 +84,7 @@ function get_device_mnt_name() { # every devmapper name should look like a UUID function is_uuid_valid() { local hex=[0-9a-f] - # TODO: this is very bash-specific - translate it to grep :) - [[ "$1" =~ "^$hex\{8\}-$hex\{4\}-$hex\{4\}-$hex\{4\}-$hex\{12\}$" ]] + echo "$1" | grep -q "^$hex\{8\}-$hex\{4\}-$hex\{4\}-$hex\{4\}-$hex\{12\}$" } @@ -120,12 +119,12 @@ function is_luks_device() ################ main #################### ACTION=unknown -[ $# -gt 0 ] && ACTION=$1 && shift +test $# -gt 0 && ACTION=$1 && shift case "$ACTION" in partition_disk ) - [ $# -ne 2 ] && error_msg 1 "wrong number of parameters" + test $# -ne 2 && error_msg 1 "wrong number of parameters" is_device_allowed "$1" || \ error_msg 3 "this device ($1) is not listed in SCAN_DEVICES (see $CONF_FILE)" partition_device "$1" "$2" || \ @@ -134,7 +133,7 @@ case "$ACTION" in mount ) # parameters: device # returns the relative name of the mointpoint for success - [ $# -ne 1 ] && error_msg 1 "wrong number of parameters" + test $# -ne 1 && error_msg 1 "wrong number of parameters" is_device_allowed "$1" || \ error_msg 3 "this device ($1) is not listed in SCAN_DEVICES (see $CONF_FILE)" mnt_name=$(get_device_mnt_name "$1") @@ -162,7 +161,7 @@ case "$ACTION" in ;; umount ) #parameter: device - [ $# -ne 1 ] && error_msg 1 "wrong number of parameters" + test $# -ne 1 && error_msg 1 "wrong number of parameters" is_device_allowed "$1" || \ error_msg 3 "this device ($1) is not listed in SCAN_DEVICES (see $CONF_FILE)" mnt_name=$(get_device_mnt_name "$1") @@ -184,9 +183,9 @@ case "$ACTION" in ;; create_crypto ) # parameter: device keyfile - [ $# -ne 2 ] && error_msg 1 "wrong number of parameters" + test $# -ne 2 && error_msg 1 "wrong number of parameters" keyfile=$2 - [ -e "$keyfile" ] || error_msg 2 "keyfile ($keyfile) not found" + test -e "$keyfile" || error_msg 2 "keyfile ($keyfile) not found" is_device_allowed "$1" || \ error_msg 3 "this device ($1) is not listed in SCAN_DEVICES (see $CONF_FILE)" # read the passphrase from stdin @@ -208,31 +207,31 @@ case "$ACTION" in error_msg 13 "failed to create the encrypted filesystem" "$CRYPTSETUP" --batch-mode luksClose "$name" || \ error_msg 14 "failed to close the encrypted mapped device" - ) /dev/null & + ) /dev/null 2>/dev/null & true ;; create_plain ) # parameter: device - [ $# -ne 1 ] && error_msg 1 "wrong number of parameters for 'create_plain'" + test $# -ne 1 && error_msg 1 "wrong number of parameters for 'create_plain'" is_device_allowed "$1" || \ error_msg 3 "this device ($1) is not listed in SCAN_DEVICES (see $CONF_FILE)" # complete in background ( "$MKFS_DATA" "$1" || \ error_msg 15 "failed to create the plaintext filesystem" - ) /dev/null & + ) /dev/null 2>/dev/null & true ;; get_device_mnt_name ) # parameter: device - [ $# -ne 1 ] && error_msg 1 "wrong number of parameters" + test $# -ne 1 && error_msg 1 "wrong number of parameters" is_device_allowed "$1" || \ error_msg 3 "this device ($1) is not listed in SCAN_DEVICES (see $CONF_FILE)" get_device_mnt_name "$1" ;; get_device_uuid ) # parameter: device - [ $# -ne 1 ] && error_msg 1 "wrong number of parameters" + test $# -ne 1 && error_msg 1 "wrong number of parameters" is_device_allowed "$1" || \ error_msg 3 "this device ($1) is not listed in SCAN_DEVICES (see $CONF_FILE)" get_device_uuid "$1" @@ -240,7 +239,7 @@ case "$ACTION" in is_config_partition ) # parameter: device # returns exitcode 0 if the device contains a configuration - [ $# -ne 1 ] && error_msg 1 "wrong number of parameters" + test $# -ne 1 && error_msg 1 "wrong number of parameters" is_device_allowed "$1" || \ error_msg 3 "this device ($1) is not listed in SCAN_DEVICES (see $CONF_FILE)" is_config=0 @@ -248,19 +247,19 @@ case "$ACTION" in mkdir -p "$tmp_dir" # error means "no config partition" if mount "$1" "$CONFIG_DIR" - then [ -e "$CONFIG_DIR/$CONFIG_MARKER" ] && is_config=1 + then test -e "$CONFIG_DIR/$CONFIG_MARKER" && is_config=1 umount "$CONFIG_DIR" || \ error_msg 14 "unable to unmount configation partition after probing" fi rmdir "$tmp_dir" || true # return 0 if $device is a config partition - [ "$is_config" -eq 1 ] && exit 0 + test "$is_config" -eq 1 && exit 0 exit 1 ;; is_crypto_partition ) # parameter: device # returns exitcode 0 if the device contains a luks header - [ $# -ne 1 ] && error_msg 1 "wrong number of parameters" + test $# -ne 1 && error_msg 1 "wrong number of parameters" is_device_allowed "$1" || \ error_msg 3 "this device ($1) is not listed in SCAN_DEVICES (see $CONF_FILE)" is_luks_device "$1" @@ -268,14 +267,14 @@ case "$ACTION" in is_plain_partition ) # parameter: device # returns exitcode 0 if the device contains a readable filesystem - [ $# -ne 1 ] && error_msg 1 "wrong number of parameters" + test $# -ne 1 && error_msg 1 "wrong number of parameters" is_device_allowed "$1" || \ error_msg 3 "this device ($1) is not listed in SCAN_DEVICES (see $CONF_FILE)" status=0 tmp_dir=/tmp/$(basename $0)-$$-mnt mkdir -p "$tmp_dir" - if mount -o ro "$1" "$tmp_dir" - then [ ! -e "$tmp_dir/$CONFIG_MARKER" ] && status=1 + if mount "$1" "$tmp_dir" >/dev/null 2>/dev/null + then test ! -e "$tmp_dir/$CONFIG_MARKER" && status=1 umount "$tmp_dir" fi rmdir "$tmp_dir" || true @@ -284,14 +283,14 @@ case "$ACTION" in ;; trash_device ) # parameter: device - [ $# -ne 1 ] && error_msg 1 "wrong number of parameters" + test $# -ne 1 && error_msg 1 "wrong number of parameters" is_device_allowed "$1" || \ error_msg 3 "this device ($1) is not listed in SCAN_DEVICES (see $CONF_FILE)" dd if=/dev/urandom of="$1" bs=512 count=1 2>/dev/null ;; diskinfo ) # parameter: device - [ $# -ne 1 ] && error_msg 1 "wrong number of parameters" + test $# -ne 1 && error_msg 1 "wrong number of parameters" is_device_allowed "$1" || \ error_msg 3 "this device ($1) is not listed in SCAN_DEVICES (see $CONF_FILE)" "$SFDISK" -L -q -l "$1" @@ -300,8 +299,8 @@ case "$ACTION" in # parameter: none ip= # TODO: can we avoid to hard-code the filename ($CONFIG_DIR/ip) here? - [ -e "$CONFIG_DIR/ip" ] && ip=$(<"$CONFIG_DIR/ip") - [ -n "$z" ] && ifconfig "$NET_IFACE" "$ip" + test -e "$CONFIG_DIR/ip" && ip=$(<"$CONFIG_DIR/ip") + test -n "$z" && ifconfig "$NET_IFACE" "$ip" ;; poweroff ) # TODO: check configuration setting before @@ -334,7 +333,7 @@ case "$ACTION" in echo ' reboot' echo ' help' echo - [ "$ACTION" == "help" ] && exit 0 + test "$ACTION" = "help" && exit 0 # return error for any unknown/unspecified action exit 1 ;; diff --git a/templates/show_volume.cs b/templates/show_volume.cs index 4e73072..61d7174 100644 --- a/templates/show_volume.cs +++ b/templates/show_volume.cs @@ -2,26 +2,29 @@

- - -

Mount container

- -

- - - - - - -

- - -

Unmount container

- -

- -

- + + + + +

Mount container

+ +

+ + + + + + +

+ + +

Unmount container

+ +

+ +

+ +