run.sh (3800B)
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 type locale >/dev/null 2>&1; then 47 CMAP="$(locale charmap)" 48 if [ "${CMAP}" = "UTF-8" ]; then 49 TREE_I='│ ' 50 TREE_T='├─ ' 51 TREE_L='└─ ' 52 fi 53 unset CMAP 54 fi 55 56 ### Terminal color support 57 BOLD_TEXT="" 58 NORMAL_TEXT="" 59 RED_TEXT="" 60 BLUE_TEXT="" 61 UNDERLINE_TEXT="" 62 NO_UNDERLINE_TEXT="" 63 if [ -n "${CLICOLOR-}" ]; then 64 BOLD_TEXT="$(printf '\033[1m')" 65 NORMAL_TEXT="$(printf '\033[0m')" 66 RED_TEXT="$(printf '\033[31m')" 67 BLUE_TEXT="$(printf '\033[34m')" 68 UNDERLINE_TEXT="$(printf '\033[4m')" 69 NO_UNDERLINE_TEXT="$(printf '\033[24m')" 70 fi 71 72 ### Git environment clean-up 73 unset GIT_DIR 74 unset GIT_WORK_TREE 75 unset GIT_NAMESPACE 76 unset GIT_INDEX_FILE 77 unset GIT_INDEX_VERSION 78 unset GIT_OBJECT_DIRECTORY 79 unset GIT_COMMON_DIR 80 export GIT_CEILING_DIRECTORIES="${PREFIX}/.." 81 82 ########### 83 # IMPORTS # 84 ########### 85 86 : "${PASHAGE_SRC_DIR:=$(dirname "$0")}" 87 PLATFORM="$(uname | tr '[:upper:]' '[:lower:]')" 88 . "${PASHAGE_SRC_DIR}/platform-${PLATFORM%%_*}.sh" 89 . "${PASHAGE_SRC_DIR}/pashage.sh" 90 91 ############ 92 # DISPATCH # 93 ############ 94 95 PROGRAM="$0" 96 COMMAND="${1-}" 97 umask "${PASSWORD_STORE_UMASK:-077}" 98 99 case "${COMMAND}" in 100 copy|cp) shift; cmd_copy "$@" ;; 101 delete) shift; cmd_delete "$@" ;; 102 edit) shift; cmd_edit "$@" ;; 103 find) shift; cmd_find "$@" ;; 104 gen) shift; cmd_generate "$@" ;; 105 generate) shift; cmd_generate "$@" ;; 106 git) shift; cmd_git "$@" ;; 107 gitconfig) shift; cmd_gitconfig ;; 108 grep) shift; cmd_grep "$@" ;; 109 help) shift; cmd_help ;; 110 -h) shift; cmd_help ;; 111 --help) shift; cmd_help ;; 112 init) shift; cmd_init "$@" ;; 113 insert) shift; cmd_insert "$@" ;; 114 list) shift; cmd_list_or_show "$@" ;; 115 ls) shift; cmd_list_or_show "$@" ;; 116 move|mv) shift; cmd_move "$@" ;; 117 random) shift; cmd_random "$@" ;; 118 re-encrypt) shift; cmd_reencrypt "$@" ;; 119 reencrypt) shift; cmd_reencrypt "$@" ;; 120 remove) shift; cmd_delete "$@" ;; 121 rm) shift; cmd_delete "$@" ;; 122 show) shift; cmd_list_or_show "$@" ;; 123 --version) shift; cmd_version ;; 124 version) shift; cmd_version ;; 125 *) cmd_list_or_show "$@" ;; 126 esac