From ea240eb2ac1877b39957d9123ab1555fb0f8c1e1 Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Sat, 3 Feb 2024 11:13:24 -0800 Subject: [PATCH] Added --pre-install --- applecrate/cli.py | 31 +++++++++++++++++++++++++++---- applecrate/templates/postinstall | 22 ++++------------------ applecrate/templates/preinstall | 7 +++++++ applecrate/templates/uninstall.sh | 14 ++++++++++++++ 4 files changed, 52 insertions(+), 22 deletions(-) create mode 100755 applecrate/templates/preinstall diff --git a/applecrate/cli.py b/applecrate/cli.py index 0275eb5..b6ecc8d 100644 --- a/applecrate/cli.py +++ b/applecrate/cli.py @@ -115,10 +115,18 @@ def cli(): 'For example: `--link "/Library/Application Support/{{ app }}/{{ version }}/app" "/usr/local/bin/{{ app }}-{{ version }}"` ', ) @click.option( - "--post-install", + "--pre-install", "-p", type=click.Path(dir_okay=False, exists=True), - help="Path to post-install script; " "if not provided, a post-install script will be created for you.", + help="Path to pre-install shell script; " + "if not provided, a pre-install script will be created for you.", +) +@click.option( + "--post-install", + "-P", + type=click.Path(dir_okay=False, exists=True), + help="Path to post-install shell script; " + "if not provided, a post-install script will be created for you.", ) def build(**kwargs): """applecrate: A Python package for creating macOS installer packages.""" @@ -150,6 +158,7 @@ def build(**kwargs): license = kwargs["license"] banner = kwargs["banner"] post_install = kwargs["post_install"] + pre_install = kwargs["pre_install"] # template data data = { @@ -161,6 +170,7 @@ def build(**kwargs): "banner": banner, "link": link, "post_install": post_install, + "pre_install": pre_install, } echo(f"Building installer package for {app} version {version}.") @@ -195,7 +205,14 @@ def build(**kwargs): pathlib.Path(target).chmod(0o755) echo(f"Created {target}") - echo("Creating post-install scripts") + echo("Creating pre- and post-install scripts") + + target = BUILD_DIR / "scripts" / "preinstall" + template = get_template("preinstall") + render_template(template, data, target) + pathlib.Path(target).chmod(0o755) + echo(f"Created {target}") + target = BUILD_DIR / "scripts" / "postinstall" template = get_template("postinstall") render_template(template, data, target) @@ -208,8 +225,14 @@ def build(**kwargs): pathlib.Path(target).chmod(0o755) echo(f"Created {target}") + if pre_install: + target = BUILD_DIR / "scripts" / "custom_preinstall" + copy_and_create_parents(pre_install, target) + pathlib.Path(target).chmod(0o755) + echo(f"Created {target}") + if post_install: - target = BUILD_DIR / "scripts" / "postinstall_user" + target = BUILD_DIR / "scripts" / "custom_postinstall" copy_and_create_parents(post_install, target) pathlib.Path(target).chmod(0o755) echo(f"Created {target}") diff --git a/applecrate/templates/postinstall b/applecrate/templates/postinstall index 9a6203c..e7f67b6 100755 --- a/applecrate/templates/postinstall +++ b/applecrate/templates/postinstall @@ -7,21 +7,7 @@ ./links {% endif %} -#Custermize this for your application -# APPLICATION_FILE_PATH=bin/wso2server.sh - -# #Parameters -# PRODUCT_HOME=/Library/__PRODUCT__/__VERSION__ - -# echo "Post installation process started" - -# #Change permissions in home directory -# echo "Change permissions in product home" -# cd ${PRODUCT_HOME} -# chmod -R 755 . -# [ -d /usr/local/bin ] || mkdir /usr/local/bin - -# #Add application shortcut to /usr/local/bin -# rm -f /usr/local/bin/__PRODUCT__-__VERSION__ -# ln -s ${PRODUCT_HOME}/${APPLICATION_FILE_PATH} /usr/local/bin/__PRODUCT__-__VERSION__ -# echo "Post installation process finished" +{% if post_install %} +# Run the user's post-install script +./custom_postinstall +{% endif %} diff --git a/applecrate/templates/preinstall b/applecrate/templates/preinstall new file mode 100755 index 0000000..700a545 --- /dev/null +++ b/applecrate/templates/preinstall @@ -0,0 +1,7 @@ +#!/bin/bash + +# Pre-installation actions + +{% if pre_install %} +./custom_preinstall +{% endif %} diff --git a/applecrate/templates/uninstall.sh b/applecrate/templates/uninstall.sh index 6f9a67d..0909d46 100755 --- a/applecrate/templates/uninstall.sh +++ b/applecrate/templates/uninstall.sh @@ -52,6 +52,20 @@ echo "Application uninstalling process started" # echo "[1/3] [ERROR] Could not delete shortcut links" >&2 # fi +# remove links that were created +{% if link %} +{% for source, target in link %} +echo "Removing link {{ target }}" +[ -e "{{ target }}" ] && rm -rf "{{ target }}" +if [ $? -eq 0 ] +then + echo "[DONE] Successfully deleted link" +else + echo "[ERROR] Could not delete link" >&2 +fi +{% endfor %} +{% endif %} + {% if install %} # remove files that were installed {% for src, target in install %}