diff options
author | simona | 2018-11-25 17:05:22 +0100 |
---|---|---|
committer | simona | 2018-11-25 17:05:22 +0100 |
commit | b583ae52f4aa6be344ff073d0e19675b24be69d5 (patch) | |
tree | b69eff7dd5c88da9d703f836eba7e91201efc14c | |
parent | 45a87ebf459dc1839988e49b60a46f91a5919fd5 (diff) | |
download | aur-b583ae52f4aa6be344ff073d0e19675b24be69d5.tar.gz |
same scripts but different packaging
-rw-r--r-- | .SRCINFO | 16 | ||||
-rwxr-xr-x | PKGBUILD | 29 | ||||
-rwxr-xr-x | boot-kernel-list | 13 | ||||
-rwxr-xr-x | image-mount | 279 | ||||
-rwxr-xr-x | image-umount | 203 | ||||
-rwxr-xr-x | ioscheduler-list | 13 | ||||
-rwxr-xr-x | pendrive-detect | 47 | ||||
-rwxr-xr-x | simona-scripts | 12 |
8 files changed, 600 insertions, 12 deletions
@@ -1,7 +1,7 @@ pkgbase = simonascripts pkgdesc = Bash unique command for mount image files (iso, vms, crypto, squashfs), detect pendrive device name, list all kernels, list all i/o schedulers. pkgver = 0.0.4 - pkgrel = 1 + pkgrel = 2 arch = any license = GPL3 depends = bash @@ -9,8 +9,18 @@ pkgbase = simonascripts optdepends = fuseiso: another way to mount iso image files optdepends = cryptsetup: for mount crypto image files optdepends = squashfs-tools: for squashfs image files - source = simonascripts-0.0.4.tar.gz - md5sums = 23906d3498e65f43db0588fad50d880f + source = boot-kernel-list + source = image-mount + source = image-umount + source = ioscheduler-list + source = pendrive-detect + source = simona-scripts + md5sums = 3f5599c3588f01b625aa9feb0a0e8b99 + md5sums = b36b71c82c7a8baf4eff72af67ed50be + md5sums = a874f35365c7c302c3db3cb8ba436a5b + md5sums = c58f5737bb41c8af2bff7dd24a3d2723 + md5sums = 6379f2d72a7f197961f7d10bf428d667 + md5sums = ef7511e134eb386162c3c0646d6c590a pkgname = simonascripts @@ -1,7 +1,7 @@ # Maintainer: Simona <simona.pisano[at]gmail[dot]com> pkgname=simonascripts pkgver=0.0.4 -pkgrel=1 +pkgrel=2 pkgdesc="Bash unique command for mount image files (iso, vms, crypto, squashfs), detect pendrive device name, list all kernels, list all i/o schedulers." arch=('any') @@ -13,17 +13,28 @@ optdepends=('qemu: for mount qemu image files' 'cryptsetup: for mount crypto image files' 'squashfs-tools: for squashfs image files' ) -source=($pkgname-$pkgver.tar.gz) -md5sums=('23906d3498e65f43db0588fad50d880f') +source=( "boot-kernel-list" + "image-mount" + "image-umount" + "ioscheduler-list" + "pendrive-detect" + "simona-scripts" ) + +md5sums=('3f5599c3588f01b625aa9feb0a0e8b99' + 'b36b71c82c7a8baf4eff72af67ed50be' + 'a874f35365c7c302c3db3cb8ba436a5b' + 'c58f5737bb41c8af2bff7dd24a3d2723' + '6379f2d72a7f197961f7d10bf428d667' + 'ef7511e134eb386162c3c0646d6c590a') package() { cd "$srcdir" - install -Dm 755 "$srcdir/usr/bin/simona-scripts" "$pkgdir/usr/bin/simona-scripts" - install -Dm 755 "$srcdir/usr/bin/pendrive-detect" "$pkgdir/usr/bin/pendrive-detect" - install -Dm 755 "$srcdir/usr/bin/image-mount" "$pkgdir/usr/bin/image-mount" - install -Dm 755 "$srcdir/usr/bin/image-umount" "$pkgdir/usr/bin/image-umount" - install -Dm 755 "$srcdir/usr/bin/boot-kernel-list" "$pkgdir/usr/bin/boot-kernel-list" - install -Dm 755 "$srcdir/usr/bin/ioscheduler-list" "$pkgdir/usr/bin/ioscheduler-list" + install -Dm 755 "$srcdir/simona-scripts" "$pkgdir/usr/bin/simona-scripts" + install -Dm 755 "$srcdir/pendrive-detect" "$pkgdir/usr/bin/pendrive-detect" + install -Dm 755 "$srcdir/image-mount" "$pkgdir/usr/bin/image-mount" + install -Dm 755 "$srcdir/image-umount" "$pkgdir/usr/bin/image-umount" + install -Dm 755 "$srcdir/boot-kernel-list" "$pkgdir/usr/bin/boot-kernel-list" + install -Dm 755 "$srcdir/ioscheduler-list" "$pkgdir/usr/bin/ioscheduler-list" } diff --git a/boot-kernel-list b/boot-kernel-list new file mode 100755 index 000000000000..a86fdb7d6807 --- /dev/null +++ b/boot-kernel-list @@ -0,0 +1,13 @@ +#!/bin/bash +# Simona Pisano - 2018-11-18 - +# simona-scripts +# Libertamente utilizzabile sotto GPL v3 + + #alias sget-kernel-list=' + search=`uname -r`; printf "Kernels /boot :\n"; + for file in /boot/vmlinuz* ; do + info=`file $file`; file="${file:6:99}"; ver=${info#*version}; ver=${ver%\(*}; [[ $ver =~ $search ]] && flag="<-used" || flag=""; + printf "%-28s %s %24s %s\n" "$file" "->" "$ver" "$flag"; + done; + #' + diff --git a/image-mount b/image-mount new file mode 100755 index 000000000000..a3ea6ea3c25c --- /dev/null +++ b/image-mount @@ -0,0 +1,279 @@ +#!/bin/bash +# Simona Pisano - 2018-11-18 - +# simona-scripts +# Libertamente utilizzabile sotto GPL v3 + + #srun-mount-img() { + + #to-do add sqash images + #to-do add input parameters + #echo -n "Continue? (Y/N): "; read confirm; [[ ! $confirm == [Yy]* ]] && echo "no" #exit 1 + #echo -n "Continue? (Y/N): "; read ok; [[ ! $ok =~ ^(yes|y|YES|y|s|S|si|SI|sì)$ ]] && echo "no" #exit 1 + +#color Foreground Background +#black 30 40 +#red 31 41 +#green 32 42 +#yellow 33 43 +#blue 34 44 +#magenta 35 45 +#cyan 36 46 +#white 37 47 +# +#black='\E[30;47m' +#red='\E[31;47m' +#green='\E[32;47m' +#yellow='\E[33;47m' +#blue='\E[34;47m' +#magenta='\E[35;47m' +#cyan='\E[36;47m' +#white='\E[37;47m' +#"\e[1;39;41m" "\e[0m " +#echo -e + +[[ $1 == "" ]] && exit 0 + +EchoReset="\e[0m" +echo -e -n "$EchoReset" +OK="\E[32;40m[OK]${EchoReset}" +WARN="\E[33;40m[OK]${EchoReset}" +ERR="\E[31;40m[OK]${EchoReset}" +#echo -e "$OK $WARN $ERR" + +# ------------------------------------------------------------------------------------------------------------------------ +# INPUT PARAMETER -------------------------------------------------------------------------------------------------------- +# ------------------------------------------------------------------------------------------------------------------------ + +allow_formats="raw qcow2 vdi blkdebug blklogwrites blkreplay blkverify bochs cloop copy-on-read dmg file ftp ftps gluster host_cdrom host_device http https iscsi iser luks nbd nfs null-aio null-co nvme parallels qcow qed quorum rbd replication sheepdog ssh throttle vhdx vmdk vpc vvfat" +allow_formats_iso="iso nrg bin img mdf" +allow_formats_crypto="tcrypt plain luks luks1 luks2 loopaes" + +if [[ $1 == "-h" || $1 == "--help" ]] ; then + echo "Sintax 1: image-mount [--help|-h]" + echo "Sintax 2: image-mount [path/]file-name.ext] [format | part#] [mount-path | part#] [--force-iso-stdmount]" + echo " --force-iso-stdmount -> forse in iso sudo mount 'mount -o loop' instead 'fuseiso'" + echo "Warning 1: part# in in format 0-9 with one integer value" + echo "Warning 2: format must be explicily specified if file extension do not say itself the correct format." + echo "Warning 3: all parameters are case sensitive." + echo "Default: image-mount image.raw raw 0 \${HOME}/mount/image" + echo "Minimal: image-mount file.ext" + echo "Typical: image-mount file.ext 2" + echo "Allowed formats: ${allow_formats} ${allow_formats_iso} ${allow_formats_crypto} sqhashfs" + exit 0 +fi + +# DEFAULTS ------------------------------------------------------------------------------------------------------------- +full_path_image="image.raw" +n_part=0 +#n_part=2 +mount_where="$HOME/mount/image" +format="" #something required (no default allowed) + +# PARS ----------------------------------------------------------------------------------------------------------------- +#parameter $1: name file used as image +par=$1; [[ $1 != "" && ${par:0:1} != "-" ]] && full_path_image=$1 +image="${full_path_image##*/}" # estract substring: take only final part after last '/' char +[[ ! -f "$full_path_image" ]] && { echo -e "$ERR File image '$full_path_image' not found!! Exit."; exit 1; } + +ext="${image##*.}" # extract substring: take only final part after last '.' char +[[ $ext != "" ]] && format=$ext + +#parameter $2: format or partition number +case $2 in + [0-9]* ) n_part=$2 ;; + [a-z]* ) format=$2 ;; +esac + +#parameter $3: mount path or partition number +case $3 in + [0-9]* ) n_part=$3 ;; + * ) par=$3; [[ $3 != "" && ${par:0:1} != "-" ]] && format=$3 ;; +esac + +[[ $format == "" ]] && { echo "Parameter missing. Please insert format as second command parameter."; exit 1; } +if [[ ! $allow_formats =~ $format && + ! $allow_formats_iso =~ $format && + ! $allow_formats_crypto =~ $format && + ! "squashfs" =~ $format ]] ; then + echo -e "$ERR Format $format unknown or not supported. Sorry. Exit." + exit 1 +fi + +#parameter 4: mount path +par=$4; [[ $4 != "" && ${par:0:1} != "-" ]] && mount_where=$4 + +[[ ! -d $mount_where ]] && { echo "[TO-DO] Please create $mount_where with 'mkdir -p $mount_where'. Exit."; exit 1; } + +#display default +#[[ $full_path_image == "image.raw" ]] && echo "Default: 'image.raw' image file" +[[ $allow_formats =~ $format && $n_part == 0 ]] && echo "Default: partition number 0" +[[ $mount_where == "$HOME/mount/image" ]] && echo "Default: '$HOME/mount/image' dir where mount image" + +[[ -d "$mount_where/$image" ]] && { echo -e "$ERR $image found. umount/rm -r \"$mount_where/$image\". Exit."; exit 1; } + +forceIsoStdMount=false #default par +while [ $# -ne 0 ] ; do + arg="$1" + case "$arg" in + --force-iso-stdmount) forceIsoStdMount=true ;; + *) ;; + esac + shift +done + +# ------------------------------------------------------------------------------------------------------------------------ +# WORK ------------------------------------------------------------------------------------------------------------------- +# ------------------------------------------------------------------------------------------------------------------------ + +mkdir -p "$mount_where/$image" +[[ $? -ne 0 ]] && { echo -e "$ERR Fail creation dir $mount_where/$image! Exit."; exit 1; } + +cd "$mount_where/$image" +if [[ $? -ne 0 ]] ; then + echo -e "$ERR Fail 'cd \"$mount_where/$image\"' cmd! Exit." + rmdir "$mount_where/$image" #undo + [ $? -ne 0 ] && echo -e "$WARN Fail undo removing dir 'rmdir $mount_where/$image' cmd!" + exit 1 +fi +echo "[OK] prepare success." + +# vm images ----------------------------------------------------------------------------------------------------------- +if [[ $allow_formats =~ $format ]] ; then + + [[ ! -r /bin/qemu-nbd ]] && { echo -e "$ERR Missing qemu-nbd cmd (qemu pkg?)! Exit"; exit 1; } + + sudo modprobe nbd max_part=63 + [[ $? -ne 0 ]] && { echo -e "$ERR Fail 'modprobe nbd max_part=63' cmd! Exit."; exit 1; } + echo "[OK] nbd module prepared... success." + + sudo qemu-nbd -c /dev/nbd0 --format=$format "$full_path_image" + [[ $? -ne 0 ]] && { echo -e "$ERR Fail 'qemu-nbd -c /dev/nbd0 --format=$format \"$full_path_image\"' cmd! Exit."; exit 1; } + echo -e "$OK qemu nbd started... success." + + if [[ n_part -eq 0 ]] ; then + #ls /dev/nbd0p? + #echo -n "* "; for dev_part in /dev/nbd0p* ; do echo $dev_part; done + #echo -n "? "; for dev_part in /dev/nbd0p? ; do echo $dev_part; done + #echo -n "[0-9] "; for dev_part in /dev/nbd0p[0-9] ; do echo $dev_part; done + for dev_part in /dev/nbd0p[0-9] ; do + part=${dev_part:10:1} # estrae substring: dopo n-esimo carattere (0 based) per N caratteri + mkdir -p "$mount_where/$image/$part" + if [ $? -ne 0 ]; then + echo -e "$WARN Fail creation dir $mount_where/$image/$part and mount part $part..." + els + sudo mount $dev_part "$mount_where/$image/$part" + if [ $? -ne 0 ]; then + sudo qemu-nbd -d /dev/nbd0 >/dev/null #undo + [[ $? -ne 0 ]] && echo -e "$WARN Fail undo 'qemu-nbd -d /dev/nbd0' cmd!" || echo -e "$OK qemu nbd stopped... success." + #rmdir -r "$mount_where/$image" #undo + #[ $? -ne 0 ] && echo "Can't execute command 'rmdir $mount_where/$image'!" + echo -e "$ERR Fail'mount $dev_part $mount_where/\"$image/$part\"' cmd! Exit." + exit 1 + fi + fi + echo -e "$OK Mount $dev_part ... [part# $part] on $mount_where/$image/$part success." + done + else + sudo mount /dev/nbd0p$n_part "$mount_where/$image" + if [ $? -ne 0 ]; then + sudo qemu-nbd -d /dev/nbd0 >/dev/null #undo + [[ $? -ne 0 ]] && echo -e "$WARN Fail undo 'qemu-nbd -d /dev/nbd0' cmd!" || echo -e "$OK qemu nbd stopped... success." + rmdir "$mount_where/$image" #undo + [ $? -ne 0 ] && echo -e "$WARN Fail undo removing dir 'rmdir $mount_where/$image' cmd!" + echo -e "$ERR Part num $n_part really exist? Fail mount /dev/nbd0p$n_part on $mount_where/\"$image\"'! Exit." + exit 1 + fi + echo -e "$OK Mount /dev/nbd0p$n_part ... [partition $n_part] on $mount_where/$image success." + fi + +# iso images ---------------------------------------------------------------------------------------------------------- +elif [[ $allow_formats_iso =~ $format ]] ; then + iso_mount_type="" + if [[ -r /bin/fuseiso && "$forceIsoStdMount" != true ]] ; then + + fuseiso "$full_path_image" "$mount_where/$image" + if [ $? -ne 0 ]; then + rmdir "$mount_where/$image" #undo + [ $? -ne 0 ] && echo -e "$WARN Fail undo removing dir 'rmdir $mount_where/$image' cmd!" + echo -e "$ERR Fail'fuseiso "$full_path_image" /mnt' cmd! Exit." + exit 1 + fi + echo -e "$OK Mount (fuseiso) $mount_where/$image success." + iso_mount_type="fuseiso" + else + + sudo mount -o loop "$full_path_image" "$mount_where/$image" + if [ $? -ne 0 ]; then + rmdir "$mount_where/$image" #undo + [ $? -ne 0 ] && echo -e "$WARN Fail undo removing dir 'rmdir $mount_where/$image' cmd!" + echo -e "$ERR Fail 'mount -o loop \"$full_path_image\" \"$mount_where/$image\"' cmd! Exit." + exit 1 + fi + + echo -e "$OK Mount (sudo mount loop) $mount_where/$image success." + iso_mount_type="mount-loop" + + fi + +# crypto images ------------------------------------------------------------------------------------------------------- +elif [[ $allow_formats_crypto =~ $format ]] ; then + + [[ ! -r /bin/cryptsetup ]] && { echo -e "$ERR Missing cryptsetup cmd (cryptsetup pkg?)! Exit"; exit 1; } + + sudo cryptsetup open --type $format "$full_path_image" crypt-disk + if [ $? -ne 0 ]; then + rmdir "$mount_where/$image" #undo + [ $? -ne 0 ] && echo -e "$WARN Fail removing dir 'rmdir $mount_where/$image' cmd!" + echo -e "$ERR Fail 'cryptsetup open --type $format \"$full_path_image\" crypt-disk' cmd! Exit." + exit 1 + fi + sudo mount -o uid=1000 /dev/mapper/crypt-disk "$mount_where/$image" + if [ $? -ne 0 ]; then + sudo cryptsetup close crypt-disk #undo + [ $? -ne 0 ] && echo -e "$WARN Fail 'cryptsetup close crypt-disk' cmd!" + rmdir "$mount_where/$image" #undo + [ $? -ne 0 ] && echo -e "$WARN Fail undo removing dir 'rmdir $mount_where/$image' cmd!" + echo -e "$ERR Fail 'mount -o uid=1000 /dev/mapper/crypt-disk \"$mount_where/$image\"' cmd! Exit." + exit 1 + fi + + echo -e "$OK Mount 'pwd-crypt..." + +# sqhash images ------------------------------------------------------------------------------------------------------- +elif [[ "squashfs" =~ $format ]] ; then + [[ ! -r /bin/mksquash ]] && { echo -e "$ERR Missing mksqhash cmd (squash-tool pkg?)! Exit"; exit 1; } + + cp "$full_path_image" "$mount_where/$image/." + if [[ $? -ne 0 ]] ; then + echo -e "$ERR Fail copy squashfs image! Exit." + rmdir "$mount_where/$image" #undo + [ $? -ne 0 ] && echo -e "$WARN Fail undo removing dir 'rmdir $mount_where/$image' cmd!" + exit 1 + fi + + #sudo mount root.sqsh mnt -t squashfs -o loop #ok, but read only, because squash file cannot be modified + unsquashfs "$full_path_image" + if [[ $? -ne 0 ]] ; then + echo -e "$ERR Fail unsquash cmd! Exit." + rmdir "$mount_where/$image" #undo + [ $? -ne 0 ] && echo -e "$WARN Fail undo removing dir 'rmdir $mount_where/$image' cmd!" + exit 1 + else + echo -e "$OK unsquash success." + fi + + rm "$mount_where/$image/$image" #erase copy of sqhash filesystem image file (after decompressed) + [ $? -ne 0 ] && echo -e "$WARN Fail removing image file dupe '$mount_where/$image/$image'!" + +fi + +start_evid="\e[1;39;41m" +stop_evid="\e[0m" +exit_string="All done. [MEMO] Dont' forget to use ${start_evid}srun-umount-img \"${image}\"" +[[ $format != $ext ]] && exit_string="${exit_string} ${format}" +[[ $iso_mount_type == "mount-loop" && "$forceIsoStdMount" == true ]] && exit_string="${exit_string} --force-iso-stdmount" +exit_string="${exit_string}${stop_evid} when finished." +echo -e "$exit_string" +exit 0 + + diff --git a/image-umount b/image-umount new file mode 100755 index 000000000000..88b6195d1f43 --- /dev/null +++ b/image-umount @@ -0,0 +1,203 @@ +#!/bin/bash +# Simona Pisano - 2018-11-18 +# simona-scripts +# Libertamente utilizzabile sotto GPL v3 +#srun-umount-img() { + +EchoReset="\e[0m" +echo -e -n "$EchoReset" +OK="\E[32;40m[OK]${EchoReset}" +WARN="\E[33;40m[OK]${EchoReset}" +ERR="\E[31;40m[OK]${EchoReset}" +#echo -e "$OK $WARN $ERR" + +[[ $1 == "" ]] && exit 0 + +if [[ $1 == "-h" || $1 == "--help" ]] ; then + echo "Sintax 1: image-umount [--help|-h]" + echo "Sintax 2: image-umount reset [path] (try)" + echo "Sintax 3: image-umount image.ext [format] [mount-path] [--force-iso-stdmount]" + echo " --force-iso-stdmount -> force in iso mount 'mount -o loop' instead 'fuseiso'" + echo "Warning: format must be explicily specified if file extension do not say itself the correct format." + echo "Warning: all parameters are case sensitive." + echo "Default: image-umount image.raw raw 0 \$HOME/mount/image" + echo "Minimal: image-umount file.ext" + echo "Typical: image-umount file.ext 2" + echo "Allowed formats: $allow_formats $allow_formats_iso $allow_formats_crypto squashfs" + exit 0 +fi + +# ------------------------------------------------------------------------------------------------------------------------ +# RESET ------------------------------------------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------------------------------------------------ + +if [[ $1 == "reset" ]] ; then + mount_where="$HOME/mount/image" #default + [[ $2 != "" ]] && mount_where=$2 + cd "$mount_where" + [[ $? -ne 0 ]] && echo -e "$WARN Fail 'cd \"$mount_where\"' cmd! Reset so don't Exit." + if [[ -r /bin/qemu-nbd ]] ; then + sudo qemu-nbd -d /dev/nbd0 >/dev/null + [[ $? -ne 0 ]] && echo -e "$WARN Fail undo 'qemu-nbd -d /dev/nbd0' cmd!" || echo -e "$OK qemu nbd stopped... success." + fi + if [[ -r /bin/fuseiso ]] ; then + for dir in "$mount_where" ; do + fusermount -u "$dir" + [[ $? -ne 0 ]] && echo -e "$WARN Fail undo 'fusemount -u \"$dir\"' cmd!" || echo -e "$OK fusemount success." + done + fi + if [[ -r /bin/cryptsetup ]] ; then + sudo cryptsetup close crypt-disk + [[ $? -ne 0 ]] && echo -e "$WARN Fail 'cryptsetup close crypt-disk' cmd!" || echo -e "$OK 'cryptsetup close crypt-disk' success." + fi + #if [[ -r /bin/mksquash ]] ; then + #TO-DO + #fi + + for dir in "$mount_where" ; do + sudo umount "$dir" + [[ $? -ne 0 ]] && echo -e "$WARN Fail umount \"$dir\" !" || echo -e "$OK umount ok" + done + sudo umount "$mount_where" + [[ $? -ne 0 ]] && echo -e "$WARN Fail umount \"$mount_where\"' ! Reset so don't Exit." || echo -e "$OK umount success." + exit 0 + echo "All done." +fi + +# ------------------------------------------------------------------------------------------------------------------------ +# INPUT PARAMETER -------------------------------------------------------------------------------------------------------- +# ------------------------------------------------------------------------------------------------------------------------ + +allow_formats="raw qcow2 vdi blkdebug blklogwrites blkreplay blkverify bochs cloop copy-on-read dmg file ftp ftps gluster host_cdrom host_device http https iscsi iser luks nbd nfs null-aio null-co nvme parallels qcow qed quorum rbd replication sheepdog ssh throttle vhdx vmdk vpc vvfat" +allow_formats_iso="iso nrg bin img mdf" +allow_formats_crypto="tcrypt plain luks luks1 luks2 loopaes" + +#þarameter $1 +full_path_image="image.raw" #default +par=$1 +if [[ $1 != "" && ${par:0:1} != "-" ]] ; then + full_path_image=$1 +else + echo "Default: 'image.raw' image file" +fi +image="${full_path_image##*/}" # estract substring: take only final string after last / +ext="${image##*.}" #estract sbustring: take only final string aster last . + +#þarameter $2 +format="" #no default +par=$2 +if [[ $2 != "" && ${par:0:1} != "-" ]] ; then + format=$2 +else + [[ $ext != "" ]] && format=$ext +fi + +[[ $format == "" ]] && { echo "Parameter missing. Please insert format as second command parameter."; exit 1; } + +#þarameter $3 +mount_where="$HOME/mount/image" #default +[[ $3 != "" ]] && mount_where=$3 + +[[ ! -d "$mount_where/$image" ]] && { echo -e "$ERR Directory $mount_where/$image do not exist!! Exit."; exit 1; } + +forceIsoStdMount=false #default par +while [ $# -ne 0 ] ; do + arg="$1" + case "$arg" in + --force-iso-stdmount) forceIsoStdMount=true ;; + *) ;; + esac + shift +done + +# ------------------------------------------------------------------------------------------------------------------------ +# WORK ------------------------------------------------------------------------------------------------------------------- +# ------------------------------------------------------------------------------------------------------------------------ + +#before exit for mounted directory if inside +if [[ $PWD == "$mount_where/$image" ]] ; then + cd "$mount_where" + [[ $? -ne 0 ]] && { echo -e "$ERR Fail 'cd \"$mount_where\"' cmd! Exit."; exit 1; } +fi + +# vm images ----------------------------------------------------------------------------------------------------------- +if [[ $allow_formats =~ $format ]] ; then + + [[ ! -r /bin/qemu-nbd ]] && { echo -e "$ERR Missing qemu-nbd cmd (qemu pkg?)! Exit"; exit 1; } + + sudo umount "$mount_where/$image" + [[ ! -d "$mount_where/$image" ]] && echo -e "$OK umount $mount_where/$image done." || echo -e "$WARN Fail umount $mount_where/$image!!" + + sudo qemu-nbd -d /dev/nbd0 >/dev/null + [[ $? -ne 0 ]] && { echo -e "$ERR Fail 'qemu-nbd -d /dev/nbd0' cmd! Exit."; exit 1; } || echo -e "$OK qemu nbd stopped... success." + +# iso images ---------------------------------------------------------------------------------------------------------- +elif [[ $allow_formats_iso =~ $format ]] ; then + + if [[ -r /bin/fuseiso && "$forceIsoStdMount" != true ]] ; then + + fusermount -u "$mount_where/$image" + [[ $? -ne 0 ]] && { echo -e "$ERR Fail 'fusemount -u \"$mount_where/$image\"' cmd! Exit."; exit 1; } + echo-e "$OK umount (fusermount -u) $mount_where/$image success." + else + + sudo umount "$mount_where/$image" + [[ $? -ne 0 ]] && { echo -e "$ERR Fail 'umount \"$mount_where/$image\"' cmd! Exit."; exit 1; } + echo -e "$OK umount (sudo umount loop) $mount_where/$image success." + + fi + +# crypto images ------------------------------------------------------------------------------------------------------- +elif [[ $allow_formats_crypto =~ $format ]] ; then + + [[ ! -r /bin/cryptsetup ]] && { echo -e "$ERR Missing cryptsetup cmd (cryptsetup pkg?)! Exit."; exit 1; } + + sudo umount "$mount_where/$image" + [[ $? -ne 0 ]] && { echo -e "$ERR Fail 'umount \"$mount_where/$image\"' cmd! Exit."; exit 1; } + + sudo cryptsetup close crypt-disk + [[ $? -ne 0 ]] && { echo -e "$ERR Fail 'cryptsetup close crypt-disk' cmd! Exit."; exit 1; } + echo -e "$OK Umount \"$mount_where/$image\"..." + +# sqhash images ------------------------------------------------------------------------------------------------------- +elif [[ "squashfs" =~ $format ]] ; then + [[ ! -r /bin/mksquash ]] && { echo -e "$ERR Missing mksquash cmd (squash-tool pkg?)! Exit"; exit 1; } + + cd "$mount_where/$image" + [[ $? -ne 0 ]] && { echo -e "$ERR Fail 'cd $mount_where/$image' cmd!! Exit."; exit 1; } + + sudo mksquash * $image + [[ $? -ne 0 ]] && { echo -e "$ERR Fail 'mksquash * $image' cmd!! Exit."; exit 1; } || echo -e "$OK mksquash success." + + cp "$mount_where/$image/$image" "$full_path_image" + if [[ $? -ne 0 ]] ; then + echo -e "$WARN Fail copy update squashfs over original image! Check file '$mount_where/$image/$image' and remember to do 'rm -r $mount_where/$image'." + exit 1 + else + echo -e "$OK Created new updated squash image file sucessfully." + fi + + rm "$mount_where/$image/$image" #erase copy of sqhash filesystem image file + [ $? -ne 0 ] && echo -e "$WARN Fail removing image file dupe '$mount_where/$image/$image'!" + +else + [[ $format == "" ]] && detail="absent" || detail="unknown" + echo -e "$ERR Supplied format $format ${detail}. Exit." + exit 1 +fi + +for dir in $mount_where/$image/[0-9] ; do [[ -d "$dir" ]] && rmdir "$dir"; done +rmdir "$mount_where/$image" +if [[ $? -ne 0 ]] ; then + echo -e "$ERR Fail 'rmdir $mount_where/$image' cmd! Exit." + sudo rm -r "$mount_where/$image" + [[ $? -ne 0 ]] && echo -e "$WARN sudo rm -r $mount_where/$image fail!" || echo -e "$OK Sudo removed dir '$mount_where/$image' success." + exit 1 +else + echo -e "$OK Removed dir '$mount_where/$image' success." +fi + +echo "All done." +exit 0 + + diff --git a/ioscheduler-list b/ioscheduler-list new file mode 100755 index 000000000000..002aab712408 --- /dev/null +++ b/ioscheduler-list @@ -0,0 +1,13 @@ +#!/bin/bash +# Simona Pisano - 2018-11-18 +# simona-scripts +# Libertamente utilizzabile sotto GPL v3 + + #alias sget-io-sched-all-device=' + echo -e -n "I/O sched: "; + for device in /sys/block/nvme*/queue/scheduler ; do echo -e -n "nvme${device:15:3}>\e[1;39;41m" ` cat /sys/block/nvme${device:15:4}/queue/scheduler | cut -d "[" -f2 | cut -d "]" -f1 ` "\e[0m " ; done; + for device in /sys/block/sd*/queue/scheduler ; do echo -e -n "sd${device:13:1}>\e[1;39;41m" `cat /sys/block/sd${device:13:1}/queue/scheduler | cut -d "[" -f2 | cut -d "]" -f1` "\e[0m "; done; + echo "" + #' + + diff --git a/pendrive-detect b/pendrive-detect new file mode 100755 index 000000000000..c5b0c132b328 --- /dev/null +++ b/pendrive-detect @@ -0,0 +1,47 @@ +#!/bin/bash +# Simona Pisano - 2018-11-18 +# simona-scripts +# Libertamente utilizzabile sotto GPL v3 + + #sget-pendrive() { + n_found=0 + #TO-DO + #for short_dev in `lsblk -ndlo NAME` ; do + # drive="/dev/$short_dev" + # #if [[ -b $drive ]] ; then + # #short_dev="${drive##*/}" # estract substring: take only final part after last '/' char + for drive in /dev/sd?* /dev/nvme* ; do + if [[ -b $drive ]] ; then + + letter=${drive:7:1} + short_dev="${drive##*/}" # estract substring: take only final part after last '/' char + + #base search + udev=`udevadm info -q path -n $drive` + udev=`udevadm info -a -p $udev ` + + search=`echo KERNEL==\"$short_dev\"` + udev_info=`echo "$udev" | grep $search | tr -d ' ' ` + [[ $udev_info != "KERNEL==\"$short_dev\"" ]] && continue #not correct device + + udev_info=`echo "$udev" | grep 'SUBSYSTEM=="block"' | tr -d ' ' ` + [[ $udev_info != "SUBSYSTEM==\"block\"" ]] && continue #not correct device + + udev_info=`echo "$udev" | grep 'ATTR{events}=="media_change"' | tr -d ' ' ` + [[ $udev_info != "ATTR{events}==\"media_change\"" ]] && continue #not correct device + + #check > 0 per evitare device pur presenti ma senza memoria inserita + udev_info=`echo "$udev" | grep -E 'ATTR{size}=="[0-9]{1,}"' | tr -d ' ' ` + [[ $udev_info != *"ATTR{size}=="* ]] && continue #not correct device + value=` echo "$udev_info" | cut -d "\"" -f2 | cut -d "\"" -f1 ` + [[ $value -lt 1 ]] && continue #not correct device + + echo -e "Pendrive \e[1;39;41m$drive\e[0m (size $(($value *512/1000/1000/1000 ))GBi) detected." + #break #uncomment to stop search after the first + + n_found=$(( $n_found + 1 )) + fi + done + [[ $n_found -lt 1 ]] && echo "No pendrive found" || echo "$n_found pendrives total found." + #} + diff --git a/simona-scripts b/simona-scripts new file mode 100755 index 000000000000..68db1464cf5e --- /dev/null +++ b/simona-scripts @@ -0,0 +1,12 @@ +#!/bin/bash +# Simona Pisano - 2018-11-18 - +# simona-scripts +# Libertamente utilizzabile sotto GPL v3 + +echo "simona-scripts - GPL v3 license" +echo "image-mount" +echo "image-umount" +echo "pendrive-detect - detect a pendrive" +echo "ioscheduler-list" +echo "boot-kernel-list" + |