tmoar small fixes - coffin - secure lan file storage on a device HTML git clone git://parazyd.org/coffin.git DIR Log DIR Files DIR Refs DIR Submodules DIR README DIR LICENSE --- DIR commit 1806989bd2345e4b85ce7cfa552ee0eb9fc4e0a6 DIR parent 1e8db60c4b19043be11e3eadc62bb75520e118f1 HTML Author: parazyd <parazyd@dyne.org> Date: Tue, 29 Mar 2016 17:55:32 +0200 moar small fixes Diffstat: M helpers/gmakehook | 322 ++++++++++++------------------- 1 file changed, 120 insertions(+), 202 deletions(-) --- DIR diff --git a/helpers/gmakehook b/helpers/gmakehook t@@ -12,6 +12,7 @@ typeset -H sudoassword keymount="/media/tombkey" coffindot="$keymount/.coffin" hooks="$coffindot/hook" +GRAVEYARD="/home/graveyard" # {{{ icon MONMORT="/tmp/monmort.png" t@@ -25,7 +26,6 @@ WHRkYXRlOmNyZWF0ZQAyMDExLTAxLTEyVDA5OjM0OjI0KzAxOjAwo//d7wAAACV0RVh0ZGF0ZTpt b2RpZnkAMjAxMS0wMS0xMlQwOTozNDoyNCswMTowMNKiZVMAAAAASUVORK5CYII=" print "$ICONB64" | base64 --decode > $MONMORT # }}} - # {{{ sudo functions function _sudo { sudoassword=$(ask_password "Insert sudo password for user $USER") t@@ -40,7 +40,6 @@ function _sudowrong { fi } # }}} - # {{{ Some pinentry code shamelessly stolen from tomb # Ask user for a password # Wraps around the pinentry command, from the GnuPG project, as it t@@ -162,16 +161,6 @@ _is_found() { return $? } # }}} - -# {{{ _clean - Clean function, removes sensitive stuff from memory -function _clean { - TOMBSIZE="$rr"; unset TOMBSIZE - TOMBNAME="$rr"; unset TOMBNAME - UNDERTAKER="$rr"; unset UNDERTAKER - sudoassword="$rr"; unset sudoassword -} -# }}} - # {{{ zenity dialogs function _fsel { zenity \ t@@ -216,27 +205,49 @@ function _zenentry { } # }}} -function _umountkey { sudo umount $keymount && sudo rmdir $keymount } -function _mountkey { - sudo umount $USBKEY - [[ $? = 0 ]] || { - _zenerr "Error" "Your key is mounted somewhere and I've run into issues. Please unmount it and re-run." - _clean && exit } +# {{{ _clean - Clean function, removes sensitive stuff from memory +function _clean { + TOMBSIZE="$rr"; unset TOMBSIZE + TOMBNAME="$rr"; unset TOMBNAME + UNDERTAKER="$rr"; unset UNDERTAKER + sudoassword="$rr"; unset sudoassword +} +# }}} +function _umountkey() { + sudo umount $keymount \ + && sudo rmdir $keymount +} - if [[ -d $keymount ]]; then +function _mountkey { + [[ -d $keymount ]] && { _zenwarn "Warning" "Something is already mounted on $keymount. Please check and re-run." _clean && exit - fi + } - sudo mkdir -p $keymount - sudo mount $USBKEY $keymount + sudo mkdir -p $keymount + sudo mount $USBKEY $keymount - if ! [[ -d $coffindot ]]; then - sudo mkdir $coffindot - fi + [[ -d $coffindot ]] || sudo mkdir $coffindot +} + +function _main { + _clean + cmnd=$(zenity \ + --window-icon="$MONMORT" \ + --title="coffin hook helper" \ + --list \ + --hide-header \ + --text="coffin hook helper\nChoose what hook you want to create:" \ + --separator=" # " \ + --column=Function \ + --column=Description \ + "create" "a new tomb on the coffin" \ + "delete" "a tomb from the coffin" \ + "backup" "a tomb from the coffin" \ + "foobar" "on the coffin") + eval "_$cmnd" } -# {{{ _writedavinfo function _writedavinfo { if [[ -n $davpass ]]; then davinfo=$(echo -n "$UNDERTAKER:WebDAV:" \ t@@ -255,7 +266,7 @@ function _writedavinfo { Options Indexes FollowSymlinks AuthType Digest AuthName WebDAV - AuthUserFile /etc/apache2/davpasswd + AuthUserFile /etc/apache2/DAV/davpasswd Require user ${UNDERTAKER} </Directory> t@@ -263,25 +274,6 @@ function _writedavinfo { </IfModule> EOF } -# }}} - -function _main { - _clean - cmnd=$(zenity \ - --window-icon="$MONMORT" \ - --title="coffin hook helper" \ - --list \ - --hide-header \ - --text="coffin hook helper\nChoose what hook you want to create:" \ - --separator=" # " \ - --column=Function \ - --column=Description \ - "create" "a new tomb on the coffin" \ - "delete" "a tomb from the coffin" \ - "backup" "a tomb from the coffin" \ - "foobar" "on the coffin") - eval "_$cmnd" -} # {{{ _create function _create { t@@ -294,27 +286,27 @@ function _create { --add-entry="coffin username" \ --add-entry="Tomb name" \ --add-entry="Tomb's size in MiB") - if [[ $? = 1 ]]; then - exec _main - else - UNDERTAKER=${vars[(ws@:@)1]} - re='^[A-Za-z0-9]+$' - if ! [[ $UNDERTAKER =~ $re ]]; then - _zenwarn "Warning" "Invalid characters in username!" - exec _create - fi - TOMBNAME=${vars[(ws@:@)2]} - if ! [[ $TOMBNAME =~ $re ]]; then - _zenwarn "Warning" "Invalid characters in tomb name!" - exec _create - fi - TOMBSIZE=${vars[(ws@:@)3]} - re='^[0-9]+$' - if ! [[ $TOMBSIZE =~ $re ]]; then - _zenwarn "Warning" "Invalid characters in tomb size!" - exec _create - fi - fi + [[ $? = 0 ]] || exec _main + + UNDERTAKER=${vars[(ws@:@)1]} + re='^[A-Za-z0-9]+$' + [[ $UNDERTAKER =~ $re ]] || { + _zenwarn "Warning" "Invalid characters in username!" + exec _create + } + + TOMBNAME=${vars[(ws@:@)2]} + [[ $TOMBNAME =~ $re ]] || { + _zenwarn "Warning" "Invalid characters in tomb name!" + exec _create + } + + TOMBSIZE=${vars[(ws@:@)3]} + re='^[0-9]+$' + [[ $TOMBSIZE =~ $re ]] || { + _zenwarn "Warning" "Invalid characters in tomb size!" + exec _create + } feats=$(zenity \ --window-icon="$MONMORT" \ t@@ -326,38 +318,33 @@ function _create { --column=Yes/No \ --column=Feature \ "FALSE" "webdav" \ - "FALSE" "sshfs" \ - "FALSE" "ipfs") - if [[ $? = 1 ]]; then; exec _main; fi + "FALSE" "sshfs") + [[ $? = 0 ]] || exec _main - if [[ $feats =~ "webdav" ]]; then + [[ $feats =~ "webdav" ]] && { _zenques "Do you already have a WebDAV login?" - if [[ $? = 1 ]]; then + [[ $? = 0 ]] || { davpass=$(_zenentry "WebDAV Password" \ "Insert the password you want to use for WebDAV login:" \ "my very strong password") - if [[ $? = 1 ]]; then; davpass=""; fi - fi - fi + [[ $? = 0 ]] || davpass="" + } + } - if [[ $feats =~ "sshfs" ]]; then + [[ $feats =~ "sshfs" ]] && { _zenques "Do you already have an SSH key setup for your user?" - if [[ $? = 1 ]]; then - sshpubkey=$(_fsel "Select your SSH pubkey you want to use.") - else - sshpubkey="" - fi - fi + [[ $? = 0 ]] || sshpubkey=$(_fsel "Select your SSH pubkey you want to use.") + } TOMBHOOKS=$(_zenques "Choose 'Yes' if you want to edit your tomb's bind-hooks and post-hooks") - if [[ $? = 0 ]]; then + [[ $? = 0 ]] || { bindhook=$(zenity \ --window-icon="$MONMORT" \ --title="bind-hooks" \ --checkbox="Accept these bind-hooks" \ --text-info \ --editable) - if [[ $? = 1 ]]; then; exec _main; fi + [[ $? = 0 ]] || exec _main posthook=$(zenity \ --window-icon="$MONMORT" \ t@@ -365,10 +352,11 @@ function _create { --checkbox="Accept these post-hooks" \ --text-info \ --editable) - if [[ $? = 1 ]]; then; exec _main; fi - fi + [[ $? = 0 ]] || exec _main + } _zeninfo "gmakehook" "Plug in your USB key and click OK." + sleep 1 lsblk -npl | awk -F" " '{print $1 " " $4}' | grep '^/dev/sd.. ' > ./.devs USBKEY=$(zenity \ t@@ -380,40 +368,34 @@ function _create { --column="Device path" \ --column="Device size" \ $(cat ./.devs)) - if [[ $? = 1 ]]; then; exec _main; fi + [[ $? = 0 ]] || exec _main _sudo _mountkey - if [[ -f $hooks ]]; then + + [[ -f $hooks ]] && { _zenques "Warning! There is already an existing hook. Do you want to overwrite?" - if [[ $? = 1 ]]; then - _zeninfo "gmakehook" "Postponing..." && _umountkey && exec _main - else - print "create:${UNDERTAKER}:${TOMBNAME}:${TOMBSIZE}:${feats}" | sudo tee $hooks - if [[ $feats =~ "webdav" ]]; then; _writedavinfo; fi - if [[ -n $sshpubkey ]]; then; sudo cp $sshpubkey ./sshpubkey ; fi - if [[ -n $bindhook ]]; then - print "$bindhook" | sudo tee $coffindot/bindhooks - fi - if [[ -n $posthook ]]; then - print "$posthook" | sudo tee $coffindot/posthooks - fi - _umountkey && _zeninfo "Success" "$hooks written successfully!\nPlug the USB key in a coffin to activate it." - exec _main - fi - else - print "create:${UNDERTAKER}:${TOMBNAME}:${TOMBSIZE}:${feats}" | sudo tee $hooks - if [[ $feats =~ "webdav" ]]; then; _writedavinfo; fi - if [[ -n $sshpubkey ]]; then; sudo cp $sshpubkey $coffindot/sshpubkey ; fi - if [[ -n $bindhook ]]; then - print "$bindhook" | sudo tee $coffindot/bindhooks - fi - if [[ -n $posthook ]]; then - print "$posthook" | sudo tee $coffindot/posthooks - fi - _umountkey && _zeninfo "Success" "$hooks written successfully!\nPlug the USB key in the coffin to activate it." - exec _main - fi + [[ $? = 0 ]] || { + _zeninfo "gmakehook" "Postponing..." && \ + _umountkey && \ + exec _main + } + } + + [[ $feats =~ "webdav" ]] && _writedavinfo + [[ $? = 0 ]] && { _zenerr "Error" "Error writing WebDAV info." && exec _main } + [[ -n $sshpubkey ]] && sudo cp $sshpubkey $coffindot/$tombid.pub + [[ $? = 0 ]] && { _zenerr "Error" "Error writing SSH info." && exec _main } + + [[ -n $bindhook ]] && print "$bindhook" | sudo tee $coffindot/bindhooks + [[ $? = 0 ]] && { _zenerr "Error" "Error writing bind-hook info." && exec _main } + [[ -n $posthook ]] && print "$posthook" | sudo tee $coffindot/posthooks + [[ $? = 0 ]] && { _zenerr "Error" "Error writing post-hook info." && exec _main } + + print "create:${UNDERTAKER}:${TOMBNAME}:${TOMBSIZE}:${feats}" | sudo tee $hooks + + _umountkey && _zeninfo "Success" "$hooks written successfully!\nPlug the USB key in the coffin to activate it." + exec _main } # }}} t@@ -427,82 +409,23 @@ function _delete { --separator=":" \ --add-entry="coffin username" \ --add-entry="Tomb name") - if [[ $? = 1 ]]; then - exec _main - else - UNDERTAKER=${vars[(ws@:@)1]} - re='^[A-Za-z0-9]+$' - if ! [[ $UNDERTAKER =~ $re ]]; then - _zenwarn "Warning" "Invalid characters in username!" - exec _delete - fi - TOMBNAME=${vars[(ws@:@)2]} - if ! [[ $TOMBNAME =~ $re ]]; then - _zenwarn "Warning" "Invalid characters in tomb name!" - exec _delete - fi - fi - - _zeninfo "gmakehook" "Plug in your USB key and click OK." - lsblk -npl | awk -F" " '{print $1 " " $4}' | grep '^/dev/sd.. ' > ./.devs - - USBKEY=$(zenity \ - --window-icon="$MONMORT" \ - --title="Choose USB key" \ - --list \ - --text="Choose your USB key to use" \ - --separator=" " \ - --column="Device path" \ - --column="Device size" \ - $(cat ./.devs)) - if [[ $? = 1 ]]; then; exec _main; fi + [[ $? = 0 ]] && exec _main - _sudo - _mountkey - if [[ -f $hooks ]]; then - _zenques "Warning! There is already an existing hook. Do you want to overwrite?" - if [[ $? = 1 ]]; then - _zeninfo "gmakehook" "Postponing..." && _umountkey && exec _main - else - print "delete:${UNDERTAKER}:${TOMBNAME}" | sudo tee $hooks - _umountkey && _zeninfo "Success" "$hooks written successfully!\nPlug the USB key in a coffin to activate it." - exec _main - fi - else - print "delete:${UNDERTAKER}:${TOMBNAME}" | sudo tee $hooks - _umountkey && _zeninfo "Success" "$hooks written successfully!\nPlug the USB key in the coffin to activate it." - exec _main - fi -} -# }}} + UNDERTAKER=${vars[(ws@:@)1]} + re='^[A-Za-z0-9]+$' + [[ $UNDERTAKER =~ $re ]] || { + _zenwarn "Warning" "Invalid characters in username!" + exec _delete + } -# {{{ _backup -function _backup { - vars=$(zenity \ - --window-icon="$MONMORT" \ - --title="Backup an existing tomb" \ - --forms \ - --text="Enter the info of your tomb" \ - --separator=":" \ - --add-entry="coffin username" \ - --add-entry="Tomb name") - if [[ $? = 1 ]]; then - exec _main - else - UNDERTAKER=${vars[(ws@:@)1]} - re='^[A-Za-z0-9]+$' - if ! [[ $UNDERTAKER =~ $re ]]; then - _zenwarn "Warning" "Invalid characters in username!" - exec _delete - fi - TOMBNAME=${vars[(ws@:@)2]} - if ! [[ $TOMBNAME =~ $re ]]; then - _zenwarn "Warning" "Invalid characters in tomb name!" - exec _delete - fi - fi + TOMBNAME=${vars[(ws@:@)2]} + [[ $TOMBNAME =~ $re ]] || { + _zenwarn "Warning" "Invalid characters in tomb name!" + exec _delete + } _zeninfo "gmakehook" "Plug in your USB key and click OK." + sleep 1 lsblk -npl | awk -F" " '{print $1 " " $4}' | grep '^/dev/sd.. ' > ./.devs USBKEY=$(zenity \ t@@ -514,24 +437,19 @@ function _backup { --column="Device path" \ --column="Device size" \ $(cat ./.devs)) - if [[ $? = 1 ]]; then; exec _main; fi + [[ $? = 0 ]] || exec _main _sudo _mountkey - if [[ -f $hooks ]]; then + + [[ -f $hooks ]] && { _zenques "Warning! There is already an existing hook. Do you want to overwrite?" - if [[ $? = 1 ]]; then - _zeninfo "gmakehook" "Postponing..." && _umountkey && exec _main - else - print "backup:${UNDERTAKER}:${TOMBNAME}" | sudo tee $hooks - _umountkey && _zeninfo "Success" "$hooks written successfully!\nPlug the USB key in a coffin to activate it." - exec _main - fi - else - print "backup:${UNDERTAKER}:${TOMBNAME}" | sudo tee $hooks - _umountkey && _zeninfo "Success" "$hooks written successfully!\nPlug the USB key in the coffin to activate it." - exec _main - fi + [[ $? = 0 ]] && _zeninfo "gmakehook" "Postponing..." && _umountkey && exec _main + } + + print "delete:${UNDERTAKER}:${TOMBNAME}" | sudo tee $hooks + _umountkey && _zeninfo "Success" "$hooks written successfully!\nPlug the USB key in a coffin to activate it." + exec _main } # }}}