Skip to content

Commit

Permalink
Makefile add build-installer
Browse files Browse the repository at this point in the history
  • Loading branch information
hientominh committed Sep 9, 2024
1 parent aa3162a commit 9d1cc89
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 17 deletions.
5 changes: 2 additions & 3 deletions engine/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ else
cp build/cortex cortex/;
endif

codesign:
codesign-binary:
ifeq ($(CODE_SIGN),false)
@echo "Skipping Code Sign"
@exit 0
Expand All @@ -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:
Expand Down
14 changes: 13 additions & 1 deletion engine/templates/linux/create_deb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion engine/templates/linux/postinst
Original file line number Diff line number Diff line change
@@ -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
23 changes: 14 additions & 9 deletions engine/templates/linux/postrm
Original file line number Diff line number Diff line change
@@ -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."
Expand All @@ -21,5 +27,4 @@ case "$answer" in
echo "Invalid response. Please type 'yes' or 'no'."
;;
esac

exit 0
6 changes: 3 additions & 3 deletions engine/templates/linux/prerm
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9d1cc89

Please sign in to comment.