diff --git a/scripts/install.sh b/scripts/install.sh index d6b581a..b6b9507 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -3,11 +3,27 @@ # Define paths BIN_NAME="typy" LOCAL_DIR="$HOME/.local/share" -BIN_PATH="$/usr/bin" CONFIG_PATH="$LOCAL_DIR/$BIN_NAME/words.txt" INSTALL_DIR="$HOME/your-repo" GIT_TAG="v0.7.0" +# Function to move binary with appropriate privileges +move_binary() { + if command -v sudo &> /dev/null; then + sudo mv /tmp/$BIN_NAME /usr/bin/$BIN_NAME + sudo chmod +x /usr/bin/$BIN_NAME + elif command -v doas &> /dev/null; then + doas mv /tmp/$BIN_NAME /usr/bin/$BIN_NAME + doas chmod +x /usr/bin/$BIN_NAME + elif [ "$(id -u)" -eq 0 ]; then + mv /tmp/$BIN_NAME /usr/bin/$BIN_NAME + chmod +x /usr/bin/$BIN_NAME + else + echo "Please run this script with elevated privileges (sudo, doas, or as root)." + exit 1 + fi +} + # Create directories if they don't exist mkdir -p "$LOCAL_DIR/$BIN_NAME" @@ -16,10 +32,9 @@ echo "Downloading and installing $BIN_NAME..." curl -L https://github.com/Pazl27/typy-cli/releases/download/$GIT_TAG/$BIN_NAME -o /tmp/$BIN_NAME # Move the binary to /usr/bin and make it executable -sudo mv /tmp/$BIN_NAME /usr/bin/$BIN_NAME -sudo chmod +x /usr/bin/$BIN_NAME +move_binary -# # Move any required files to the ~/.local folder (e.g., configuration files) +# Move any required files to the ~/.local folder (e.g., configuration files) echo "Setting up configuration files..." curl -L https://github.com/Pazl27/typy-cli/releases/download/$GIT_TAG/words.txt -o "$CONFIG_PATH" diff --git a/scripts/uninstall.sh b/scripts/uninstall.sh index 2c94604..d51e512 100755 --- a/scripts/uninstall.sh +++ b/scripts/uninstall.sh @@ -7,9 +7,23 @@ BIN_PATH="/usr/bin/$BIN_NAME" CONFIG_PATH="$LOCAL_DIR/$BIN_NAME/words.txt" CONFIG_DIR="$LOCAL_DIR/$BIN_NAME" +# Function to remove the binary with appropriate privileges +remove_binary() { + if command -v sudo &> /dev/null; then + sudo rm -f "$BIN_PATH" + elif command -v doas &> /dev/null; then + doas rm -f "$BIN_PATH" + elif [ "$(id -u)" -eq 0 ]; then + rm -f "$BIN_PATH" + else + echo "Please run this script with elevated privileges (sudo, doas, or as root)." + exit 1 + fi +} + # Remove the binary echo "Removing $BIN_NAME binary..." -sudo rm -f "$BIN_PATH" +remove_binary # Remove configuration files echo "Removing configuration files..."