From 9d1cc89453a9e4387822873891aab1240696a061 Mon Sep 17 00:00:00 2001 From: Hien To Date: Tue, 10 Sep 2024 01:33:42 +0700 Subject: [PATCH] Makefile add build-installer --- engine/Makefile | 5 ++--- engine/templates/linux/create_deb.sh | 14 +++++++++++++- engine/templates/linux/postinst | 5 ++++- engine/templates/linux/postrm | 23 ++++++++++++++--------- engine/templates/linux/prerm | 6 +++--- 5 files changed, 36 insertions(+), 17 deletions(-) diff --git a/engine/Makefile b/engine/Makefile index 660d34d13..918c1aaa0 100644 --- a/engine/Makefile +++ b/engine/Makefile @@ -59,7 +59,7 @@ else cp build/cortex cortex/; endif -codesign: +codesign-binary: ifeq ($(CODE_SIGN),false) @echo "Skipping Code Sign" @exit 0 @@ -68,12 +68,11 @@ endif ifeq ($(OS),Windows_NT) @powershell -Command "dotnet tool install --global AzureSignTool;" @powershell -Command 'azuresigntool.exe sign -kvu "$(AZURE_KEY_VAULT_URI)" -kvi "$(AZURE_CLIENT_ID)" -kvt "$(AZURE_TENANT_ID)" -kvs "$(AZURE_CLIENT_SECRET)" -kvc "$(AZURE_CERT_NAME)" -tr http://timestamp.globalsign.com/tsa/r6advanced1 -v ".\cortex\cortex.exe";' - @powershell -Command 'azuresigntool.exe sign -kvu "$(AZURE_KEY_VAULT_URI)" -kvi "$(AZURE_CLIENT_ID)" -kvt "$(AZURE_TENANT_ID)" -kvs "$(AZURE_CLIENT_SECRET)" -kvc "$(AZURE_CERT_NAME)" -tr http://timestamp.globalsign.com/tsa/r6advanced1 -v ".\cortex\engines\cortex.llamacpp\engine.dll";' else ifeq ($(shell uname -s),Linux) @echo "Skipping Code Sign for linux" @exit 0 else - find "cortex" -type f -exec codesign --force -s "$(DEVELOPER_ID)" --options=runtime {} \; + codesign --force -s "$(DEVELOPER_ID)" --options=runtime --entitlements="./templates/macos/entitlements.plist" ./cortex/cortex; endif package: diff --git a/engine/templates/linux/create_deb.sh b/engine/templates/linux/create_deb.sh index 72005c755..c01f5c15d 100644 --- a/engine/templates/linux/create_deb.sh +++ b/engine/templates/linux/create_deb.sh @@ -2,15 +2,27 @@ PACKAGE_NAME=$1 VERSION=$2 SOURCE_BINARY_PATH=$3 DESTINATION_BINARY_NAME=$4 +DATA_FOLDER_NAME=$5 +CONFIGURATION_FILE_NAME=$6 mkdir -p $PACKAGE_NAME/DEBIAN mkdir -p $PACKAGE_NAME/usr/bin cp $SOURCE_BINARY_PATH $PACKAGE_NAME/usr/bin/$DESTINATION_BINARY_NAME +export DESTINATION_BINARY_NAME + cp postinst $PACKAGE_NAME/DEBIAN/postinst -cp postrm $PACKAGE_NAME/DEBIAN/postrm +sed -i '2s/.*/DESTINATION_BINARY_NAME=\$DESTINATION_BINARY_NAME/' $PACKAGE_NAME/DEBIAN/postinst + cp prerm $PACKAGE_NAME/DEBIAN/prerm +sed -i '3s/.*/DESTINATION_BINARY_NAME=\$DESTINATION_BINARY_NAME/' $PACKAGE_NAME/DEBIAN/prerm + +export DATA_FOLDER_NAME CONFIGURATION_FILE_NAME + +cp postrm $PACKAGE_NAME/DEBIAN/postrm +sed -i '3s/.*/DATA_FOLDER_NAME=\$DATA_FOLDER_NAME/' $PACKAGE_NAME/DEBIAN/postrm +sed -i '3s/.*/CONFIGURATION_FILE_NAME=\$CONFIGURATION_FILE_NAME/' $PACKAGE_NAME/DEBIAN/postrm chmod 755 $PACKAGE_NAME/DEBIAN/postinst chmod 755 $PACKAGE_NAME/DEBIAN/postrm diff --git a/engine/templates/linux/postinst b/engine/templates/linux/postinst index 3a3c9a134..2ca83f96e 100644 --- a/engine/templates/linux/postinst +++ b/engine/templates/linux/postinst @@ -1,2 +1,5 @@ #!/bin/sh -echo "Running post-install script..." +DESTINATION_BINARY_NAME=cortex +echo "Download cortex.llamacpp engines by default" +USER_TO_RUN_AS=${SUDO_USER:-$(whoami)} +sudo -u "$USER_TO_RUN_AS" /usr/bin/$DESTINATION_BINARY_NAME engines cortex.llamacpp install diff --git a/engine/templates/linux/postrm b/engine/templates/linux/postrm index 891ddb402..9bf1aed7f 100644 --- a/engine/templates/linux/postrm +++ b/engine/templates/linux/postrm @@ -1,18 +1,24 @@ #!/bin/sh set +e +DATA_FOLDER_NAME=.cortex +CONFIGURATION_FILE_NAME=.cortexrc -echo "Do you want to delete the 'cortex' data folder for all users? (yes/no)" +echo "Do you want to delete the '~/${DATA_FOLDER_NAME}' data folder and file '~/${CONFIGURATION_FILE_NAME}'? (yes/no)" read -r answer +USER_TO_RUN_AS=${SUDO_USER:-$(whoami)} + case "$answer" in [yY][eE][sS]|[yY]) - echo "Deleting 'cortex' data folders..." - for userdir in /home/*; do - if [ -d "$userdir/cortex" ]; then - echo "Removing $userdir/cortex" - rm -rf "$userdir/cortex" > /dev/null 2>&1 - fi - done + echo "Deleting cortex data folders..." + if [ -d "/home/${USER_TO_RUN_AS}/${DATA_FOLDER_NAME}" ]; then + echo "Removing /home/${USER_TO_RUN_AS}/${DATA_FOLDER_NAME}" + rm -rf "/home/${USER_TO_RUN_AS}/${DATA_FOLDER_NAME}" > /dev/null 2>&1 + fi + if [ -f "/home/${USER_TO_RUN_AS}/${CONFIGURATION_FILE_NAME}" ]; then + echo "Removing /home/${USER_TO_RUN_AS}/${CONFIGURATION_FILE_NAME}" + rm -f "/home/${USER_TO_RUN_AS}/${CONFIGURATION_FILE_NAME}" > /dev/null 2>&1 + fi ;; [nN][oO]|[nN]) echo "Keeping the 'cortex' data folders." @@ -21,5 +27,4 @@ case "$answer" in echo "Invalid response. Please type 'yes' or 'no'." ;; esac - exit 0 diff --git a/engine/templates/linux/prerm b/engine/templates/linux/prerm index 40b730f2b..4f3c0abfd 100644 --- a/engine/templates/linux/prerm +++ b/engine/templates/linux/prerm @@ -1,6 +1,6 @@ #!/bin/sh set +e - -/usr/bin/cortex stop > /dev/null 2>&1 - +DESTINATION_BINARY_NAME=cortex +USER_TO_RUN_AS=${SUDO_USER:-$(whoami)} +sudo -u "$USER_TO_RUN_AS" /usr/bin/$DESTINATION_BINARY_NAME stop > /dev/null 2>&1 exit 0 \ No newline at end of file