Add install.sh

This commit is contained in:
colin 2024-07-21 13:00:52 +00:00
parent afaf0871fb
commit 8cf372609a
1 changed files with 41 additions and 0 deletions

41
install.sh Normal file
View File

@ -0,0 +1,41 @@
#!/bin/bash
# Check if script name argument is provided
if [ -z "$1" ]; then
echo "Usage: $0 <script-name>"
exit 1
fi
SCRIPT_NAME="$1"
BASE_URL="https://git.nixc.us/colin/shell-utils/raw/branch/main/src"
SCRIPT_URL="$BASE_URL/$SCRIPT_NAME"
DEST_DIR="/etc/profile.d"
DEST_FILE="$DEST_DIR/$SCRIPT_NAME"
# Check if the script is being run as root
if [ "$EUID" -ne 0 ]; then
echo "Please run as root."
exit 1
fi
# Download the specified script to /etc/profile.d/
echo "Downloading $SCRIPT_NAME from $SCRIPT_URL..."
curl -o "$DEST_FILE" "$SCRIPT_URL"
# Check if the download was successful
if [ $? -ne 0 ]; then
echo "Failed to download $SCRIPT_NAME."
exit 1
fi
# Make the script executable
echo "Making $SCRIPT_NAME executable..."
chmod +x "$DEST_FILE"
echo "$SCRIPT_NAME has been installed in /etc/profile.d/ and made executable."
# Source the new script
echo "Sourcing the $SCRIPT_NAME script..."
source "$DEST_FILE"
echo "Installation complete. The functions are now available for use."