65 lines
1.7 KiB
Bash
Executable File
65 lines
1.7 KiB
Bash
Executable File
#!/bin/sh
|
|
# Dropbear Connect Script (DBC) - Developed by acidvegas (https://git.acid.vegas/void)
|
|
|
|
# Store your SSH connections in pass with the following format:
|
|
# NAME USER HOST PORT [KEY]
|
|
|
|
# Check if exactly one argument is provided
|
|
if [ "$#" -ne 1 ]; then
|
|
echo "Usage: $0 NAME"
|
|
exit 1
|
|
fi
|
|
|
|
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")
|
|
if [ $? -ne 0 ]; then
|
|
echo "Failed to decrypt config with pass"
|
|
exit 1
|
|
fi
|
|
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
|
|
fi
|
|
|
|
# Use grep to find the matching line
|
|
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
|
|
fi
|
|
|
|
# Read parameters from the matching line
|
|
read -r line_name line_user line_host line_port line_key <<< "$MATCHING_LINES"
|
|
|
|
# Build and execute the dbclient command
|
|
DBCLIENT_CMD="dbclient -p $line_port -l $line_user $line_host"
|
|
|
|
# Append key to the command if it is provided and exists
|
|
if [ -n "$line_key" ]; then
|
|
KEY_PATH="$CONFIG_DIR/$line_key"
|
|
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 |