From fdb2ed3606877ecfb066f19869c19ba408dc1ca8 Mon Sep 17 00:00:00 2001 From: Jonathan Hodgson Date: Tue, 29 Oct 2019 13:50:18 +0000 Subject: [PATCH] Change some scripts a bit --- bin/.bin/dmenu/password-manager | 43 ++++++++++++++++++++++ bin/.bin/download | 11 ++++-- bin/.bin/nmap/nmapAutomator | 2 - bin/.bin/project-management/project-hosts | 43 ++++++++++++++++++++++ bin/.bin/project-management/project-switch | 2 + 5 files changed, 96 insertions(+), 5 deletions(-) create mode 100755 bin/.bin/dmenu/password-manager diff --git a/bin/.bin/dmenu/password-manager b/bin/.bin/dmenu/password-manager new file mode 100755 index 00000000..4ee18abe --- /dev/null +++ b/bin/.bin/dmenu/password-manager @@ -0,0 +1,43 @@ +#!/usr/bin/env bash + +PASSWORDS="$HOME/.password-store" + + +function copy_password(){ + local password="$1" + local sleep_argv0="jh password store sleep on display $DISPLAY" + local before="$(xclip -o -selection clipboard 2>/dev/null | base64)" + pkill -f "^$sleep_argv0" 2>/dev/null && sleep 0.5 + local pw=$(pass "$selection" | head -n 1) + echo "$pw" | xclip -selection "primary" + echo "$pw" | xclip -selection "clipboard" + notify-send "Password put on clipboard" "Will be removed in 10 seconds" + ( + ( exec -a "$sleep_argv0" bash <<<"trap 'kill %1' TERM; sleep '10' & wait" ) + + echo "$before" | base64 -d | xclip -selection "primary" + echo "$before" | base64 -d | xclip -selection "clipboard" + + notify-send "Password Clearerd" + + ) >/dev/null 2>&1 & disown +} + +if [ -d "$PASSWORDS" ]; then + cd "$PASSWORDS" + selection=$((echo "NEW";find . -type f -name '*.gpg' | sed 's/.gpg$//' | sed 's/^.\///') | rofi -dmenu -i -l 20) + if [ -n "$selection" ]; then + if [[ "$selection" == "NEW" ]]; then + dir="$(find . -type d -not -path \*.git\* |rofi -dmenu -p Directory | sed 's/^.\/?//')" + if [ ! -d "$dir" ]; then + mkdir -p "$dir" + fi + name="$(rofi -dmenu -p Name -lines 0)" + # Todo - create new passwords + else + copy_password "$selection" + fi + fi +else + notify-send "$BOOKMARKS doesn't exist" +fi diff --git a/bin/.bin/download b/bin/.bin/download index 304dba48..6f3cd95d 100755 --- a/bin/.bin/download +++ b/bin/.bin/download @@ -10,13 +10,14 @@ if [[ "$1" = "surf-download" ]]; then url="$4" fi -path="~/Downloads/" +path="$HOME/Downloads/" project=$(project current --path) if [ -n "$project" ]; then path="$project/Downloads/" fi -mkcd -p "$path" + +mkdir -p "$path" cd "$path" echo "$useragent" @@ -24,4 +25,8 @@ echo "$cookiefile" echo "$referer" echo "$url" -curl -g -L -J -O -A "$useragent" -b "$cookiefile" -c "$cookiefile" -e "$referer" "$url" +if command -v aria2c; then + aria2c -U "$useragent" --referer "$referer" --load-cookies $cookiefile --save-cookies $cookiefile "$url" +else + curl -k -g -L -J -O -A "$useragent" -b "$cookiefile" -c "$cookiefile" -e "$referer" "$url" +fi diff --git a/bin/.bin/nmap/nmapAutomator b/bin/.bin/nmap/nmapAutomator index bf507a69..6eefaeb2 100755 --- a/bin/.bin/nmap/nmapAutomator +++ b/bin/.bin/nmap/nmapAutomator @@ -1,6 +1,4 @@ #!/bin/bash -# Came from here: https://raw.githubusercontent.com/21y4d/nmapAutomator/master/nmapAutomator.sh -#by 21y4d RED='\033[0;31m' YELLOW='\033[0;33m' diff --git a/bin/.bin/project-management/project-hosts b/bin/.bin/project-management/project-hosts index bd441a6a..15b12086 100755 --- a/bin/.bin/project-management/project-hosts +++ b/bin/.bin/project-management/project-hosts @@ -19,6 +19,36 @@ function listhosts(){ fi } +function get_hosts(){ + local current="$(project current --path)" + index="$current/index.yaml" + if [ ! -f "$index" ]; then + echo "" + exit 0 + fi + if [ $(yq -r '.hosts | length ' "$index" ) -gt 0 ]; then + yq -r '.hosts[]| select(.domain) | [.ip, .domain ] | join(",,")' "$index" | tr ',' '\t' + else + echo "" + exit 0 + fi +} + +function host_file(){ + + sed '/# Project specific hosts/,$ d' /etc/hosts > /tmp/newhosts + cat /tmp/newhosts > /etc/hosts + rm /tmp/newhosts + + local current="$(project current --path)" + if [ -n "$current" ]; then + ( + echo "# Project specific hosts - Everything after this line will be deleted when the project is changed" + get_hosts + ) >> /etc/hosts + fi +} + function getip(){ local current="$(project current --path)" index="$current/index.yaml" @@ -44,8 +74,12 @@ function getip(){ } function addip(){ + local current="$(project current --path)" + index="$current/index.yaml" echo -n "Name: " read name < /dev/tty + echo -n "Domain: " + read domain < /dev/tty echo -n "IP: " read ip < /dev/tty echo -n "Description: " @@ -54,15 +88,20 @@ function addip(){ if [ -n "$name" ]; then host="$(echo $host | jq ".name=\"$name\"" )" fi + if [ -n "$domain" ]; then + host="$(echo $host | jq ".domain=\"$domain\"" )" + fi if [ -n "$ip" ]; then host="$(echo $host | jq ".ip=\"$ip\"" )" fi if [ -n "$description" ]; then host="$(echo $host | jq ".description=\"$description\"" )" fi + echo $host yq --yaml-output ".hosts |= .+ [$host]" "$index" > newindex rm "$index" mv newindex "$index" + host_file } case "$1" in @@ -77,6 +116,10 @@ case "$1" in list) listhosts ;; + hosts_file) + shift + host_file "$@" + ;; ip) getip ;; diff --git a/bin/.bin/project-management/project-switch b/bin/.bin/project-management/project-switch index b7cc555c..e41a99d5 100755 --- a/bin/.bin/project-management/project-switch +++ b/bin/.bin/project-management/project-switch @@ -28,6 +28,7 @@ function unset_project(){ rm "$SYMLINC" 2> /dev/null # See note about SIGWINCH below pkill -u $USER -SIGWINCH zsh + project hosts hosts_file fi } @@ -39,6 +40,7 @@ function set_project(){ fi ln -s "$switchto" "$SYMLINC" pkill -u $USER -SIGWINCH zsh + project hosts hosts_file else echo "No such directory $switchto" exit 1