Added irc-post-commit-hook and fixed/updated dbc script
This commit is contained in:
parent
44ad542202
commit
d715d54205
|
@ -30,6 +30,7 @@ alias nrmcommits="git checkout --orphan latest_branch && git add -A && git commi
|
|||
# random
|
||||
alias ..="cd ../"
|
||||
alias crypto="curl rate.sx"
|
||||
alias dropkey="dropbearkey -y -f .dropbear/key | head -n 2 | tail -n 1"
|
||||
alias dump='setterm -dump 1 -file screen.dump'
|
||||
alias newnym='echo -e "AUTHENTICATE \"CHANGEME\"\r\nSIGNAL NEWNYM\r\nQUIT" | nc 127.0.0.1 9051'
|
||||
alias mkgz='tar -cvzf'
|
||||
|
|
91
scripts/dbc
91
scripts/dbc
|
@ -1,38 +1,50 @@
|
|||
#!/bin/sh
|
||||
# Dropbear Connect Script (DBC) - Developed by acidvegas (https://git.acid.vegas/void)
|
||||
|
||||
# Store your SSH connections in pass with the following format:
|
||||
# Usage: dbc <NAME>
|
||||
#
|
||||
# You can store your SSH connections in the CONFIG_FILE or securely using pass.
|
||||
#
|
||||
# Store your SSH connections with the following format:
|
||||
# NAME USER HOST PORT [KEY]
|
||||
#
|
||||
# The [KEY] argument is optional and is the name of a key file in your CONFIG_DIR.
|
||||
# If you are using pass, the [KEY] argument can be a plain text password instead.
|
||||
|
||||
# Config settings
|
||||
CONFIG_DIR="$HOME/.dropbear"
|
||||
CONFIG_FILE="$CONFIG_DIR/config" # Ignored if USE_PASS is set to 1
|
||||
|
||||
# Pass settings
|
||||
CONFIG_PASS="dropbear" # Replace with your pass entry for the config
|
||||
USE_PASS=0 # Change to 1 to use pass
|
||||
|
||||
# Check if config file exists
|
||||
if [ $USE_PASS -eq 0 ] && [ ! -f $CONFIG_FILE ]; then
|
||||
echo "Error: Config file not found." && exit 1
|
||||
fi
|
||||
|
||||
# Check if exactly one argument is provided
|
||||
if [ "$#" -ne 1 ]; then
|
||||
echo "Usage: $0 NAME"
|
||||
exit 1
|
||||
echo "Usage: $0 NAME" && exit 1
|
||||
fi
|
||||
|
||||
# Read the name argument
|
||||
NAME=$1
|
||||
CONFIG_DIR="$HOME/.dropbear"
|
||||
CONFIG_PASS_ENTRY="dropbear" # Replace with your pass entry for the config
|
||||
CONFIG_PASS_ENABLED=1 # Set to 0 to disable pass
|
||||
|
||||
# Read the config file
|
||||
if [ "$CONFIG_PASS_ENABLED" -eq 1 ]; then
|
||||
CONFIG_DATA=$(pass "$CONFIG_PASS_ENTRY")
|
||||
# Load the config data
|
||||
if [ $USE_PASS -eq 1 ]; then
|
||||
CONFIG_DATA=$(pass $CONFIG_PASS)
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Failed to decrypt config with pass"
|
||||
exit 1
|
||||
echo "Failed to decrypt config with pass" && exit 1
|
||||
fi
|
||||
elif [ $USE_PASS -eq 0 ]; then
|
||||
if [ ! -f $CONFIG_FILE ]; then
|
||||
echo "Error: Config file not found." && exit 1
|
||||
fi
|
||||
CONFIG_DATA=$(cat $CONFIG_FILE)
|
||||
else
|
||||
if [ ! -f "$CONFIG_DIR/config" ]; then
|
||||
echo "Error: Config file not found"
|
||||
exit 1
|
||||
fi
|
||||
CONFIG_DATA=$(cat "$CONFIG_DIR/config")
|
||||
fi
|
||||
|
||||
if [ -z "$CONFIG_DATA" ]; then
|
||||
echo "Error: Config file is empty"
|
||||
exit 1
|
||||
echo "Error: Invalid value for USE_PASS." && exit 1
|
||||
fi
|
||||
|
||||
# Use grep to find the matching line
|
||||
|
@ -41,25 +53,34 @@ MATCHING_LINES=$(echo "$CONFIG_DATA" | grep "^$NAME ")
|
|||
# Check if exactly one matching line is found
|
||||
LINE_COUNT=$(echo "$MATCHING_LINES" | wc -l)
|
||||
if [ "$LINE_COUNT" -ne 1 ]; then
|
||||
echo "Error: The NAME '$NAME' matches multiple or no lines."
|
||||
exit 1
|
||||
echo "Error: The NAME '$NAME' matches multiple or no lines." && exit 1
|
||||
fi
|
||||
|
||||
# Read parameters from the matching line
|
||||
read -r line_name line_user line_host line_port line_key <<< "$MATCHING_LINES"
|
||||
# Remove extra whitespace from the matching line
|
||||
MATCHING_LINES=$(echo $MATCHING_LINES | tr -s '[:space:]' ' ')
|
||||
|
||||
# Build and execute the dbclient command
|
||||
DBCLIENT_CMD="dbclient -p $line_port -l $line_user $line_host"
|
||||
# Read parameters from the matching line ("Failed reading termmodes" and "Failed to set raw TTY mode" errors when using read inside a while loop)
|
||||
line_name=$(echo $MATCHING_LINES | cut -d ' ' -f 1)
|
||||
line_user=$(echo $MATCHING_LINES | cut -d ' ' -f 2)
|
||||
line_host=$(echo $MATCHING_LINES | cut -d ' ' -f 3)
|
||||
line_port=$(echo $MATCHING_LINES | cut -d ' ' -f 4)
|
||||
line_key=$(echo $MATCHING_LINES | cut -d ' ' -f 5) # Can also be a password if using pass
|
||||
|
||||
# Append key to the command if it is provided and exists
|
||||
# Set the initial dbclient command line arguments
|
||||
DBCLIENT_CMD="-p $line_port -l $line_user $line_host"
|
||||
|
||||
# Parse the optional key/password argument
|
||||
if [ -n "$line_key" ]; then
|
||||
KEY_PATH="$CONFIG_DIR/$line_key"
|
||||
if [ -f "$KEY_PATH" ]; then
|
||||
if [ -f $KEY_PATH ]; then
|
||||
DBCLIENT_CMD="$DBCLIENT_CMD -i $KEY_PATH"
|
||||
else
|
||||
echo "Warning: Key file $KEY_PATH not found, proceeding without it"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Execute the command
|
||||
$DBCLIENT_CMD
|
||||
if [ $USE_PASS -eq 1 ]; then
|
||||
DROPBEAR_PASSWORD=$line_key dbclient $DBCLIENT_CMD
|
||||
else
|
||||
echo "Error: Key file not found. (If this is a password and not a key, you must use Pass)"
|
||||
fi
|
||||
|
||||
else
|
||||
dbclient $DBCLIENT_CMD
|
||||
fi
|
|
@ -0,0 +1,26 @@
|
|||
#!/bin/sh
|
||||
# irc post-commit hook - developed by acidvegas (https://git.acid.vegas/void)
|
||||
|
||||
# Place this file in .git/hooks/post-commit and chmod +x
|
||||
|
||||
# Configuration
|
||||
WEECHAT_NETWORK="irc.supernets.org"
|
||||
WEECHAT_CHANNEL="#dev"
|
||||
WEECHAT_FIFO="$HOME/.local/share/weechat/weechat_fifo"
|
||||
SSH_SERVER="war"
|
||||
|
||||
# Get commit data for the message
|
||||
_data=$(git log -1 --graph --pretty=format:"%h|%s|%cn")
|
||||
_hash=$(echo "$_data" | cut -d'|' -f1 | cut -c 3-)
|
||||
_msg=$(echo "$_data" | cut -d'|' -f2)
|
||||
_name=$(echo "$_data" | cut -d'|' -f3)
|
||||
#_name=$(basename $(dirname $(git rev-parse --show-toplevel))) # For locally parsing organization names
|
||||
_repo=$(basename -s .git $(git config --get remote.origin.url))
|
||||
_summary=$(git show $_hash --stat | grep -E "fil(e|es) changed" | awk '{files+=$1; inserted+=$4; deleted+=$6} END {printf "%s|+%s|-%s", files, inserted, deleted }')
|
||||
_files=$(echo $_summary | cut -d'|' -f1)
|
||||
_inserts=$(echo $_summary | cut -d'|' -f2)
|
||||
_deletes=$(echo $_summary | cut -d'|' -f3)
|
||||
_ircmsg="irc.$WEECHAT_NETWORK.$WEECHAT_CHANNEL *^C14[^C11GitHub^C14]^O Commit pushed to ^C08$_name/$_repo^O (^C06$_hash^O) ^C14[^O$_files^C14|^C03$_inserts^C14|^C04$_deletes^C14]^O : $_msg"
|
||||
|
||||
# Send the message to weechat
|
||||
echo "$_ircmsg" | ssh $SSH_SERVER tee $WEECHAT_FIFO > /dev/null
|
2
setup
2
setup
|
@ -65,7 +65,7 @@ setup_root() {
|
|||
printf "AuthenticationMethods publickey\nBanner /etc/issue\nClientAliveInterval 0\nDisableForwarding yes\nPermitRootLogin no\nPort CHANGEME\nPrintLastLog no\n" > /etc/ssh/sshd_config
|
||||
elif [ $REMOTE_ACCESS = "dropbear" ]; then
|
||||
xbps-install -y dropbear
|
||||
printf '#!/bin/sh\nexec 2>&1\n[ -r conf ] && . ./conf\npkill -9 dropbear\nexec dropbear -p $REMOTE_PORT -w -s -R -F\n' > /etc/sv/dropbear/run
|
||||
printf '#!/bin/sh\nexec 2>&1\n[ -r conf ] && . ./conf\nexec dropbear -p CHANGE:ME -w -s -R -F}\n' > /etc/sv/dropbear/run
|
||||
ln -sf /etc/sv/dropbear /var/service/
|
||||
fi
|
||||
|
||||
|
|
Loading…
Reference in New Issue