shell-utils/install.sh

42 lines
1019 B
Bash

#!/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."