Skip to content

Commit

Permalink
Merge pull request #13 from liquidz00/develop
Browse files Browse the repository at this point in the history
Installer, Uninstaller & Tools directory
  • Loading branch information
ball42 authored Apr 9, 2024
2 parents d58bdd5 + 4dd1182 commit 43f691a
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Patcher leverages the Jamf Pro API to fetch patch management data and generate c

### Prerequisites

> **Note**<br>
> [!NOTE]
> Patcher **requires** an API client for authentication. For instructions on creating an API Role & Client in Jamf Pro, refer to the [Jamf Pro Deployment Guide](https://github.com/liquidz00/Patcher/wiki/Jamf-Pro-Deployment-Guide#creating-an-api-role--client) in the wiki.
- Python 3.9+ (with pip).
Expand All @@ -34,7 +34,7 @@ Patcher leverages the Jamf Pro API to fetch patch management data and generate c

1. **Run the Installer**
```shell
bash -c "$(curl -fsSL https://raw.githubusercontent.com/liquidz00/Patcher/main/installer.sh)"
bash -c "$(curl -fsSL https://raw.githubusercontent.com/liquidz00/Patcher/main/tools/installer.sh)"
```
2. **Follow the Installer Script Prompts**
The installer script will guide you through setting up your Jamf Pro instance details and installing project dependencies. Follow the prompts to enter your Jamf Pro URL, Client ID, and Client Secret. If you already have a Bearer Token, you can pass the value to the installer script, otherwise the installer script will generate one for you. You'll also be asked to customize the report header and footer text. Optionally, you can opt to use a custom font instead of the default font [Assistant](https://fonts.google.com/specimen/Assistant).
Expand Down
56 changes: 54 additions & 2 deletions installer.sh → tools/installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
# shellcheck disable=SC2086
#
# This script should be run via curl:
# bash -c "$(curl -fsSL https://raw.githubusercontent.com/liquidz00/Patcher/main/installer.sh)"
# bash -c "$(curl -fsSL https://raw.githubusercontent.com/liquidz00/Patcher/main/tools/installer.sh)"
#
# Alternatively, the script can be downloaded first and run afterwards:
# curl -O https://raw.githubusercontent.com/liquidz00/Patcher/main/installer.sh && bash ./installer.sh
# curl -O https://raw.githubusercontent.com/liquidz00/Patcher/main/tools/installer.sh && bash ./installer.sh
#
# Default repo settings
REPO=${REPO:-liquidz00/Patcher}
Expand Down Expand Up @@ -228,6 +228,20 @@ setup_color() {
FMT_RESET=$(printf '\033[0m')
}

copy_v0() {
# Copies .env file and fonts directory from initial Patcher release location ($HOME/.patcher)
local old_path="$HOME/.patcher"
if ! cp "$old_path/.env" "$PARENT/.env"; then
fmt_error "Unable to copy .env to new install location. Exiting..."
return 1
fi

if ! cp -r "$old_path/fonts/"* "$PARENT/fonts"; then
fmt_error "Unable to copy fonts directory to new install location. Exiting..."
return 1
fi
}

setup_patcher() {
echo "${FMT_GREEN}Starting installation...${FMT_RESET}"
echo "Starting installation..." >> "$LOG_FILE"
Expand Down Expand Up @@ -398,6 +412,11 @@ print_success() {
main() {
setup_color

# Check if script is running as root
if [ "$(id -u)" -eq 0 ]; then
fmt_error "This script should not be run as root or with sudo privileges. Exiting..."
exit 1
fi
# Pre-flight checks (Git, python)
command_exists git || {
fmt_error "Git is not installed. Please install Git and try again."
Expand All @@ -409,6 +428,39 @@ main() {
exit 1
}

while [[ "$#" -gt 0 ]]; do
case $1 in
-d|--develop)
BRANCH="develop"
shift
;;
*)
echo "Unknown option: $1"
fmt_warning "Unknown option passed. Defaulting to main..."
;;
esac
done

if [ -d "$HOME/.patcher" ]; then
fmt_info "Previous installation found. Attempting migration of .env file and fonts directory."

if ! copy_v0; then
# Prompt user to delete old installation if copy fails
read -p "Would you like to delete the previous installation at $HOME/.patcher? Note: You will need to enter your custom fonts and API client information again if you choose yes. (y/n): " confirm_delete

if [[ "$confirm_delete" =~ ^[Yy]$ ]]; then
rm -rf "$HOME/.patcher"
fmt_info "Previous install deleted successfully."
else
fmt_info "Opted to retain previous installation."
fi
else
# Copy succeeded, remove previous location automatically
rm -rf "$HOME/.patcher"
fmt_info "Previous installation migrated and removed as expected."
fi
fi

setup_patcher
setup_environment
setup_ui
Expand Down
56 changes: 56 additions & 0 deletions tools/uninstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash
#
# Author: liquidz00
# GitHub: https://github.com/liquidz00
#
# Removes Patcher directory from $HOME/Patcher (v1.0+) or $HOME/.patcher
#
# Shellcheck disables
# shellcheck disable=SC2039
# shellcheck disable=SC2162
# shellcheck disable=SC2068
# shellcheck disable=SC2198
#
# This script should be run via curl:
# bash -c "$(curl -fsSL https://raw.githubusercontent.com/liquidz00/Patcher/main/uninstaller.sh)"
#
# Parent directory array (accounts for v0 of Patcher)
PARENTS=()

# Add Patcher directories to array if they exist
if [ -d "$HOME/Patcher" ]; then
PARENTS+=("$HOME/Patcher")
fi

if [ -d "$HOME/.patcher" ]; then
PARENTS+=("$HOME/.patcher")
fi

# Remove directory function
remove_directory() {
local dir=$1
if [ -n "$dir" ] && [ -d "$dir" ]; then
read -p "Are you sure you want to remove $dir? (y/N): " confirm
if [[ "$confirm" =~ ^[Yy]$ ]]; then
rm -rf "$dir"
echo "$dir has been removed."
else
echo "Removal of $dir canceled."
fi
else
echo "Directory $dir does not exist or variable is unset. Skipping..."
fi
}

# Iterate over array to remove each directory
for dir in "${PARENTS[@]}"; do
remove_directory "$dir"
done

if [ ${#PARENTS[@]} -eq 0 ]; then
echo "No Patcher directories found. Nothing to uninstall."
else
echo "Patcher uninstalled successfully."
fi

exit 0

0 comments on commit 43f691a

Please sign in to comment.