coffin

secure lan file storage on a device
git clone git://parazyd.org/coffin.git
Log | Files | Refs | Submodules | README | LICENSE

makehook (5290B)


      1 #!/usr/bin/env bash
      2 #
      3 # Copyright (c) 2016 Dyne.org Foundation
      4 # coffin is written and maintained by Ivan J. <parazyd@dyne.org>
      5 #
      6 # This file is part of coffin
      7 #
      8 # This source code is free software: you can redistribute it and/or modify
      9 # it under the terms of the GNU General Public License as published by
     10 # the Free Software Foundation, either version 3 of the License, or
     11 # (at your option) any later version.
     12 #
     13 # This software is distributed in the hope that it will be useful,
     14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 # GNU General Public License for more details.
     17 #
     18 # You should have received a copy of the GNU General Public License
     19 # along with this source code. If not, see <http://www.gnu.org/licenses/>.
     20 
     21 hooks="hook"
     22 davfile="davpasswd"
     23 ttab="ttab"
     24 system=$(uname -o)
     25 
     26 gendav() {
     27 	if [[ $system == "GNU/Linux" ]]; then
     28 		daventry=$(echo -n "${undertaker}:WebDAV:" \
     29 			&& echo -n "${undertaker}:WebDAV:${davpass}" \
     30 			| md5sum \
     31 			| awk '{print $1}'
     32 		)
     33 
     34 	elif [[ $system == "Darwin" ]]; then
     35 		daventry=$(echo -n "${undertaker}:WebDAV:" \
     36 			&& echo -n "${undertaker}:WebDAV:${davpass}" \
     37 			| md5 \
     38 			| awk '{print $NF}'
     39 		)
     40 	fi
     41 }
     42 
     43 successmsg() {
     44 	cat <<EOM
     45 
     46 Your hook has been created successfully. Plug your USB key into the coffin to
     47 execute it, or rerun this script to create another hook.
     48 
     49 EOM
     50 }
     51 
     52 genhook() {
     53 	case $1 in
     54 		create)
     55 			hookentry="create:${undertaker}:${tombname}:${tombsize}:webdav"
     56 			echo $hookentry >> $hooks
     57 			gendav
     58 			echo ${daventry} >> ${davfile}
     59 			;;
     60 		delete)
     61 			hookentry="delete:${undertaker}:${tombname}"
     62 			[[ -f ${tombname}.key ]] || {
     63 				echo "WARNING: This delete hook will not work, as you do not
     64 have the keyfile used for it with you."
     65 			}
     66 			echo ${hookentry} >> ${hooks}
     67 			;;
     68 		backup)
     69 			echo "backup"
     70 			;;
     71 		wallet)
     72 			hookentry="create:${undertaker}:${tombname}:${tombsize}:wallet"
     73 			echo ${hookentry} >> ${hooks}
     74 			;;
     75 		*)
     76 			echo "how did you even get here?"
     77 			;;
     78 	esac
     79 }
     80 
     81 happenz() {
     82 	case $1 in
     83 	# {{{ create
     84 		1)
     85 			echo -e "\n"
     86 			echo "Creating a new tomb..."
     87 
     88 			read -p "Please input the username you wish to use: " undertaker
     89 			re='^[A-Za-z0-9]+$'
     90 			[[ $undertaker =~ $re ]] || {
     91 				echo "ERROR: Invalid characters in username."
     92 				exec $0
     93 			}
     94 
     95 			read -p "Please input the name you wish to use for your tomb: " tombname
     96 			[[ $tombname =~ $re ]] || {
     97 				echo "ERROR: Invalid characters in tomb name."
     98 				exec $0
     99 			}
    100 
    101 			read -p "Please input the size of your tomb in MiB: " tombsize
    102 			re='^[0-9]+$'
    103 			[[ $tombsize =~ $re ]] || {
    104 				echo "ERROR: Invalid characters in tomb size."
    105 				exec $0
    106 			}
    107 
    108 			read -r -p "Please input the password you will use to access your tomb: " davpass
    109 
    110 			genhook create && successmsg
    111 			;;
    112 	# }}}
    113 	# {{{ delete
    114 		2)
    115 			echo -e "\nDeleting an exising tomb...\n"
    116 
    117 			read -p "Please input the username you used to create the tomb: " undertaker
    118 			re='^[A-Za-z0-9]+$'
    119 			[[ $undertaker =~ $re ]] || {
    120 				echo "ERROR: Invalid characters in username."
    121 				exec $0
    122 			}
    123 
    124 			read -p "Please input the name you used for your tomb: " tombname
    125 			[[ $tombname =~ $re ]] || {
    126 				echo "ERROR: Invalid characters in tomb name."
    127 				exec $0
    128 			}
    129 
    130 			# NOTE: possibly include prompt for webdav password
    131 
    132 			genhook delete && successmsg
    133 			;;
    134 	# }}}
    135 		3)
    136 			echo -e "\n"
    137 			echo "backin up"
    138 			;;
    139 		4)
    140 			echo -e "\n"
    141 			echo "Toggling state..."
    142 
    143 			read -p "Please input the name of the tomb you wish to toggle: "
    144 			re='^[A-Za-z0-9]+$'
    145 			[[ $tombname =~ $re ]] || {
    146 				echo "ERROR: Invalid characters in tomb name."
    147 				exec $0
    148 			}
    149 			[[ `grep $tombname $ttab` ]] || {
    150 				echo "ERROR: No tomb of that name."
    151 				exec $0
    152 			}
    153 
    154 			# TODO: make pattern recognition, sed or awk
    155 			;;
    156 		5)
    157 			echo -e "\n"
    158 			echo "Creating a Bitcoin wallet..."
    159 
    160 			read -p "Please input the username you wish to use: " undertaker
    161 			re='^[A-Za-z0-9]+$'
    162 			[[ $undertaker =~ $re ]] || {
    163 				echo "ERROR: Invalid characters in username."
    164 				exec $0
    165 			}
    166 
    167 			read -p "Please input the name you wish to use for your tomb: " tombname
    168 			[[ $tombname =~ $re ]] || {
    169 				echo "ERROR: Invalid characters in tomb name."
    170 				exec $0
    171 			}
    172 
    173 			tombsize=20 ## NOTE: could possibly be less
    174 
    175 			read -r -p "Please input the password you will use to access your tomb: " davpass
    176 
    177 			genhook wallet
    178 			[[ $? = 0 ]] && {
    179 				successmsg
    180 			}
    181 			;;
    182 		0)
    183 
    184 			echo -e "Quitting...\n"
    185 			exit 0
    186 			;;
    187 		*)
    188 			echo -e "\nNo valid option. Exiting...\n"
    189 			exit 1
    190 			;;
    191 	esac
    192 }
    193 
    194 main() {
    195 	cat <<EOF
    196 
    197 #########################################################
    198                    ┏━╸┏━┓┏━╸┏━╸╻┏┓╻
    199                    ┃  ┃ ┃┣╸ ┣╸ ┃┃┗┫
    200                    ┗━╸┗━┛╹  ╹  ╹╹ ╹
    201    = cryptographic office filer for important nuggets =
    202                       version 0.4
    203                 https://coffin.dyne.org
    204 
    205 1) Create a new tomb on the coffin
    206 2) Delete an existing tomb on the coffin
    207 3) Backup a tomb from the coffin
    208 4) Toggle your tomb's open/close state
    209 5) Configure and create a Bitcoin wallet
    210 0) Quit
    211 
    212 #########################################################
    213 
    214 EOF
    215 
    216 read -p "Type in the number of the function you wish to perform: " action
    217 happenz $action
    218 }
    219 
    220 main