Compare commits

...

2 Commits

Author SHA1 Message Date
Fierelier 763b07f92f Add install message 2024-02-15 15:23:43 +01:00
Fierelier b694a6d7a6 Global lock + eject cmd + help update 2024-02-15 15:23:29 +01:00
11 changed files with 54 additions and 32 deletions

19
app/app
View File

@ -3,10 +3,15 @@ set -e
APP_CMD="$(realpath "$BASH_SOURCE")"
APP_DIR="$(dirname "$APP_CMD")"
source "$APP_DIR/env"
if [ -f "$APP_DIR/cmd/$1" ]; then
source "$APP_DIR/cmd/$1"
exit 0
else
echo "ERROR: Action \"$1\" not found, use: \"$0\" help"
exit 1
fi
echo "Acquiring lock ..." >&2
mkdir -p /run/$APP_NAME
exec 100>/run/$APP_NAME/lock
set +e
while true; do
if flock -e -n 100; then
break
fi
sleep 1
done
exec bash "$APP_DIR/cmd/main" "${@}"

6
app/cmd/eject Normal file
View File

@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -e
eval "$(bash "$APP_DIR/cmd/main" plist "$2")"
eject "$mm_path"
set +e
hdparm -Y "$mm_path"

View File

@ -1,24 +1,22 @@
#!/usr/bin/env bash
cat << EOF
Commands:
* mountman list
List known partitions for humans:
* 8G [] (/dev/sda, disk)
* 8G [label] (/dev/sda1, crypto_LUKS)
* 0M [] (/dev/sda2, part)
...
List known block devices.
* mountman plist
List known partitions, programmatically:
mm_path='/dev/sda1'; mm_label='label'; mm_size='8G'; mm_type='part'; mm_format='crypto_LUKS'; mm_parent='/dev/sda'; mm_mountpath=''
...
(note: escape ' in strings with ")
* mountman plist [/path]
List known block device(s), with technical information, parseable with bash.
* mountman mount </path>
Mount a partition
* mountman mount
Mount block device, returns the mountpoint's path.
* mountman umount </path>
Unmount a partition
Unmount block device.
* mountman eject </path>
Eject the device the partition belongs to"
Eject block device, and shut it off, if possible.
Legend:
* <> - Required argument
* [] - Optional argument
EOF

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash
set +e
"$APP_CMD" plist | while read mm_cmd; do
bash "$APP_DIR/cmd/main" plist | while read mm_cmd; do
eval "$mm_cmd"
if ! [ "$mm_format" = "" ]; then
echo "[$mm_label] $mm_size - $mm_path ($mm_type/$mm_format)"

12
app/cmd/main Normal file
View File

@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -e
APP_CMD="$(realpath "$(dirname "$BASH_SOURCE")/../app")"
APP_DIR="$(dirname "$APP_CMD")"
source "$APP_DIR/env"
if [ -f "$APP_DIR/cmd/$1" ]; then
source "$APP_DIR/cmd/$1"
exit 0
else
echo "ERROR: Action \"$1\" not found, use: \"$0\" help" >&2
exit 1
fi

View File

@ -1,15 +1,15 @@
#!/usr/bin/env bash
set -e
eval "$("$APP_CMD" plist "$2")"
eval "$(bash "$APP_DIR/cmd/main" plist "$2")"
if [ "$mm_format" = "crypto_LUKS" ]; then
mm_target="$("$APP_CMD" name "$mm_path")"
mm_target="$(bash "$APP_DIR/cmd/main" name "$mm_path")"
cryptsetup luksOpen "$mm_path" "$mm_target"
echo "/dev/mapper/$mm_target"
exit 0
fi
mm_target="$("$APP_CMD" path "$mm_path")"
mm_target="$(bash "$APP_DIR/cmd/main" path "$mm_path")"
mkdir -p "$mm_target"
mount "$mm_path" "$mm_target"
echo "$mm_target"

View File

@ -1,9 +1,9 @@
#!/usr/bin/env bash
set -e
eval "$("$APP_CMD" plist "$2")"
eval "$(bash "$APP_DIR/cmd/main" plist "$2")"
mm_label="${mm_label//-/_}"
mm_label="${mm_label//\//_}"
mm_uuid="$("$APP_CMD" hash "${mm_uuid}_${mm_partuuid}")"
mm_uuid="$(bash "$APP_DIR/cmd/main" hash "${mm_uuid}_${mm_partuuid}")"
mm_uuid="${mm_uuid//-/_}"
mm_uuid="${mm_uuid//\//_}"
echo "_$mm_label-$mm_uuid"

View File

@ -1,4 +1,4 @@
#!/usr/bin/env bash
set -e
mm_name="$("$APP_CMD" name "$2")"
mm_name="$(bash "$APP_DIR/cmd/main" name "$2")"
echo "/run/media/$mm_name"

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash
set +e
function output_line() {
mm_path="$("$APP_CMD" standardize "$1")"
mm_path="$(bash "$APP_DIR/cmd/main" standardize "$1")"
mm_label="$(blkid -o value -s LABEL "$mm_path")"
mm_size="$(lsblk -ndpo SIZE "$mm_path")"
mm_size="${mm_size// /}"

View File

@ -1,14 +1,14 @@
#!/usr/bin/env bash
set -e
eval "$("$APP_CMD" plist "$2")"
eval "$(bash "$APP_DIR/cmd/main" plist "$2")"
if [ "$mm_format" = "crypto_LUKS" ]; then
mm_target="$("$APP_CMD" name "$mm_path")"
mm_target="$(bash "$APP_DIR/cmd/main" name "$mm_path")"
cryptsetup luksClose "$mm_target"
exit 0
fi
mm_target="$("$APP_CMD" path "$mm_path")"
mm_target="$(bash "$APP_DIR/cmd/main" path "$mm_path")"
set +e
umount "$mm_target"
set -e

View File

@ -18,6 +18,7 @@ if [ "$APP_UNINSTALL" = "1" ]; then
fi
fi
echo "Installing $APP_NAME ..."
mkdir -p "$APP_INSTALL_PATH"
cp -r "$APP_PATH/app/." "$APP_INSTALL_PATH"
ln -s "$APP_INSTALL_PATH/app" "/usr/local/bin/$APP_NAME"