From 757fe70cd77daa4a58aec21d2ef93fb40981bc6e Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 8 Apr 2013 09:02:51 +0200 Subject: more on the makefile --- CHANGELOG | 91 ------------ COPYING | 2 +- Makefile | 31 +++- bin/pwgrep.sh | 415 +++++++++++++++++++++++++++++++++++++++++++++++++++++ create-symlinks.sh | 15 -- debian/changelog | 96 ++++++++++++- pwgrep.sh | 415 ----------------------------------------------------- 7 files changed, 535 insertions(+), 530 deletions(-) delete mode 100644 CHANGELOG create mode 100755 bin/pwgrep.sh delete mode 100755 create-symlinks.sh delete mode 100755 pwgrep.sh diff --git a/CHANGELOG b/CHANGELOG deleted file mode 100644 index 1c44a0a..0000000 --- a/CHANGELOG +++ /dev/null @@ -1,91 +0,0 @@ -Sat Mar 23 22:49:10 CET 2013 -* Change RCS from SVN to GIT as default. -* Added some GIT tweaks. -* Released 0.8.2 - -Sun Mar 10 12:08:16 CET 2013 -* Fix code indention - -Sun Mar 10 11:57:15 CET 2013 -* Released 0.8.1 - -Sun Mar 10 11:47:47 CET 2013 -* Moved source to git - -Mon Oct 3 22:33:50 CEST 2011 -* Some bugfixes -* Some minor code refactoring - -So 12. Jun 11:51:43 CEST 2011 -* Filestore has now categories -* Renamed lots of variables - -So 15. Mai 15:26:56 CEST 2011 -* Added initial README file - -Fri Jan 14 18:06:57 CET 2011 -* pwhelp prints now pwgrep version -* Using -devel postfix instead of -pre-X for dev versions - -Mo 3. Jan 08:04:13 CET 2011 - v0.8.1-pre-1 -* Initial new version made - -Mo 3. Jan 07:41:13 CET 2011 -* Tagged v0.8.0 -* Since pwgrep consinsts of very small updates only no more branches - except of trunk are used from now on. - -Mi 22. Dez 12:40:10 CET 2010 - v0.8-pre-4 -* Added option -a which searches all available databases at once. - This feature needs gpg-agent installed. Otherwise the gpg key passphrase - needs to be entered for each file separately . -* Some bugfix (using -z "$VAR" instead of -z $VAR) - -Mi 22. Dez 11:49:33 CET 2010 - v0.8-pre-3 -* Added WISHLIST file - -Fri Dec 10 14:22:04 CET 2010 - v0.8-pre-2 -* Set default db to private.gpg - -Fri Nov 19 22:05:27 CET 2010 - v0.8-pre-1 -* Added create-symlinks.sh - -Sun Nov 7 22:37:21 CET 2010 -* Released 0.7.0 - -Sat Oct 16 10:48:59 CEST 2010 - v0.7-pre-3 -* Added ~/.pwgreprc as default configuration file - -Mon Sep 27 22:43:23 CEST 2010 - v0.7-pre-2 -* Set SVN_EDITOR="ex -c 1" as default - -Sun Sep 19 12:29:06 CEST 2010 - v0.7-pre-1 -* New format of the CHANGELOG.txt (it's not GNU style) -* No VERSIONUPDATE on pwgrep, pwfls, pwfcat, pwdbls anymore -* Introduced new command pwupdate which will check out the newest version -from the repository. -* Introduced new command pwhelp which prints out a help screen - -Tue Sep 7 20:41:04 CEST 2010 -* v0.6 release branched - -Fri Jul 30 23:31:12 CEST 2010 - v0.5-pre-3 -* New command pwdbls, which lists all databases available. -* pwldb is a synonym for pwdbls. Changed the default database name -(database.gpg => mydb.gpg) - -Wed Jul 28 18:44:03 CEST 2010 - v0.5-pre-2 -* New option -d DATABASE, so its multi database capable now - -Wed Jul 28 18:16:09 CEST 2010 - v0.5-pre-1 -* pwfcat redirects all informational message to stderr. means -pwfcat includes no informational messages in stdout of pwgrep itself -anymore. Usefull for piping the content do another process or for -redirecting it into a file. - -Sun Jul 18 10:10:29 CEST 2010 v0.5-pre-0 -* Offlinemode support (Option -o) which does not use the versioning system -(usable if there is no internet connection available -atm). e.g. "pwgrep -o pwgrepbar" - - diff --git a/COPYING b/COPYING index c6090f6..5fd405b 100644 --- a/COPYING +++ b/COPYING @@ -1,4 +1,4 @@ -# pwgrep (c) 2009-2011, Dipl.-Inform. (FH) Paul Buetow +# pwgrep (c) 2009-2011, 2013, Dipl.-Inform. (FH) Paul Buetow # # E-Mail: pwgrep@mx.buetow.org WWW: http://pwgrep.buetow.org # diff --git a/Makefile b/Makefile index a867b95..c0fbc58 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,6 @@ all: version documentation build # Builds the project. Since this is only a fake project, it just copies a script. build: - cp -p ./src/$(NAME) bin/$(NAME) echo "echo This is version $$(cat .version)" >> bin/$(NAME) # 'install' installes a fake-root, which will be used to build the Debian package @@ -13,15 +12,35 @@ build: install: test ! -d $(DESTDIR)/usr/bin && mkdir -p $(DESTDIR)/usr/bin || exit 0 test ! -d $(DESTDIR)/usr/share/$(NAME) && mkdir -p $(DESTDIR)/usr/share/$(NAME) || exit 0 - cp ./bin/* $(DESTDIR)/usr/bin - #cp -r ./lib $(DESTDIR)/usr/share/$(NAME)/lib + cp ./bin/$(NAME).sh $(DESTDIR)/usr/share/$(NAME)/ + chmod 755 ./bin/$(NAME).sh $(DESTDIR)/usr/share/$(NAME)/$(NAME).sh + ln -s $(DESTDIR)/share/$(NAME)/$(NAME).sh $(DESTDIR)/fwipe + ln -s $(DESTDIR)/share/$(NAME)/$(NAME).sh $(DESTDIR)/pwdbls + ln -s $(DESTDIR)/share/$(NAME)/$(NAME).sh $(DESTDIR)/pwedit + ln -s $(DESTDIR)/share/$(NAME)/$(NAME).sh $(DESTDIR)/pwfadd + ln -s $(DESTDIR)/share/$(NAME)/$(NAME).sh $(DESTDIR)/pwfcat + ln -s $(DESTDIR)/share/$(NAME)/$(NAME).sh $(DESTDIR)/pwfdel + ln -s $(DESTDIR)/share/$(NAME)/$(NAME).sh $(DESTDIR)/pwfls + ln -s $(DESTDIR)/share/$(NAME)/$(NAME).sh $(DESTDIR)/pwgrep + ln -s $(DESTDIR)/share/$(NAME)/$(NAME).sh $(DESTDIR)/pwhelp + ln -s $(DESTDIR)/share/$(NAME)/$(NAME).sh $(DESTDIR)/pwldb + ln -s $(DESTDIR)/share/$(NAME)/$(NAME).sh $(DESTDIR)/pwupdate deinstall: - test ! -z "$(DESTDIR)" && test -f $(DESTDIR)/usr/bin/$(NAME) && rm $(DESTDIR)/usr/bin/$(NAME) || exit 0 - test ! -z "$(DESTDIR)/usr/share/$(NAME)" && -d $(DESTDIR)/usr/share/$(NAME) && rm -r $(DESTDIR)/usr/share/$(NAME) || exit 0 + rm $(DESTDIR)/fwipe 2>/dev/null || exit 0 + rm $(DESTDIR)/pwdbls 2>/dev/null || exit 0 + rm $(DESTDIR)/pwedit 2>/dev/null || exit 0 + rm $(DESTDIR)/pwfadd 2>/dev/null || exit 0 + rm $(DESTDIR)/pwfcat 2>/dev/null || exit 0 + rm $(DESTDIR)/pwfdel 2>/dev/null || exit 0 + rm $(DESTDIR)/pwfls 2>/dev/null || exit 0 + rm $(DESTDIR)/pwgrep 2>/dev/null || exit 0 + rm $(DESTDIR)/pwhelp 2>/dev/null || exit 0 + rm $(DESTDIR)/pwldb 2>/dev/null || exit 0 + rm $(DESTDIR)/pwupdate 2>/dev/null || exit 0 + -d $(DESTDIR)/usr/share/$(NAME) && rm -r $(DESTDIR)/usr/share/$(NAME) || exit 0 clean: - rm bin/* # ADDITIONAL RULES: diff --git a/bin/pwgrep.sh b/bin/pwgrep.sh new file mode 100755 index 0000000..b9d1edc --- /dev/null +++ b/bin/pwgrep.sh @@ -0,0 +1,415 @@ +#!/bin/bash + +# pwgrep v0.8.2 (c) 2009, 2010, 2011, 2013 by Paul Buetow +# pwgrep helps you to manage all your passwords using GnuGP +# for encryption and a versioning system (subversion by default) +# for keeping track all changes of your password database. In +# combination to GnuPG you should use the versioning system in +# combination with SSL or SSH encryption. + +# If you are using a *BSD, you may want to edit the shebang line. +# +# Usage: +# +# Searching for a database value: +# ./pwgrep.sh searchstring +# +# Editing the database (same but without args): +# ./pwgrep.sh +# +# For more reasonable commands the following symlinks are recommended. +# Take a look at the create-symlinks.sh script. + +# You can overwrite the default values by setting env. variables +# or by just editing this file. +DEFAULTDB=private.gpg +DEFAULTFILESTOREDIR=filestore +DEFAULTFILESTORECATEGORY=default +[ -z "$RCFILE" ] && RCFILE=~/.pwgreprc + +# Only use mawk or gawk, but if possible not nawk. On *BSD awk=nawk. So try +# awk/nawk last. You can use nawk but nawk will not match case insensitive. +[ -z "$TRYAWKLIST" ] && TRYAWKLIST="mawk gawk awk nawk" +# Find the correct command to wipe temporaly files after usage +[ -z "$TRYWIPELIST" ] && TRYWIPELIST="destroy shred" +# Same for sed +[ -z "$TRYSEDLIST" ] && TRYSEDLIST="sed gsed" + +# From here, do not change stuff! You may edit the content of the file $RCFILE! + +function source_config () { + [ -f $RCFILE ] && source <($SED 's/^/export /' $RCFILE) +} + +function pwgrep_version () { + sed -n '/# pwgrep v/ { s/# //; p; q; }' $0 +} + +function configure () { + # Reading the current configuration + source_config + + # Setting default values if not set in the configuration file already + ( + #[ -z "$SVN_EDITOR" ] && echo 'export SVN_EDITOR="ex -c 1"' + [ -z "$GIT_EDITOR" ] && echo 'export GIT_EDITOR=vim' + [ -z "$DB" ] && echo DB=$DEFAULTDB + [ -z "$FILESTOREDIR" ] && echo export FILESTOREDIR=$DEFAULTFILESTOREDIR + [ -z "$FILESTORECATEGORY" ] && echo export FILESTORECATEGORY=$DEFAULTFILESTORECATEGORY + + # The PWGREPWORDIR should be in its own versioning repository. + # For password revisions. + [ -z "$WORKDIR" ] && echo export WORKDIR=~/git/pwdb + + # Enter here your GnuPG key ID + [ -z "$GPGKEYID" ] && echo export GPGKEYID=37EC5C1D + + # Customizing the versioning commands (i.e. if you want to use another + # versioning system). + [ -z "$VERSIONCOMMIT" ] && echo 'export VERSIONCOMMIT="git commit -a"' + [ -z "$VERSIONUPDATE" ] && echo 'export VERSIONUPDATE="git pull origin master"' + [ -z "$VERSIONPUSH" ] && echo 'export VERSIONPUSH="git push origin master"' + [ -z "$VERSIONADD" ] && echo 'export VERSIONADD="git add"' + [ -z "$VERSIONDEL" ] && echo 'export VERSIONDEL="git rm"' + ) >> $RCFILE + + # Re-reading the current configuration, because there might be new + # variables by now + source_config +} + +function out () { + echo "$@" 1>&2 +} + +function info () { + out "=====> $@" +} + +function error () { + echo "ERROR: $@" + exit 666 +} + +function findbin () { + local -r trylist=$1 + found="" + for bin in $trylist; do + if [ -z $found ]; then + which=$(which $bin) + [ ! -z $which ] && found=$bin + fi + done + + echo $found +} + +function setawkcmd () { + AWK=$(findbin "$TRYAWKLIST") + [ -z $AWK ] && error No awk found in $PATH +} + +function setsedcmd () { + SED=$(findbin "$TRYSEDLIST") + [ -z $SED ] && error No sed found in $PATH +} + +function setwipecmd () { + WIPE=$(findbin "$TRYWIPELIST") + + if [ -z $WIPE ]; then + # FreeBSDs rm includes -P which is secure enough + if [ $(uname) = 'FreBSD' ]; then + WIPE="rm -v -P" + else + error "No wipe command found in $PATH, please install shred or destroy" + fi + fi + + info Using $WIPE for secure file deletion +} + +function pwgrep () { + local -r search=$1 + local -a dbs=() + + if [ -z "$ALL" ]; then + dbs=$DB + else + dbs=$(_pwdbls | sed 's/$/.gpg/') + fi + + for db in $dbs; do + info Searching for $search in $db + gpg --use-agent --decrypt $db | $AWK -v search="$search" ' + BEGIN { + flag=0 + IGNORECASE=1 + } + !/^\t/ { + if (!flag && $0 ~ search) { + flag=1 + print $0 + } else if (flag && $0 ~ search) { + print $0 + } else if (flag) { + flag=0 + } + } /^\t/ && flag { + print $0 + }' + done +} + +function pwupdate () { + if [ -z "$NOVERSIONING" ]; then + info Updating repository + $VERSIONUPDATE 2>&1 >/dev/null + fi +} + +function pwedit () { + pwupdate + cp -vp $DB $DB.$(date +'%s').snap && \ + gpg --decrypt $DB > .database && \ + vim --cmd 'set noswapfile' --cmd 'set nobackup' \ + --cmd 'set nowritebackup' .database && \ + gpg --output .$DB -e -r $GPGKEYID .database && \ + $WIPE .database && \ + mv .$DB $DB && \ + [ -z "$NOVERSIONING" ] && $VERSIONCOMMIT && [ ! -z "$VERSIONPUSH" ] && $VERSIONPUSH +} + +function _pwdbls () { + ls *.gpg | sed 's/\.gpg$//' +} + +function pwdbls () { + echo Available Databases: + _pwdbls + echo Current database: $DB +} + +function pwfls () { + local arg=$1 + + if [ "$ALL" = "1" ]; then + ALL=0 + local -r dir=$WORKDIR/$FILESTOREDIR + [ ! -e $dir ] && error $dir does not exist + + info Showing all categories + ls $dir | while read store; do + pwfls $store + done + else + local dir=$WORKDIR/$FILESTOREDIR + + if [ -z "$USEFILESTORECATEGORY" ]; then + info Available file store categories: + dir=$WORKDIR/$FILESTOREDIR + info "(You may use '`basename $0` -d ' to display containing files.)" + else + info Available files in store $FILESTORECATEGORY + dir=$WORKDIR/$FILESTOREDIR/$FILESTORECATEGORY + fi + + [ ! -e $dir ] && error "Category ($dir) does not exist" + ls $dir + fi +} + +function pwfcat () { + local arg=$1 + + if [ -z "$arg" ]; then + error "No file specified (hint: use pwfls)" + + else + local -r dir=$WORKDIR/$FILESTOREDIR/$FILESTORECATEGORY + local -r file=$(echo $arg | sed 's/.gpg$//') + + [ ! -e $dir ] && error "Category $FILESTORECATEGORY ($dir) does not exist" + [ ! -e $dir/$file.gpg ] && error "File $file in category $FILESTORECATEGORY does not exist" + gpg --decrypt $dir/$file.gpg + fi +} + +function pwfadd () { + local -r name=$(echo $1 | sed 's/.gpg$//') + local srcfile=$1 + local outfile='' + + if [ $(echo "$srcfile" | grep -v '^/') ]; then + srcfile=$CWD/$srcfile + fi + + if [ ! -z $2 ]; then + outfile=$(basename $2) + else + outfile=$(basename $name) + fi + + pwupdate + + [ -z "$name" ] && error Missing argument + if [ ! -e $FULLFILESTORE ]; then + info Creating new category + [ ! -z "$NOVERSIONING" ] && error Cannot add new category with versioning disabled + local -r umaskbackup=$(umask) + umask 0022 + mkdir $FULLFILESTORE && $VERSIONADD $FULLFILESTORE && $VERSIONCOMMIT && [ ! -z "$VERSIONPUSH" ] && $VERSIONPUSH + + umask $umaskbackup + fi + + [ ! -e $FILESTOREWORKDIR ] && error $FILESTOREWORKDIR does not exist + gpg --output $FULLFILESTORE/$outfile.gpg -e -r $GPGKEYID $srcfile && \ + + if [ -z "$NOVERSIONING" ]; then + $VERSIONADD $FULLFILESTORE/$outfile.gpg && $VERSIONCOMMIT && [ ! -z "$VERSIONPUSH" ] && $VERSIONPUSH + + fi +} + +function pwfdel () { + local arg=$1 + + if [ -z "$arg" ]; then + error "No file specified (hint: use pwfls)" + + else + local -r dir=$WORKDIR/$FILESTOREDIR/$FILESTORECATEGORY + local -r file=$(echo $arg | sed 's/.gpg$//') + local -r filepath=$dir/$file.gpg + + [ ! -e $dir ] && error "Category $FILESTORECATEGORY ($dir) does not exist" + [ ! -e $filepath ] && error "File $file in category $FILESTORECATEGORY does not exist" + + if [ -z "$NOVERSIONING" ]; then + # Wipe even encrypted file securely + $WIPE $filepath && \ + touch $filepath && $VERSIONCOMMIT && \ + $VERSIONDEL $filepath && $VERSIONCOMMIT + [ ! -z "$VERSIONPUSH" ] && $VERSIONPUSH + else + $WIPE $filepath + fi + fi +} + +function fwipe () { + [ -z $1 ] && error Missing argument + $WIPE $CWD/$1 +} + +function pwhelp () { + info $(pwgrep_version) + info Possible operations are: +cat < - Wiping a file + pwdbls - Listing available DBs + pwedit [OPTS] - Editing current DB + pwfadd - Adding a file to FDB + pwfcat - Printing a file from filestore to stdout + pwfdel - Deleting a file from filestore + pwgrep [OPTS] - Grepping current DB + pwldb - Synonym for pwdbls + pwupdate - Updating FDB and all DBs + pwhelp - Printing this help screen +Where OPTS are: + -o - Offline mode + -d - Using a specific DB + -a - Searching all available DBs or categories at once +END +} + +setawkcmd +setsedcmd +setwipecmd + +configure + +CWD=$(pwd) +#umask 177 + +cd $WORKDIR || error "No such file or directory: $WORKDIR" + +BASENAME=$(basename $0) +ARGS=$@ + +function set_opts () { + case $ARGS in + -o*) + # Offlinemode + NOVERSIONING=1 + ARGS=${ARGS[@]:2} + set_opts + ;; + + -d*) + # Alternate DB + DB=$(echo $ARGS | $AWK '{ print $2 }') + FILESTORECATEGORY=$DB + USEFILESTORECATEGORY=1 + ARGS=$(echo $ARGS | $SED "s/-d $DB//") + DB=$DB.gpg + set_opts + ;; + + -a*) + # All DBs at once + which gpg-agent + if [ $? == "0" ]; then + ALL=1 + ARGS=${ARGS[@]:2} + set_opts + else + error You need gpg-agent installed + fi + ;; + + *) + esac +} + +set_opts $ARGS +FULLFILESTORE=$FILESTOREDIR/$FILESTORECATEGORY +FILESTOREWORKDIR=$WORKDIR/$FULLFILESTORE + +case $BASENAME in + pwgrep) + pwgrep $ARGS + ;; + pwupdate) + pwupdate + ;; + pwedit) + pwedit + ;; + pwdbls) + pwdbls + ;; + pwldb) + pwdbls + ;; + pwfls) + pwfls $ARGS + ;; + pwfcat) + pwfcat $ARGS + ;; + pwfadd) + pwfadd $ARGS + ;; + pwfdel) + pwfdel $ARGS + ;; + fwipe) + fwipe $ARGS + ;; + *) + pwhelp + ;; +esac + diff --git a/create-symlinks.sh b/create-symlinks.sh deleted file mode 100755 index 4270052..0000000 --- a/create-symlinks.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -mkdir -p ~bin - -ln -s $(pwd)/pwgrep.sh ~/bin/fwipe -ln -s $(pwd)/pwgrep.sh ~/bin/pwdbls -ln -s $(pwd)/pwgrep.sh ~/bin/pwedit -ln -s $(pwd)/pwgrep.sh ~/bin/pwfadd -ln -s $(pwd)/pwgrep.sh ~/bin/pwfcat -ln -s $(pwd)/pwgrep.sh ~/bin/pwfdel -ln -s $(pwd)/pwgrep.sh ~/bin/pwfls -ln -s $(pwd)/pwgrep.sh ~/bin/pwgrep -ln -s $(pwd)/pwgrep.sh ~/bin/pwhelp -ln -s $(pwd)/pwgrep.sh ~/bin/pwldb -ln -s $(pwd)/pwgrep.sh ~/bin/pwupdate diff --git a/debian/changelog b/debian/changelog index 53ebeb6..d928c9d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,5 +1,97 @@ -pwgrep (0.0.0.0) stable; urgency=low +pwgrep (0.8.3.0) stable; urgency=low + + * Initial version of the debian Package. + * All old change logs not in debian forma so far: + + Sat Mar 23 22:49:10 CET 2013 + * Change RCS from SVN to GIT as default. + * Added some GIT tweaks. + * Released 0.8.2 + + Sun Mar 10 12:08:16 CET 2013 + * Fix code indention + + Sun Mar 10 11:57:15 CET 2013 + * Released 0.8.1 + + Sun Mar 10 11:47:47 CET 2013 + * Moved source to git + + Mon Oct 3 22:33:50 CEST 2011 + * Some bugfixes + * Some minor code refactoring + + So 12. Jun 11:51:43 CEST 2011 + * Filestore has now categories + * Renamed lots of variables + + So 15. Mai 15:26:56 CEST 2011 + * Added initial README file + + Fri Jan 14 18:06:57 CET 2011 + * pwhelp prints now pwgrep version + * Using -devel postfix instead of -pre-X for dev versions + + Mo 3. Jan 08:04:13 CET 2011 - v0.8.1-pre-1 + * Initial new version made + + Mo 3. Jan 07:41:13 CET 2011 + * Tagged v0.8.0 + * Since pwgrep consinsts of very small updates only no more branches + except of trunk are used from now on. + + Mi 22. Dez 12:40:10 CET 2010 - v0.8-pre-4 + * Added option -a which searches all available databases at once. + This feature needs gpg-agent installed. Otherwise the gpg key passphrase + needs to be entered for each file separately . + * Some bugfix (using -z "$VAR" instead of -z $VAR) + + Mi 22. Dez 11:49:33 CET 2010 - v0.8-pre-3 + * Added WISHLIST file + + Fri Dec 10 14:22:04 CET 2010 - v0.8-pre-2 + * Set default db to private.gpg + + Fri Nov 19 22:05:27 CET 2010 - v0.8-pre-1 + * Added create-symlinks.sh + + Sun Nov 7 22:37:21 CET 2010 + * Released 0.7.0 + + Sat Oct 16 10:48:59 CEST 2010 - v0.7-pre-3 + * Added ~/.pwgreprc as default configuration file + + Mon Sep 27 22:43:23 CEST 2010 - v0.7-pre-2 + * Set SVN_EDITOR="ex -c 1" as default + + Sun Sep 19 12:29:06 CEST 2010 - v0.7-pre-1 + * New format of the CHANGELOG.txt (it's not GNU style) + * No VERSIONUPDATE on pwgrep, pwfls, pwfcat, pwdbls anymore + * Introduced new command pwupdate which will check out the newest version + from the repository. + * Introduced new command pwhelp which prints out a help screen + + Tue Sep 7 20:41:04 CEST 2010 + * v0.6 release branched + + Fri Jul 30 23:31:12 CEST 2010 - v0.5-pre-3 + * New command pwdbls, which lists all databases available. + * pwldb is a synonym for pwdbls. Changed the default database name + (database.gpg => mydb.gpg) + + Wed Jul 28 18:44:03 CEST 2010 - v0.5-pre-2 + * New option -d DATABASE, so its multi database capable now + + Wed Jul 28 18:16:09 CEST 2010 - v0.5-pre-1 + * pwfcat redirects all informational message to stderr. means + pwfcat includes no informational messages in stdout of pwgrep itself + anymore. Usefull for piping the content do another process or for + redirecting it into a file. + + Sun Jul 18 10:10:29 CEST 2010 v0.5-pre-0 + * Offlinemode support (Option -o) which does not use the versioning system + (usable if there is no internet connection available + atm). e.g. "pwgrep -o pwgrepbar" - * Initial version of the template -- Paul Buetow Fri, 04 Jan 2013 07:53:32 +0100 diff --git a/pwgrep.sh b/pwgrep.sh deleted file mode 100755 index b9d1edc..0000000 --- a/pwgrep.sh +++ /dev/null @@ -1,415 +0,0 @@ -#!/bin/bash - -# pwgrep v0.8.2 (c) 2009, 2010, 2011, 2013 by Paul Buetow -# pwgrep helps you to manage all your passwords using GnuGP -# for encryption and a versioning system (subversion by default) -# for keeping track all changes of your password database. In -# combination to GnuPG you should use the versioning system in -# combination with SSL or SSH encryption. - -# If you are using a *BSD, you may want to edit the shebang line. -# -# Usage: -# -# Searching for a database value: -# ./pwgrep.sh searchstring -# -# Editing the database (same but without args): -# ./pwgrep.sh -# -# For more reasonable commands the following symlinks are recommended. -# Take a look at the create-symlinks.sh script. - -# You can overwrite the default values by setting env. variables -# or by just editing this file. -DEFAULTDB=private.gpg -DEFAULTFILESTOREDIR=filestore -DEFAULTFILESTORECATEGORY=default -[ -z "$RCFILE" ] && RCFILE=~/.pwgreprc - -# Only use mawk or gawk, but if possible not nawk. On *BSD awk=nawk. So try -# awk/nawk last. You can use nawk but nawk will not match case insensitive. -[ -z "$TRYAWKLIST" ] && TRYAWKLIST="mawk gawk awk nawk" -# Find the correct command to wipe temporaly files after usage -[ -z "$TRYWIPELIST" ] && TRYWIPELIST="destroy shred" -# Same for sed -[ -z "$TRYSEDLIST" ] && TRYSEDLIST="sed gsed" - -# From here, do not change stuff! You may edit the content of the file $RCFILE! - -function source_config () { - [ -f $RCFILE ] && source <($SED 's/^/export /' $RCFILE) -} - -function pwgrep_version () { - sed -n '/# pwgrep v/ { s/# //; p; q; }' $0 -} - -function configure () { - # Reading the current configuration - source_config - - # Setting default values if not set in the configuration file already - ( - #[ -z "$SVN_EDITOR" ] && echo 'export SVN_EDITOR="ex -c 1"' - [ -z "$GIT_EDITOR" ] && echo 'export GIT_EDITOR=vim' - [ -z "$DB" ] && echo DB=$DEFAULTDB - [ -z "$FILESTOREDIR" ] && echo export FILESTOREDIR=$DEFAULTFILESTOREDIR - [ -z "$FILESTORECATEGORY" ] && echo export FILESTORECATEGORY=$DEFAULTFILESTORECATEGORY - - # The PWGREPWORDIR should be in its own versioning repository. - # For password revisions. - [ -z "$WORKDIR" ] && echo export WORKDIR=~/git/pwdb - - # Enter here your GnuPG key ID - [ -z "$GPGKEYID" ] && echo export GPGKEYID=37EC5C1D - - # Customizing the versioning commands (i.e. if you want to use another - # versioning system). - [ -z "$VERSIONCOMMIT" ] && echo 'export VERSIONCOMMIT="git commit -a"' - [ -z "$VERSIONUPDATE" ] && echo 'export VERSIONUPDATE="git pull origin master"' - [ -z "$VERSIONPUSH" ] && echo 'export VERSIONPUSH="git push origin master"' - [ -z "$VERSIONADD" ] && echo 'export VERSIONADD="git add"' - [ -z "$VERSIONDEL" ] && echo 'export VERSIONDEL="git rm"' - ) >> $RCFILE - - # Re-reading the current configuration, because there might be new - # variables by now - source_config -} - -function out () { - echo "$@" 1>&2 -} - -function info () { - out "=====> $@" -} - -function error () { - echo "ERROR: $@" - exit 666 -} - -function findbin () { - local -r trylist=$1 - found="" - for bin in $trylist; do - if [ -z $found ]; then - which=$(which $bin) - [ ! -z $which ] && found=$bin - fi - done - - echo $found -} - -function setawkcmd () { - AWK=$(findbin "$TRYAWKLIST") - [ -z $AWK ] && error No awk found in $PATH -} - -function setsedcmd () { - SED=$(findbin "$TRYSEDLIST") - [ -z $SED ] && error No sed found in $PATH -} - -function setwipecmd () { - WIPE=$(findbin "$TRYWIPELIST") - - if [ -z $WIPE ]; then - # FreeBSDs rm includes -P which is secure enough - if [ $(uname) = 'FreBSD' ]; then - WIPE="rm -v -P" - else - error "No wipe command found in $PATH, please install shred or destroy" - fi - fi - - info Using $WIPE for secure file deletion -} - -function pwgrep () { - local -r search=$1 - local -a dbs=() - - if [ -z "$ALL" ]; then - dbs=$DB - else - dbs=$(_pwdbls | sed 's/$/.gpg/') - fi - - for db in $dbs; do - info Searching for $search in $db - gpg --use-agent --decrypt $db | $AWK -v search="$search" ' - BEGIN { - flag=0 - IGNORECASE=1 - } - !/^\t/ { - if (!flag && $0 ~ search) { - flag=1 - print $0 - } else if (flag && $0 ~ search) { - print $0 - } else if (flag) { - flag=0 - } - } /^\t/ && flag { - print $0 - }' - done -} - -function pwupdate () { - if [ -z "$NOVERSIONING" ]; then - info Updating repository - $VERSIONUPDATE 2>&1 >/dev/null - fi -} - -function pwedit () { - pwupdate - cp -vp $DB $DB.$(date +'%s').snap && \ - gpg --decrypt $DB > .database && \ - vim --cmd 'set noswapfile' --cmd 'set nobackup' \ - --cmd 'set nowritebackup' .database && \ - gpg --output .$DB -e -r $GPGKEYID .database && \ - $WIPE .database && \ - mv .$DB $DB && \ - [ -z "$NOVERSIONING" ] && $VERSIONCOMMIT && [ ! -z "$VERSIONPUSH" ] && $VERSIONPUSH -} - -function _pwdbls () { - ls *.gpg | sed 's/\.gpg$//' -} - -function pwdbls () { - echo Available Databases: - _pwdbls - echo Current database: $DB -} - -function pwfls () { - local arg=$1 - - if [ "$ALL" = "1" ]; then - ALL=0 - local -r dir=$WORKDIR/$FILESTOREDIR - [ ! -e $dir ] && error $dir does not exist - - info Showing all categories - ls $dir | while read store; do - pwfls $store - done - else - local dir=$WORKDIR/$FILESTOREDIR - - if [ -z "$USEFILESTORECATEGORY" ]; then - info Available file store categories: - dir=$WORKDIR/$FILESTOREDIR - info "(You may use '`basename $0` -d ' to display containing files.)" - else - info Available files in store $FILESTORECATEGORY - dir=$WORKDIR/$FILESTOREDIR/$FILESTORECATEGORY - fi - - [ ! -e $dir ] && error "Category ($dir) does not exist" - ls $dir - fi -} - -function pwfcat () { - local arg=$1 - - if [ -z "$arg" ]; then - error "No file specified (hint: use pwfls)" - - else - local -r dir=$WORKDIR/$FILESTOREDIR/$FILESTORECATEGORY - local -r file=$(echo $arg | sed 's/.gpg$//') - - [ ! -e $dir ] && error "Category $FILESTORECATEGORY ($dir) does not exist" - [ ! -e $dir/$file.gpg ] && error "File $file in category $FILESTORECATEGORY does not exist" - gpg --decrypt $dir/$file.gpg - fi -} - -function pwfadd () { - local -r name=$(echo $1 | sed 's/.gpg$//') - local srcfile=$1 - local outfile='' - - if [ $(echo "$srcfile" | grep -v '^/') ]; then - srcfile=$CWD/$srcfile - fi - - if [ ! -z $2 ]; then - outfile=$(basename $2) - else - outfile=$(basename $name) - fi - - pwupdate - - [ -z "$name" ] && error Missing argument - if [ ! -e $FULLFILESTORE ]; then - info Creating new category - [ ! -z "$NOVERSIONING" ] && error Cannot add new category with versioning disabled - local -r umaskbackup=$(umask) - umask 0022 - mkdir $FULLFILESTORE && $VERSIONADD $FULLFILESTORE && $VERSIONCOMMIT && [ ! -z "$VERSIONPUSH" ] && $VERSIONPUSH - - umask $umaskbackup - fi - - [ ! -e $FILESTOREWORKDIR ] && error $FILESTOREWORKDIR does not exist - gpg --output $FULLFILESTORE/$outfile.gpg -e -r $GPGKEYID $srcfile && \ - - if [ -z "$NOVERSIONING" ]; then - $VERSIONADD $FULLFILESTORE/$outfile.gpg && $VERSIONCOMMIT && [ ! -z "$VERSIONPUSH" ] && $VERSIONPUSH - - fi -} - -function pwfdel () { - local arg=$1 - - if [ -z "$arg" ]; then - error "No file specified (hint: use pwfls)" - - else - local -r dir=$WORKDIR/$FILESTOREDIR/$FILESTORECATEGORY - local -r file=$(echo $arg | sed 's/.gpg$//') - local -r filepath=$dir/$file.gpg - - [ ! -e $dir ] && error "Category $FILESTORECATEGORY ($dir) does not exist" - [ ! -e $filepath ] && error "File $file in category $FILESTORECATEGORY does not exist" - - if [ -z "$NOVERSIONING" ]; then - # Wipe even encrypted file securely - $WIPE $filepath && \ - touch $filepath && $VERSIONCOMMIT && \ - $VERSIONDEL $filepath && $VERSIONCOMMIT - [ ! -z "$VERSIONPUSH" ] && $VERSIONPUSH - else - $WIPE $filepath - fi - fi -} - -function fwipe () { - [ -z $1 ] && error Missing argument - $WIPE $CWD/$1 -} - -function pwhelp () { - info $(pwgrep_version) - info Possible operations are: -cat < - Wiping a file - pwdbls - Listing available DBs - pwedit [OPTS] - Editing current DB - pwfadd - Adding a file to FDB - pwfcat - Printing a file from filestore to stdout - pwfdel - Deleting a file from filestore - pwgrep [OPTS] - Grepping current DB - pwldb - Synonym for pwdbls - pwupdate - Updating FDB and all DBs - pwhelp - Printing this help screen -Where OPTS are: - -o - Offline mode - -d - Using a specific DB - -a - Searching all available DBs or categories at once -END -} - -setawkcmd -setsedcmd -setwipecmd - -configure - -CWD=$(pwd) -#umask 177 - -cd $WORKDIR || error "No such file or directory: $WORKDIR" - -BASENAME=$(basename $0) -ARGS=$@ - -function set_opts () { - case $ARGS in - -o*) - # Offlinemode - NOVERSIONING=1 - ARGS=${ARGS[@]:2} - set_opts - ;; - - -d*) - # Alternate DB - DB=$(echo $ARGS | $AWK '{ print $2 }') - FILESTORECATEGORY=$DB - USEFILESTORECATEGORY=1 - ARGS=$(echo $ARGS | $SED "s/-d $DB//") - DB=$DB.gpg - set_opts - ;; - - -a*) - # All DBs at once - which gpg-agent - if [ $? == "0" ]; then - ALL=1 - ARGS=${ARGS[@]:2} - set_opts - else - error You need gpg-agent installed - fi - ;; - - *) - esac -} - -set_opts $ARGS -FULLFILESTORE=$FILESTOREDIR/$FILESTORECATEGORY -FILESTOREWORKDIR=$WORKDIR/$FULLFILESTORE - -case $BASENAME in - pwgrep) - pwgrep $ARGS - ;; - pwupdate) - pwupdate - ;; - pwedit) - pwedit - ;; - pwdbls) - pwdbls - ;; - pwldb) - pwdbls - ;; - pwfls) - pwfls $ARGS - ;; - pwfcat) - pwfcat $ARGS - ;; - pwfadd) - pwfadd $ARGS - ;; - pwfdel) - pwfdel $ARGS - ;; - fwipe) - fwipe $ARGS - ;; - *) - pwhelp - ;; -esac - -- cgit v1.2.3