Migrate most macros to standalone scripts
This commit is contained in:
parent
f070c1d331
commit
7a8e12f4a5
@ -71,14 +71,6 @@ if [ ! -z "$EWP_IN_GURU_ENVIRONMENT" ]; then
|
|||||||
alias cd-dev="cd /s/development/epratten"
|
alias cd-dev="cd /s/development/epratten"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Kill via pgrep
|
|
||||||
nkill() {
|
|
||||||
if [ $# != 1 ]; then
|
|
||||||
echo "Usage: nkill <name>"
|
|
||||||
else
|
|
||||||
kill -9 $(pgrep $1)
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Makes a directory, then moves into it
|
# Makes a directory, then moves into it
|
||||||
mkcd() {
|
mkcd() {
|
||||||
@ -121,66 +113,6 @@ extract() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Generate a password
|
|
||||||
genpass() {
|
|
||||||
if [ $# != 1 ]; then
|
|
||||||
echo "Usage: genpass <len>"
|
|
||||||
else
|
|
||||||
echo $(openssl rand -base64 $1 | tr -d "\n")
|
|
||||||
fi
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
# Sign a file with an SSH key
|
|
||||||
ssh-sign(){
|
|
||||||
if [ $# != 2 ]; then
|
|
||||||
echo "Usage: ssh-sign <key_file> <file>"
|
|
||||||
else
|
|
||||||
if [ -f $2 ]; then
|
|
||||||
cat $2 | ssh-keygen -Y sign -f $1 -n file -
|
|
||||||
else
|
|
||||||
>&2 echo "File not found: $2"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Verify a file, using the ~/.ssh/allowed_signers file
|
|
||||||
ssh-verify(){
|
|
||||||
if [ $# != 3 ]; then
|
|
||||||
echo "Usage: ssh-verify <author> <sigfile> <file>"
|
|
||||||
else
|
|
||||||
ssh-keygen -Y verify -f ~/.ssh/allowed_signers -n file -I $1 -s $2 < $3
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Fully restart a wireguard link
|
|
||||||
wg-restart() {
|
|
||||||
if [ $# != 1 ]; then
|
|
||||||
echo "Usage: wg-restart <interface>"
|
|
||||||
else
|
|
||||||
wg-quick down $1 || true;
|
|
||||||
wg-quick up $1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Edit a wireguard config file
|
|
||||||
wg-edit() {
|
|
||||||
if [ $# != 1 ]; then
|
|
||||||
echo "Usage: wg-edit <interface>"
|
|
||||||
else
|
|
||||||
sudoedit /etc/wireguard/$1.conf
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Print a wireguard config file
|
|
||||||
wg-cat() {
|
|
||||||
if [ $# != 1 ]; then
|
|
||||||
echo "Usage: wg-cat <interface>"
|
|
||||||
else
|
|
||||||
sudo cat /etc/wireguard/$1.conf
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Updates ewconfig
|
# Updates ewconfig
|
||||||
ewconfig-pull() {
|
ewconfig-pull() {
|
||||||
cwd=$(pwd)
|
cwd=$(pwd)
|
||||||
@ -230,46 +162,14 @@ ewconfig-reinstall() {
|
|||||||
ewconfig-run sh ./install-$1.sh
|
ewconfig-run sh ./install-$1.sh
|
||||||
}
|
}
|
||||||
|
|
||||||
# Define a function to emulate gh
|
# If `gh` is not installed, fake it so that I can save my muscle memory
|
||||||
gh-emulated() {
|
|
||||||
if [ $# != 3 ]; then
|
|
||||||
echo "You don't have gh installed. Emulating its functionality."
|
|
||||||
echo "Usage: gh repo clone <user>/<repo>"
|
|
||||||
else
|
|
||||||
git clone https://github.com/$3
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Only if `gh` is not installed
|
|
||||||
if ! command -v gh &> /dev/null; then
|
if ! command -v gh &> /dev/null; then
|
||||||
alias gh=gh-emulated
|
gh() {
|
||||||
|
if [ $# != 3 ]; then
|
||||||
|
echo "You don't have gh installed. Emulating its functionality."
|
||||||
|
echo "Usage: gh repo clone <user>/<repo>"
|
||||||
|
else
|
||||||
|
git clone https://github.com/$3
|
||||||
|
fi
|
||||||
|
}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Convert an SVG to a PNG
|
|
||||||
svg2png() {
|
|
||||||
if [ $# != 1 ]; then
|
|
||||||
echo "Usage: svg2png <file>"
|
|
||||||
else
|
|
||||||
inkscape -z "$1.png" "$1" --export-type=png
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Get the AS Path to an IP
|
|
||||||
aspath() {
|
|
||||||
# There must be at least one argument (cab be more)
|
|
||||||
if [ $# -lt 1 ]; then
|
|
||||||
echo "Usage: aspath <ip> [args]"
|
|
||||||
else
|
|
||||||
mtr $@ -z -rw -c1 -G0.25 | tail -n +3 | awk '{print $2}' | grep -v AS\?\?\? | uniq | cut -c 3- | tr '\n' ',' | sed 's/,/ -> /g' | rev | cut -c 5- | rev
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Get the AS Path to an IP (include unknown hops)
|
|
||||||
aspath-long() {
|
|
||||||
# There must be at least one argument (cab be more)
|
|
||||||
if [ $# -lt 1 ]; then
|
|
||||||
echo "Usage: aspath-long <ip> [args]"
|
|
||||||
else
|
|
||||||
mtr $@ -z -rw -c1 -G0.25 | tail -n +3 | awk '{print $2}' | uniq | cut -c 3- | tr '\n' ',' | sed 's/,/ -> /g' | rev | cut -c 5- | rev
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
10
scripts/genpass
Executable file
10
scripts/genpass
Executable file
@ -0,0 +1,10 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Check args
|
||||||
|
if [ $# != 1 ]; then
|
||||||
|
echo "Usage: genpass <len>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo $(openssl rand -base64 $1 | tr -d "\n")
|
16
scripts/ssh-sign
Normal file
16
scripts/ssh-sign
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Check args
|
||||||
|
if [ $# != 2 ]; then
|
||||||
|
echo "Usage: ssh-sign <key_file> <file>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
if [ -f $2 ]; then
|
||||||
|
cat $2 | ssh-keygen -Y sign -f $1 -n file -
|
||||||
|
else
|
||||||
|
>&2 echo "File not found: $2"
|
||||||
|
exit 1
|
||||||
|
fi
|
10
scripts/ssh-verify
Normal file
10
scripts/ssh-verify
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
# Verify a file, using the ~/.ssh/allowed_signers file
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Check args
|
||||||
|
if [ $# != 3 ]; then
|
||||||
|
echo "Usage: ssh-verify <author> <sigfile> <file>"
|
||||||
|
fi
|
||||||
|
|
||||||
|
ssh-keygen -Y verify -f ~/.ssh/allowed_signers -n file -I $1 -s $2 < $3
|
9
scripts/wg-cat
Normal file
9
scripts/wg-cat
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Check args
|
||||||
|
if [ $# != 1 ]; then
|
||||||
|
echo "Usage: wg-cat <interface>"
|
||||||
|
fi
|
||||||
|
|
||||||
|
sudo cat /etc/wireguard/$1.conf
|
9
scripts/wg-edit
Normal file
9
scripts/wg-edit
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Check args
|
||||||
|
if [ $# != 1 ]; then
|
||||||
|
echo "Usage: wg-edit <interface>"
|
||||||
|
fi
|
||||||
|
|
||||||
|
sudoedit /etc/wireguard/$1.conf
|
12
scripts/wg-restart
Normal file
12
scripts/wg-restart
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
# Fully restarts a wireguard link
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Check args
|
||||||
|
if [ $# != 1 ]; then
|
||||||
|
echo "Usage: wg-restart <interface>"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Its ok if the down command fails
|
||||||
|
wg-quick down $1 || true;
|
||||||
|
wg-quick up $1
|
Loading…
x
Reference in New Issue
Block a user