Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installer.sh and API Role & Clients requirement #3

Merged
merged 7 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 12 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,27 @@ Patcher leverages the Jamf Pro API to fetch patch management data and generate c

### Prerequisites

- Python 3.9 or higher.
> **Note**<br>
> 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 or higher installed.
- Git installed (via Homebrew or Developer Tools)
- Access to a Jamf Pro instance with administrator privileges (for API client creation).
- A Jamf Pro API Client with the following:
- Read Computers, Read Patch Reporting roles
- Client ID
- Client Secret
- Bearer Token (Optional, installer script can generate one for you)

> **Note**<br>
> Although not required, it is **highly recommended** to create an API client for use with Patcher. For more details, reference the [Jamf Pro Documentation](https://learn.jamf.com/bundle/jamf-pro-documentation-current/page/API_Roles_and_Clients.html) on API Roles and Clients.

### Installation

1. **Clone the Repository**
```shell
git clone https://github.com/liquidz00/patcher.git
cd patcher
```
2. **Run the Installer Script**
The installer script will guide you through setting up your Jamf Pro instance details and installing project dependencies.
1. **Download the Installer Script**
Instead of cloning the repository, you now simply need to download and run the installer script, which will handle the setup, including cloning the repository.
```shell
chmod +x installer.sh
./installer.sh
curl -O https://raw.githubusercontent.com/liquidz00/Patcher/main/installer.sh && bash ./installer.sh
```
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).
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).

### Usage
After installation, you can generate reports by running the main script. You can specify the output directory for the reports and choose to generate PDF reports alongside Excel files.
Expand All @@ -52,13 +48,10 @@ python patcher.py --path /path/to/output/directory [--pdf]
- The `--path` option specifies the directory where the reports will be saved.
- The optional `--pdf` flag indicates if PDF reports should be generated in addition to Excel files.

For additional command options to use, visit the [Command Options](https://github.com/liquidz00/patcher/wiki/Command-Options) in the Wiki.

### Customizing Report UI
To customize the UI elements like header and footer text after the initial setup, edit the `ui_config.py` file in the project directory. Changes will be reflected in subsequent reports.

## Authors & Contributions
Patcher is co-authored by [Andrew Speciale - @liquidz00](https://github.com/liquidz00) and [Chris Ball - @ball42](https://github.com/ball42). Contributions to Patcher are welcome! Please feel free to submit pull requests or create issues for bugs, questions, or new feature requests.





65 changes: 56 additions & 9 deletions installer.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,56 @@
#!/bin/bash
# shellcheck disable=SC2129
# shellcheck disable=SC2162
# shellcheck disable=SC2155

echo "Starting installation..."
# Logging
LOG_DIR="$HOME/.patcher/logs"
LOG_FILE="$LOG_DIR/installer.log"

log_message() {
local message="$1"
local type="$2" # INFO, WARNING, or ERROR
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')

# Log error to logfile
echo "$timestamp - $type - $message" >> "$LOG_FILE"

# Echo error to stdout for user visibility
echo "$timestamp - $type - $message"
}

# Pre-flight checks
# Create log directory
mkdir -p "$LOG_DIR"

# Git
if ! command -v git &> /dev/null
then
log_message "Git is not installed. Please install Git and try again." "ERROR"
exit 1
fi

# Python
if ! command -v python3 &> /dev/null
then
log_message "Python is not installed. Please install Python and try again." "ERROR"
exit 1
fi

# Clone repo into home directory
PROJECT_DIR="$HOME/patcher"
if [ ! -d "$PROJECT_DIR" ]; then
log_message "Cloning Patcher repository into $PROJECT_DIR" "INFO"
git clone https://github.com/liquidz00/patcher.git "$PROJECT_DIR"
else
log_message "Directory already exists. Pulling latest updates..." "INFO"
(cd "$PROJECT_DIR" && git pull)
fi

# Change into project directory or exit if error thrown
cd "$PROJECT_DIR" || exit

log_message "Starting installation..." "INFO"

# Prompt for Jamf instance details, write to .env
read -p "Enter the URL of your Jamf instance: " jamf_url
Expand All @@ -20,9 +68,8 @@ else
--data-urlencode "grant_type=client_credentials" \
--data-urlencode "client_secret=${client_secret}")
token=$(echo "$response" | plutil -extract access_token raw -)

if [ "$token" == "null" ]; then
echo "Failed to generate a token. Please check your Jamf instance details."
log_message "Failed to generate a token. Please check your Jamf instance details." "ERROR"
exit 1
fi
fi
Expand All @@ -38,14 +85,14 @@ echo "CLIENT_ID=${client_id}" >> .env
echo "CLIENT_SECRET=${client_secret}" >> .env
echo "TOKEN=${token}" >> .env

echo "Jamf instance details saved to .env file."
log_message "Jamf instance details saved to .env file." "INFO"

# Install project dependencies
if [ -f "requirements.txt" ]; then
python3 -m pip install -r requirements.txt
echo "Dependencies installed."
log_message "Dependencies installed." "INFO"
else
echo "requirements.txt not found. Skipping dependency installation."
log_message "requirements.txt not found. Skipping dependency installation." "WARNING"
fi

# Update UI configurations in ui_config.py
Expand All @@ -65,7 +112,7 @@ fi

# Ensure ui_config.py exists. If not, create with default values
if [ -f "ui_config.py" ]; then
echo "Creating default ui_config.py with user-defined configurations..."
log_message "Creating default ui_config.py with user-defined configurations..." "INFO"
cat > ui_config.py << EOF
# ui_config.py
import os
Expand All @@ -82,7 +129,7 @@ FONT_BOLD_PATH = os.path.join(FONTS, "$custom_font_bold_path")
EOF
else
# Update existing ui_config.py with the new values
echo "ui_config.py exists. Updating with new UI configurations..."
log_message "ui_config.py exists. Updating with new UI configurations..." "INFO"
# Use -i.bak to make it compatible across GNU and BSD sed, creates a backup file
sed -i.bak "s/^HEADER_TEXT = .*/HEADER_TEXT = \"$header_text\"/" ui_config.py
sed -i.bak "s/^FOOTER_TEXT = .*/FOOTER_TEXT = \"$footer_text\"/" ui_config.py
Expand All @@ -94,4 +141,4 @@ else
rm ui_config.py.bak
fi

echo "UI configurations updated as expected."
log_message "UI configurations updated as expected." "INFO"
Loading