updateed install and uninstall so it works

This commit is contained in:
ronny abraham 2025-05-12 03:27:10 +03:00
parent 7518d708fe
commit 383b936cec
2 changed files with 58 additions and 10 deletions

View file

@ -2,21 +2,45 @@
set -euo pipefail
ROOT_SRC=".."
ROOT_DST="/usr/local"
PREFIX="${PREFIX:-/usr/local}"
SCRIPT_NAME="$ROOT_SRC/convert_dirs.sh"
INSTALL_DIR="$ROOT_DST/bin"
TARGET_NAME="convert_dirs"
INSTALL_DIR="$PREFIX/bin"
TARGET_NAME="convert-dirs"
SCRIPT_NAME="$TARGET_NAME.sh"
SCRIPT_PATH="$ROOT_SRC/$SCRIPT_NAME"
# Optional --prefix CLI override
while [[ $# -gt 0 ]]; do
case "$1" in
--prefix)
PREFIX="$2"
INSTALL_DIR="$PREFIX/bin"
shift 2
;;
--help|-h)
echo "Usage: $0 [--prefix /desired/install/path]" >&2
echo 0
;;
*)
echo "Unknown option: $1"
echo "Usage: $0 [--prefix /desired/install/path]" >&2
exit 1
;;
esac
done
# Check script exists
if [[ ! -f "$SCRIPT_NAME" ]]; then
echo "❌ Error: $SCRIPT_NAME not found in current directory." >&2
if [[ ! -f "$SCRIPT_PATH" ]]; then
echo "❌ Error: Expected to find $SCRIPT_NAME at: $SCRIPT_PATH" >&2
exit 1
fi
# Copy to install location
echo "📦 Installing $SCRIPT_NAME to $INSTALL_DIR/$TARGET_NAME ..."
sudo install -m 755 "$SCRIPT_NAME" "$INSTALL_DIR/$TARGET_NAME"
sudo install -m 755 "$SCRIPT_PATH" "$INSTALL_DIR/$TARGET_NAME"
echo "✅ Installed successfully."
echo "🔧 Run it with: $TARGET_NAME"
echo "Installed successfully."
echo "Run it with: $TARGET_NAME"
echo "Add to your PATH if not already:"
echo " export PATH=\"$INSTALL_DIR:\$PATH\""

View file

@ -1,8 +1,32 @@
#!/bin/bash
set -euo pipefail
INSTALL_PATH="/usr/local/bin/convert_dirs"
ROOT_SRC=".."
TARGET_NAME="convert-dirs"
PREFIX="${PREFIX:-/usr/local}"
INSTALL_PATH="$PREFIX/bin/$TARGET_NAME"
while [[ $# -gt 0 ]]; do
case "$1" in
--prefix)
PREFIX="$2"
INSTALL_PATH="$PREFIX/bin/$TARGET_NAME"
shift 2
;;
--help|-h)
echo "Usage: $0 [--prefix /custom/bin/path]" >&2
exit 0
;;
*)
echo "Unknown option $1" >&2
exit 1
;;
esac
done
# check and remove
if [[ ! -f "$INSTALL_PATH" ]]; then
echo "$INSTALL_PATH not found. Nothing to uninstall."
exit 1