diff --git a/LICENSE b/LICENSE deleted file mode 100644 index ce03a47..0000000 --- a/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2024 RSHOP - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/README.md b/README.md index 9a26fd8..71a997b 100644 --- a/README.md +++ b/README.md @@ -1 +1,17 @@ -# homebrew-pass \ No newline at end of file +# pass + +Simplified access to passbolt CLI. + +## Configuration + +Create a configuration file `~/.ssh/passbolt.json` by running: + +```bash +passbolt configure --config ~/.ssh/passbolt.json --serverAddress https://passbolt-instance --userPassword '1234' --userPrivateKeyFile 'keys/privatekey.asc' +``` + +## Usage + +```bash +pass "SEARCH TERM" +``` diff --git a/pass b/pass new file mode 100755 index 0000000..ecb9fc9 --- /dev/null +++ b/pass @@ -0,0 +1,67 @@ +#!/bin/bash + +music_file="$(brew --prefix)/share/pass/passbolt.mp3" + +# Function to stop music +finish() { + if [ -n "$music_pid" ]; then + kill "$music_pid" > /dev/null 2>&1 + exit 0 + fi +} + +afplay $music_file & +music_pid=$! + +# Trap Ctrl+C (SIGINT) and stop the music before exiting +trap finish INT + +# List resources with the given search string in Name or Username +result=$(passbolt --config ~/.ssh/passbolt.json list resource --filter "matches(Name, '(?i)$1') || matches(Username, '(?i)$1')") + +# Check if result is empty +if [ -z "$result" ]; then + printf "\n\033[30m\033[41m\033[1mNo resource found!\033[0m\n\n" + finish +fi + +printf '\n\033[35m ██▓███ ▄▄▄ ██████ ▄▄▄▄ ▒█████ ██▓ ▄▄▄█████▓ ▐██▌ \n ▓██░ ██▒▒████▄ ▒██ ▒ ██████ ▓█████▄ ▒██▒ ██▒▓██▒ ▓ ██▒ ▓▒ ▐██▌ \n ▓██░ ██▓▒▒██ ▀█▄ ░ ▓██▄ ▒██ ▒ ▒██▒ ▄██▒██░ ██▒▒██░ ▒ ▓██░ ▒░ ▐██▌ \n ▒██▄█▓▒ ▒░██▄▄▄▄██ ▒ ██░ ▓██▄ ▒▒██░█▀ ▒██ ██░▒██░ ░ ▓██▓ ░ ▓██▒ \n ▒██▒ ░ ░ ▓█ ▓██▒▒██████▒ ▒ ██▒░▓█ ▀█▓░ ████▓▒░░██████▒▒██▒ ░ ▒▄▄ \n ▒▓▒░ ░ ░ ▒▒ ▓▒█░▒ ▒▓▒ ▒ ▒██████▒░░▒▓███▀▒░ ▒░▒░▒░ ░ ▒░▓ ░▒ ░░ ░▀▀▒ \n ░▒ ░ ▒ ▒▒ ░░ ░▒ ░ ▒ ▒▓▒ ▒ ░▒░▒ ░ ░ ▒ ▒░ ░ ░ ▒ ░ ░ ░ ░ \n ░░ ░ ▒ ░ ░ ░ ░▒ ░ ░ ░ ░ ░ ░ ▒ ░ ░ ░ ░ \n ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ \033[0m\n\n' + +# Check if any resource is found +count=$(echo "$result" | awk 'NR>1 && NF {count++} END {print count}') + +if [ "$count" -eq 0 ]; then + finish + +elif [ "$count" -eq 1 ]; then + printf "$result\n" | awk 'BEGIN {FS="|"; HFS=" "; OFS="\033[0m\033[2m\033[90m | \033[0m\033[97m"} NR==1 {print "\n \033[0m\033[2m\033[90m\033[3m" $3 HFS $4 HFS $5 "\033[0m"} NR>1 && NF {print " \033[1m\033[35m" NR-1 " \033[0m\033[97m\033[1m" $3 OFS $4 OFS $5 "\033[0m\n"}' + + # Only one resource found, obtain it + resource_id=$(echo "$result" | awk -v n="1" 'NR==n+1 {print $1}') + +else + # Multiple resources found, list them and let the user choose + printf "$result\n" | awk 'BEGIN {FS="|"; HFS=" "; OFS="\033[0m\033[2m\033[90m | \033[0m\033[97m"} NR==1 {print "\n \033[0m\033[2m\033[90m\033[3m" $3 HFS $4 HFS $5 "\033[0m"} NR>1 && NF {print " \033[1m\033[35m" NR-1 " \033[0m\033[97m\033[1m" $3 OFS $4 OFS $5 "\033[0m"}' + + # Prompt user to choose a number + read -p $'\n\e[35m\e[1m Enter the number of resource: \033[7m' selected + printf '\033[0m\n' + + # Validate user input + if ! [[ "$selected" =~ ^[0-9]+$ ]] || [ "$selected" -lt "1" ] || [ "$selected" -gt "$count" ]; then + printf " \033[30m\033[41m\033[1mInvalid input. Please enter a valid number!\033[0m\n\n" + finish + fi + + # Get the resource ID based on user's choice + resource_id=$(echo "$result" | awk -v n="$selected" 'NR==n+1 {print $1}') +fi + +# Obtain the selected resource and get the password +password=$(passbolt --config ~/.ssh/passbolt.json get resource --id "$resource_id" | awk -F: '/Password/ {printf $2}' | tr -d '[:space:]' | tr -d '\n') + +# Copy the password to the clipboard +echo "$password" | pbcopy + +printf " \033[1m\033[42mPassword copied to clipboard!\033[0m\n\n" +finish diff --git a/passbolt.mp3 b/passbolt.mp3 new file mode 100644 index 0000000..bcbea53 Binary files /dev/null and b/passbolt.mp3 differ