Change some scripts a bit

master
Jonathan Hodgson 5 years ago
parent 22d3634415
commit 3c6b8fd06c
  1. 43
      bin/.bin/dmenu/password-manager
  2. 11
      bin/.bin/download
  3. 2
      bin/.bin/nmap/nmapAutomator
  4. 43
      bin/.bin/project-management/project-hosts
  5. 2
      bin/.bin/project-management/project-switch

@ -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

@ -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

@ -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'

@ -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
;;

@ -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

Loading…
Cancel
Save