tremove gmakehook - coffin - secure lan file storage on a device (HTM) git clone git://parazyd.org/coffin.git (DIR) Log (DIR) Files (DIR) Refs (DIR) Submodules (DIR) README (DIR) LICENSE --- (DIR) commit 880a2a60fdf3bdbdf2af6cee76aa2da1b74236e5 (DIR) parent 8ceaaa6ae295fa51e824de63f4e86e6633e8ad45 (HTM) Author: parazyd <parazyd@dyne.org> Date: Thu, 6 Oct 2016 14:50:03 +0200 remove gmakehook Diffstat: D helpers/gmakehook | 461 ------------------------------ 1 file changed, 0 insertions(+), 461 deletions(-) --- (DIR) diff --git a/helpers/gmakehook b/helpers/gmakehook t@@ -1,461 +0,0 @@ -#!/usr/bin/env zsh -# -# Zenity helper script to make coffin hooks more user-friendly -# -# ~ parazyd - -typeset -H UNDERTAKER -typeset -H TOMBSIZE -typeset -H TOMBNAME -typeset -H sudoassword - -keymount="/media/tombkey" -coffindot="$keymount/.coffin" -hooks="$coffindot/hook" -GRAVEYARD="/home/graveyard" - -# {{{ icon -MONMORT="/tmp/monmort.png" -ICONB64="iVBORw0KGgoAAAANSUhEUgAAACAAAAAgEAQAAACJ4248AAAAAmJLR0T//xSrMc0AAAAJcEhZcwAA -AEgAAABIAEbJaz4AAAAJdnBBZwAAACAAAAAgAIf6nJ0AAADrSURBVFjD5ZZBEsMgCEU/TO/l2XMx -04VjQ1K1CDYswkwWJnH+E/EL4RP7jluDCACoim/bvfIpFQiKEJcQHCN9xEtLCgDMQM7f33sZrPNG -/05loCXujfAtCAVgNgLwIuycjQAra8G9Fm823ADabPRA1QDelfZAVUZktWrNvL8ew5YTnsStx3Am -AyOInJVbYF1prZuU+tsR1g9UMDqGuo5oFWhtSEQNEGmeVrqv73Tj0pIZirANMYqRhyw5Bb9MauSW -SwA8l9OzG5LnAsiiDQGQRRvaEwInK54J390hndAIYIeQ4k6AAjE/h06ab0SjP08MA1xDAAAAJXRF -WHRkYXRlOmNyZWF0ZQAyMDExLTAxLTEyVDA5OjM0OjI0KzAxOjAwo//d7wAAACV0RVh0ZGF0ZTpt -b2RpZnkAMjAxMS0wMS0xMlQwOTozNDoyNCswMTowMNKiZVMAAAAASUVORK5CYII=" -print "$ICONB64" | base64 --decode > $MONMORT -# }}} -# {{{ sudo functions -function _sudo { - sudoassword=$(ask_password "Insert sudo password for user $USER") - print "$sudoassword\n" | sudo -S -v - _sudowrong -} -function _sudowrong { - if [[ $? == 1 ]]; then - sudoassword=$(ask_password "Wrong password. Insert sudo password for user $USER") - print "$sudoassword\n" | sudo -S -v - _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 -# provides better security and conveniently use the right toolkit. -ask_password() { - local description="$1" - local title="${2:-Enter tomb password.}" - local output - local password - local gtkrc - local theme - - # Distributions have broken wrappers for pinentry: they do - # implement fallback, but they disrupt the output somehow. We are - # better off relying on less intermediaries, so we implement our - # own fallback mechanisms. Pinentry supported: curses, gtk-2, qt4 - # and x11. - - # make sure LANG is set, default to C - LANG=${LANG:-C} - - - if [[ "$DISPLAY" = "" ]]; then - - if _is_found "pinentry-curses"; then - output=`cat <<EOF | pinentry-curses -OPTION ttyname=$TTY -OPTION lc-ctype=$LANG -SETTITLE $title -SETDESC $description -SETPROMPT Password: -GETPIN -EOF` - fi - - else # a DISPLAY is found to be active - - # customized gtk2 dialog with a skull (if extras are installed) - if _is_found "pinentry-gtk-2"; then - - gtkrc="" - theme=/share/themes/tomb/gtk-2.0-key/gtkrc - for i in /usr/local /usr; do - [[ -r $i/$theme ]] && { - gtkrc="$i/$theme" - break - } - done - [[ "$gtkrc" = "" ]] || { - gtkrc_old="$GTK2_RC_FILES" - export GTK2_RC_FILES="$gtkrc" - } - output=`cat <<EOF | pinentry-gtk-2 -OPTION ttyname=$TTY -OPTION lc-ctype=$LANG -SETTITLE $title -SETDESC $description -SETPROMPT Password: -GETPIN -EOF` - [[ "$gtkrc" = "" ]] || export GTK2_RC_FILES="$gtkrc_old" - - # TODO QT4 customization of dialog - elif _is_found "pinentry-qt4"; then - - # TODO X11 customization of dialog - elif _is_found "pinentry-x11"; then - - output=`cat <<EOF | pinentry-x11 -OPTION ttyname=$TTY -OPTION lc-ctype=$LANG -SETTITLE $title -SETDESC $description -SETPROMPT Password: -GETPIN -EOF` - - else - - if _is_found "pinentry-curses"; then - - output=`cat <<EOF | pinentry-curses -OPTION ttyname=$TTY -OPTION lc-ctype=$LANG -SETTITLE $title -SETDESC $description -SETPROMPT Password: -GETPIN -EOF` - else - fi - - fi - - fi # end of DISPLAY block - - # parse the pinentry output - for i in ${(f)output}; do - [[ "$i" =~ "^ERR.*" ]] && { - print "canceled" - return 1 } - - # here the password is found - [[ "$i" =~ "^D .*" ]] && password="${i##D }" - done - - [[ "$password" = "" ]] && { - print "empty" - return 1 } - - print "$password" - return 0 -} - -_is_found() { - # returns 0 if binary is found in path - [[ "$1" = "" ]] && return 1 - command -v "$1" 1>/dev/null 2>/dev/null - return $? -} -# }}} -# {{{ zenity dialogs -function _fsel { - zenity \ - --window-icon="$MONMORT" \ - --file-selection \ - --title="$1" -} -function _zenques { - zenity \ - --window-icon="$MONMORT" \ - --question \ - --text="$1" -} -function _zenwarn { - zenity \ - --window-icon="$MONMORT" \ - --warning \ - --title="$1" \ - --text="$2" -} -function _zeninfo { - zenity \ - --window-icon="$MONMORT" \ - --info \ - --title="$1" \ - --text="$2" -} -function _zenerr { - zenity \ - --window-icon="$MONMORT" \ - --error \ - --title="$1" \ - --text="$2" -} -function _zenentry { - zenity \ - --window-icon="$MONMORT" \ - --entry \ - --title="$1" \ - --text="$2" \ - --entry-text="$3" -} -# }}} - -# {{{ _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 -} - -function _mountkey { - [[ -d $keymount ]] && { - _zenwarn "Warning" "Something is already mounted on $keymount. Please check and re-run." - _clean && exit - } - - sudo mkdir -p $keymount - sudo mount $USBKEY $keymount - - sudo chown $UID:$GID $keymount - - [[ -d $coffindot ]] || { - 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" -} - -function _writedavinfo { - if [[ -n $davpass ]]; then - davinfo=$(echo -n "$UNDERTAKER:WebDAV:" \ - && echo -n "$UNDERTAKER:WebDAV:$davpass" \ - | md5sum \ - | awk '{print $1}') - print $davinfo | sudo tee $coffindot/davinfo - fi - - cat <<EOF | sudo tee $coffindot/webdav.conf - - alias /${TOMBNAME} /media/${TOMBNAME} - <Directory "/media/${TOMBNAME}"> - Dav On - AllowOverride none - Options Indexes FollowSymlinks - AuthType Digest - AuthName WebDAV - AuthUserFile /etc/apache2/DAV/davpasswd - Require user ${UNDERTAKER} - </Directory> - - </VirtualHost> -</IfModule> -EOF -} - -# {{{ _create -function _create { - vars=$(zenity \ - --window-icon="$MONMORT" \ - --title="Create a new tomb" \ - --forms \ - --text="Enter the info for your new tomb" \ - --separator=":" \ - --add-entry="coffin username" \ - --add-entry="Tomb name" \ - --add-entry="Tomb's size in MiB") - [[ $? = 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" \ - --title="Choose features" \ - --text="Choose features you wish to include with your tomb" \ - --list \ - --checklist \ - --separator=":" \ - --column=Yes/No \ - --column=Feature \ - "FALSE" "webdav" \ - "FALSE" "sshfs") - [[ $? = 0 ]] || exec _main - - [[ $feats =~ "webdav" ]] && { - _zenques "Do you already have a WebDAV login?" - [[ $? = 0 ]] || { - davpass=$(_zenentry "WebDAV Password" \ - "Insert the password you want to use for WebDAV login:" \ - "my very strong password") - [[ $? = 0 ]] || davpass="" - } - } - - [[ $feats =~ "sshfs" ]] && { - _zenques "Do you already have an SSH key setup for your user?" - [[ $? = 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") - [[ $? = 0 ]] || { - bindhook=$(zenity \ - --window-icon="$MONMORT" \ - --title="bind-hooks" \ - --checkbox="Accept these bind-hooks" \ - --text-info \ - --editable) - [[ $? = 0 ]] || exec _main - - posthook=$(zenity \ - --window-icon="$MONMORT" \ - --title="post-hooks" \ - --checkbox="Accept these post-hooks" \ - --text-info \ - --editable) - [[ $? = 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 \ - --window-icon="$MONMORT" \ - --title="Choose USB key" \ - --list \ - --text="Choose your USB key to use" \ - --separator=" " \ - --column="Device path" \ - --column="Device size" \ - $(cat ./.devs)) - [[ $? = 0 ]] || exec _main - - _sudo - _mountkey - - [[ -f $hooks ]] && { - _zenques "Warning! There is already an existing hook. Do you want to overwrite?" - [[ $? = 0 ]] || { - _zeninfo "gmakehook" "Postponing..." && \ - _umountkey && \ - exec _main - } - } - - [[ $feats =~ "webdav" ]] && _writedavinfo - [[ $? = 0 ]] && { _zenerr "Error" "Error writing WebDAV info." && exec _main } - [[ -n $sshpubkey ]] && cp $sshpubkey $coffindot/$tombid.pub - [[ $? = 0 ]] && { _zenerr "Error" "Error writing SSH info." && exec _main } - - [[ -n $bindhook ]] && print "$bindhook" | tee $coffindot/bindhooks - [[ $? = 0 ]] && { _zenerr "Error" "Error writing bind-hook info." && exec _main } - [[ -n $posthook ]] && print "$posthook" | tee $coffindot/posthooks - [[ $? = 0 ]] && { _zenerr "Error" "Error writing post-hook info." && exec _main } - - print "create:${UNDERTAKER}:${TOMBNAME}:${TOMBSIZE}:${feats}" >> $hooks - - _umountkey && _zeninfo "Success" "$hooks written successfully!\nPlug the USB key in the coffin to activate it." - exec _main -} -# }}} - -# {{{ _delete -function _delete { - vars=$(zenity \ - --window-icon="$MONMORT" \ - --title="Delete an existing tomb" \ - --forms \ - --text="Enter the info of your tomb" \ - --separator=":" \ - --add-entry="coffin username" \ - --add-entry="Tomb name") - [[ $? = 0 ]] && exec _main - - UNDERTAKER=${vars[(ws@:@)1]} - re='^[A-Za-z0-9]+$' - [[ $UNDERTAKER =~ $re ]] || { - _zenwarn "Warning" "Invalid characters in username!" - exec _delete - } - - 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 \ - --window-icon="$MONMORT" \ - --title="Choose USB key" \ - --list \ - --text="Choose your USB key to use" \ - --separator=" " \ - --column="Device path" \ - --column="Device size" \ - $(cat ./.devs)) - [[ $? = 0 ]] || exec _main - - _sudo - _mountkey - - [[ -f $hooks ]] && { - _zenques "Warning! There is already an existing hook. Do you want to overwrite?" - [[ $? = 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 -} -# }}} - -function _ { rm ./.devs } -exec _main