initial commit
This commit is contained in:
48
bin/scripts/build-binary.sh
Executable file
48
bin/scripts/build-binary.sh
Executable file
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
BINARY_NAME=$1
|
||||
BINARY_PATH=$2
|
||||
COMPLETION_SCRIPT=$3
|
||||
BINARY_PATH_VERSION=$BINARY_PATH.version
|
||||
|
||||
source bin/helpers/func.sh
|
||||
|
||||
# Check if HEAD is clean, if not abort
|
||||
if [ -n "$(git status --porcelain)" ]; then
|
||||
printfe "%s\n" "yellow" "You have uncomitted and/or untracked changes in your working directory."
|
||||
fi
|
||||
|
||||
# Get the current tag checked out to HEAD and hash
|
||||
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null)
|
||||
LATEST_COMMIT_HASH=$(git rev-parse --short HEAD 2>/dev/null)
|
||||
LATEST_TAG_HASH=$(git rev-list -n 1 --abbrev-commit $LATEST_TAG 2>/dev/null)
|
||||
BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
|
||||
|
||||
# If BRANCH is HEAD and latest commit hash equals latest tag hash, we are on a tag and up to date
|
||||
if [ "$BRANCH" == "HEAD" ] && [ "$LATEST_COMMIT_HASH" == "$LATEST_TAG_HASH" ]; then
|
||||
BRANCH=$LATEST_TAG
|
||||
fi
|
||||
|
||||
# In case the current head has uncomitted and/or untracked changes, append a postfix to the version saying (dirty)
|
||||
if [ -n "$(git status --porcelain)" ]; then
|
||||
POSTFIX=" (dirty)"
|
||||
fi
|
||||
|
||||
printfe "%s\n" "cyan" "Building $BINARY_NAME binary for $BRANCH ($LATEST_COMMIT_HASH)$POSTFIX..."
|
||||
go build -o $BINARY_PATH
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
printf "\033[0;31m"
|
||||
echo "Build failed."
|
||||
printf "\033[0m"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Put tag and hash in .sshtunnel_version file
|
||||
echo "$BRANCH ($LATEST_COMMIT_HASH)$POSTFIX" > $BINARY_PATH_VERSION
|
||||
|
||||
printfe "%s\n" "cyan" "Generating Bash completion script..."
|
||||
$BINARY_PATH completion bash > $COMPLETION_SCRIPT
|
||||
|
||||
printfe "%s\n" "green" "Bash completion script installed to $COMPLETION_SCRIPT."
|
||||
printfe "%s\n" "green" "Restart or 'source ~/.bashrc' to update your shell."
|
19
bin/scripts/clean.sh
Executable file
19
bin/scripts/clean.sh
Executable file
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
source bin/helpers/func.sh
|
||||
|
||||
# $1 should be binary path
|
||||
BINARY_PATH=$1
|
||||
|
||||
# $2 should be completion script path
|
||||
COMPLETION_SCRIPT=$2
|
||||
|
||||
# Confirm these are paths
|
||||
if [ -z "$BINARY_PATH" ] || [ -z "$COMPLETION_SCRIPT" ]; then
|
||||
printfe "%s\n" "red" "Usage: $0 <binary_path> <completion_script_path>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printfe "%s\n" "cyan" "Cleaning up old binaries and completion scripts..."
|
||||
rm -f $BINARY_PATH
|
||||
rm -f $COMPLETION_SCRIPT
|
18
bin/scripts/install-local.sh
Executable file
18
bin/scripts/install-local.sh
Executable file
@@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
source bin/helpers/func.sh
|
||||
|
||||
# Create any missing directories/files
|
||||
touch ~/.bash_completion
|
||||
mkdir -p $HOME/.local/bin/
|
||||
|
||||
# Symbolically link binaries
|
||||
ln -sf $(pwd)/bin/sshtunnel $HOME/.local/bin/sshtunnel
|
||||
ln -sf $(pwd)/bin/sshtunnel-completion.bash $HOME/.local/bin/sshtunnel-completion.bash
|
||||
|
||||
# Add completion to bash_completion for sshtunnel
|
||||
sed -i '/sshtunnel/d' ~/.bash_completion
|
||||
echo "source $HOME/.local/bin/sshtunnel-completion.bash" >> ~/.bash_completion
|
||||
|
||||
printfe "%s\n" "green" "Local installation complete. Binary has been installed to $HOME/.local/bin/sshtunnel"
|
||||
source ~/.bash_completion
|
49
bin/scripts/install.sh
Executable file
49
bin/scripts/install.sh
Executable file
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
source bin/helpers/func.sh
|
||||
|
||||
# Test for root privileges
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
printfe "%s\n" "red" "Please run as root"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Firstly compile the sshtunnel binary
|
||||
printfe "%s\n" "cyan" "Compiling sshtunnel..."
|
||||
MAKE_OUTPUT=$(make 2>&1)
|
||||
MAKE_EXIT_CODE=$?
|
||||
if [ $MAKE_EXIT_CODE -ne 0 ]; then
|
||||
printfe "%s\n" "red" "Compilation failed. Please check the output below."
|
||||
echo "$MAKE_OUTPUT"
|
||||
exit 1
|
||||
fi
|
||||
printfe "%s\n" "green" "Compilation successful."
|
||||
|
||||
# Remove any existing sshtunnel installation
|
||||
printfe "%s\n" "cyan" "Removing existing sshtunnel installation..."
|
||||
if [ -f "/usr/local/bin/sshtunnel" ]; then
|
||||
log_and_run rm /usr/local/bin/sshtunnel
|
||||
fi
|
||||
if [ -f "/usr/share/bash-completion/completions/sshtunnel" ]; then
|
||||
log_and_run rm /usr/share/bash-completion/completions/sshtunnel
|
||||
fi
|
||||
if [ -f "/usr/local/share/sshtunnel/sshtunnel.version" ]; then
|
||||
log_and_run rm /usr/local/share/sshtunnel/sshtunnel.version
|
||||
fi
|
||||
|
||||
# Copy binary files to /usr/local/bin
|
||||
printfe "%s\n" "cyan" "Installing sshtunnel..."
|
||||
log_and_run cp $(pwd)/bin/sshtunnel /usr/local/bin/sshtunnel
|
||||
log_and_run cp $(pwd)/bin/sshtunnel-completion.bash /usr/share/bash-completion/completions/sshtunnel
|
||||
|
||||
# Copy version file to /usr/local/share/sshtunnel/sshtunnel.version
|
||||
mkdir -p /usr/local/share/sshtunnel
|
||||
log_and_run cp $(pwd)/bin/sshtunnel.version /usr/local/share/sshtunnel/sshtunnel.version
|
||||
|
||||
# Clean up any compiled files
|
||||
printfe "%s\n" "cyan" "Cleaning up..."
|
||||
log_and_run rm $(pwd)/bin/sshtunnel
|
||||
log_and_run rm $(pwd)/bin/sshtunnel-completion.bash
|
||||
log_and_run rm $(pwd)/bin/sshtunnel.version
|
||||
|
||||
printfe "%s\n" "green" "Installation complete."
|
36
bin/scripts/uninstall.sh
Executable file
36
bin/scripts/uninstall.sh
Executable file
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
source bin/helpers/func.sh
|
||||
|
||||
# Test for root privileges if uninstalling system-wide files
|
||||
NEED_ROOT=0
|
||||
if [ -f /usr/local/bin/sshtunnel ] || [ -f /usr/share/bash-completion/completions/sshtunnel ] || [ -f /usr/local/share/sshtunnel/sshtunnel.version ]; then
|
||||
NEED_ROOT=1
|
||||
fi
|
||||
if [ $NEED_ROOT -eq 1 ] && [ "$EUID" -ne 0 ]; then
|
||||
printfe "%s\n" "red" "Please run as root"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Remove user-local files
|
||||
printfe "%s\n" "cyan" "Removing sshtunnel from user-local locations..."
|
||||
if [ -f $HOME/.local/bin/sshtunnel ]; then
|
||||
log_and_run rm $HOME/.local/bin/sshtunnel
|
||||
fi
|
||||
if [ -f $HOME/.local/bin/sshtunnel-completion.bash ]; then
|
||||
log_and_run rm $HOME/.local/bin/sshtunnel-completion.bash
|
||||
fi
|
||||
|
||||
# Remove system-wide files using log_and_run
|
||||
printfe "%s\n" "cyan" "Removing sshtunnel from system-wide locations..."
|
||||
if [ -f /usr/share/bash-completion/completions/sshtunnel ]; then
|
||||
log_and_run rm /usr/share/bash-completion/completions/sshtunnel
|
||||
fi
|
||||
if [ -f /usr/local/bin/sshtunnel ]; then
|
||||
log_and_run rm /usr/local/bin/sshtunnel
|
||||
fi
|
||||
if [ -f /usr/local/share/sshtunnel/sshtunnel.version ]; then
|
||||
log_and_run rm /usr/local/share/sshtunnel/sshtunnel.version
|
||||
fi
|
||||
|
||||
printfe "%s\n" "green" "Uninstall complete."
|
Reference in New Issue
Block a user