Skip to content

Commit

Permalink
Added --pre-install
Browse files Browse the repository at this point in the history
  • Loading branch information
RhetTbull committed Feb 3, 2024
1 parent e8beb8e commit ea240eb
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 22 deletions.
31 changes: 27 additions & 4 deletions applecrate/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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 = {
Expand All @@ -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}.")
Expand Down Expand Up @@ -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)
Expand All @@ -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}")
Expand Down
22 changes: 4 additions & 18 deletions applecrate/templates/postinstall
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
7 changes: 7 additions & 0 deletions applecrate/templates/preinstall
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

# Pre-installation actions

{% if pre_install %}
./custom_preinstall
{% endif %}
14 changes: 14 additions & 0 deletions applecrate/templates/uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down

0 comments on commit ea240eb

Please sign in to comment.