pashage

Yet Another Opinionated Re-engineering of the Unix Password Store
git clone https://git.instinctive.eu/pashage.git
Log | Files | Refs | README | LICENSE

run.sh (3759B)


      1 #!/bin/sh
      2 # pashage - age-backed POSIX password manager
      3 # Copyright (C) 2024  Natasha Kerensikova
      4 #
      5 # This program is free software; you can redistribute it and/or
      6 # modify it under the terms of the GNU General Public License
      7 # as published by the Free Software Foundation; either version 2
      8 # of the License, or (at your option) any later version.
      9 #
     10 # This program is distributed in the hope that it will be useful,
     11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 # GNU General Public License for more details.
     14 #
     15 # You should have received a copy of the GNU General Public License
     16 # along with this program; if not, write to the Free Software
     17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     18 
     19 # Set pipefail if it works in a subshell, disregard if unsupported
     20 # shellcheck disable=SC3040
     21 (set -o pipefail 2> /dev/null) && set -o pipefail
     22 set -Cue
     23 set +x
     24 
     25 #################
     26 # CONFIGURATION #
     27 #################
     28 
     29 ### Pashage/passage specific configuration
     30 AGE="${PASHAGE_AGE:-${PASSAGE_AGE:-age}}"
     31 IDENTITIES_FILE="${PASHAGE_IDENTITIES_FILE:-${PASSAGE_IDENTITIES_FILE:-${HOME}/.passage/identities}}"
     32 PREFIX="${PASHAGE_DIR:-${PASSAGE_DIR:-${PASSWORD_STORE_DIR:-${HOME}/.passage/store}}}"
     33 
     34 ### Configuration inherited from password-store
     35 CHARACTER_SET="${PASSWORD_STORE_CHARACTER_SET:-[:punct:][:alnum:]}"
     36 CHARACTER_SET_NO_SYMBOLS="${PASSWORD_STORE_CHARACTER_SET_NO_SYMBOLS:-[:alnum:]}"
     37 CLIP_TIME="${PASSWORD_STORE_CLIP_TIME:-45}"
     38 GENERATED_LENGTH="${PASSWORD_STORE_GENERATED_LENGTH:-25}"
     39 X_SELECTION="${PASSWORD_STORE_X_SELECTION:-clipboard}"
     40 
     41 ### UTF-8 or ASCII tree
     42 TREE__='   '
     43 TREE_I='|  '
     44 TREE_T='|- '
     45 TREE_L='`- '
     46 if [ -n "${LC_CTYPE-}" ] && ! [ "${LC_CTYPE}" = "${LC_CTYPE#*UTF}" ]; then
     47 	TREE_I='│  '
     48 	TREE_T='├─ '
     49 	TREE_L='└─ '
     50 fi
     51 
     52 ### Terminal color support
     53 BOLD_TEXT=""
     54 NORMAL_TEXT=""
     55 RED_TEXT=""
     56 BLUE_TEXT=""
     57 UNDERLINE_TEXT=""
     58 NO_UNDERLINE_TEXT=""
     59 if [ -n "${CLICOLOR-}" ]; then
     60 	BOLD_TEXT="$(printf '\033[1m')"
     61 	NORMAL_TEXT="$(printf '\033[0m')"
     62 	RED_TEXT="$(printf '\033[31m')"
     63 	BLUE_TEXT="$(printf '\033[34m')"
     64 	UNDERLINE_TEXT="$(printf '\033[4m')"
     65 	NO_UNDERLINE_TEXT="$(printf '\033[24m')"
     66 fi
     67 
     68 ### Git environment clean-up
     69 unset GIT_DIR
     70 unset GIT_WORK_TREE
     71 unset GIT_NAMESPACE
     72 unset GIT_INDEX_FILE
     73 unset GIT_INDEX_VERSION
     74 unset GIT_OBJECT_DIRECTORY
     75 unset GIT_COMMON_DIR
     76 export GIT_CEILING_DIRECTORIES="${PREFIX}/.."
     77 
     78 ###########
     79 # IMPORTS #
     80 ###########
     81 
     82 : "${PASHAGE_SRC_DIR:=$(dirname "$0")}"
     83 PLATFORM="$(uname | tr '[:upper:]' '[:lower:]')"
     84 . "${PASHAGE_SRC_DIR}/platform-${PLATFORM%%_*}.sh"
     85 . "${PASHAGE_SRC_DIR}/pashage.sh"
     86 
     87 ############
     88 # DISPATCH #
     89 ############
     90 
     91 PROGRAM="$0"
     92 COMMAND="${1-}"
     93 umask "${PASSWORD_STORE_UMASK:-077}"
     94 
     95 case "${COMMAND}" in
     96     copy|cp)	shift; cmd_copy "$@" ;;
     97     delete)	shift; cmd_delete "$@" ;;
     98     edit)	shift; cmd_edit "$@" ;;
     99     find)	shift; cmd_find "$@" ;;
    100     gen)	shift; cmd_generate "$@" ;;
    101     generate)	shift; cmd_generate "$@" ;;
    102     git)	shift; cmd_git "$@" ;;
    103     gitconfig)	shift; cmd_gitconfig ;;
    104     grep)	shift; cmd_grep "$@" ;;
    105     help)	shift; cmd_help ;;
    106     -h)		shift; cmd_help ;;
    107     --help)	shift; cmd_help ;;
    108     init)	shift; cmd_init "$@" ;;
    109     insert)	shift; cmd_insert "$@" ;;
    110     list)	shift; cmd_list_or_show "$@" ;;
    111     ls)		shift; cmd_list_or_show "$@" ;;
    112     move|mv)	shift; cmd_move "$@" ;;
    113     random)	shift; cmd_random "$@" ;;
    114     re-encrypt)	shift; cmd_reencrypt "$@" ;;
    115     reencrypt)	shift; cmd_reencrypt "$@" ;;
    116     remove)	shift; cmd_delete "$@" ;;
    117     rm)		shift; cmd_delete "$@" ;;
    118     show)	shift; cmd_list_or_show "$@" ;;
    119     --version)	shift; cmd_version ;;
    120     version)	shift; cmd_version ;;
    121     *)		       cmd_list_or_show "$@" ;;
    122 esac