#!/bin/sh # POSIX-compliant install script for shmake # Define installation paths BIN_DIR="$HOME/.local/bin" SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" # Source files SRC_SOURCE="$SCRIPT_DIR/source_code" SRC_LICENSES="$SCRIPT_DIR/licenses" # Destination names DEST_SOURCE="$BIN_DIR/shmake_source" DEST_SCRIPT="$DEST_SOURCE/shmake.sh" DEST_SYMLINK="$BIN_DIR/shmake" DEST_LICENSES="$BIN_DIR/licenses" # 1. Verify source files exist in the current directory if [ ! -d "$SRC_SOURCE" ]; then printf 'Error: source_code directory not found in %s\n' "$SCRIPT_DIR" >&2 exit 1 fi if [ ! -d "$SRC_LICENSES" ]; then printf 'Error: licenses directory not found in %s\n' "$SCRIPT_DIR" >&2 exit 1 fi # 2. Create destination directory mkdir -p "$BIN_DIR" # 3. Clean up old installation if it exists if [ -e "$DEST_SOURCE" ]; then if [ -f "$DEST_SOURCE" ]; then printf 'Removing old shmake file...\n' rm -rf "$DEST_SOURCE" elif [ -d "$DEST_SOURCE" ]; then printf 'Removing old shmake directory...\n' rm -rf "$DEST_SOURCE" fi fi # 4. Also clean up old symlink if it exists if [ -e "$DEST_SYMLINK" ] && [ "$DEST_SYMLINK" != "$DEST_SOURCE" ]; then printf 'Removing old shmake symlink...\n' rm -rf "$DEST_SYMLINK" fi # 5. Copy the entire source_code directory cp -R "$SRC_SOURCE" "$DEST_SOURCE" # 6. Ensure the main script is executable chmod +x "$DEST_SCRIPT" # 7. Create symlink from ~/.local/bin/shmake to ~/.local/bin/shmake/shmake.sh # This allows you to run "shmake" command rm -rf "$DEST_SYMLINK" ln -s "$DEST_SCRIPT" "$DEST_SYMLINK" # 8. Clean up old licenses directory if it exists if [ -e "$DEST_LICENSES" ]; then if [ -f "$DEST_LICENSES" ]; then rm -f "$DEST_LICENSES" elif [ -d "$DEST_LICENSES" ]; then rm -rf "$DEST_LICENSES" fi fi # 9. Copy the licenses directory cp -R "$SRC_LICENSES" "$BIN_DIR/" # 10. Check if the binary directory is in the user's PATH case ":$PATH:" in *":$BIN_DIR:"*) # PATH is already set ;; *) printf '\n' printf 'NOTE: %s is not in your PATH.\n' "$BIN_DIR" printf 'To use shmake from anywhere, add this to your shell profile:\n' printf ' export PATH="%s:$PATH"\n' "$BIN_DIR" printf '\n' ;; esac printf 'Installation complete!\n' printf 'You can now run "shmake" in your terminal.\n' printf 'Shmake files are installed at: %s\n' "$DEST_SOURCE" printf 'Symlink created at: %s\n' "$DEST_SYMLINK" printf 'Licenses are available at: %s\n' "$DEST_LICENSES" exit 0