@@ -6,6 +6,14 @@ if [ "$(id -u)" != "0" ]; then
66 exit 1
77fi
88
9+ # Determine the home directory based on the user
10+ USER_TO_RUN_AS=${SUDO_USER:- $(whoami)}
11+ if [ " $USER_TO_RUN_AS " = " root" ]; then
12+ USER_HOME=" /root"
13+ else
14+ USER_HOME=" /home/$USER_TO_RUN_AS "
15+ fi
16+
917# Check and suggest installing jq and tar if not present
1018check_install_jq_tar () {
1119 RED=' \033[0;31m'
@@ -47,18 +55,11 @@ get_latest_version() {
4755 echo " ${tag_name# v} "
4856}
4957
50- # Determine the home directory based on the user
51- USER_TO_RUN_AS=${SUDO_USER:- $(whoami)}
52- if [ " $USER_TO_RUN_AS " = " root" ]; then
53- USER_HOME=" /root"
54- else
55- USER_HOME=" /home/$USER_TO_RUN_AS "
56- fi
57-
5858# Default values
5959CHANNEL=" stable"
6060VERSION=" "
6161IS_UPDATE=" false"
62+ DEB_LOCAL=" false"
6263
6364# Function to parse command-line arguments
6465parse_args () {
@@ -72,6 +73,10 @@ parse_args() {
7273 VERSION=" $2 "
7374 shift 2
7475 ;;
76+ --deb_local)
77+ DEB_LOCAL=" true"
78+ shift 1
79+ ;;
7580 --is_update)
7681 IS_UPDATE=" true"
7782 shift 1
@@ -99,24 +104,24 @@ case $CHANNEL in
99104 SERVER_BINARY_NAME=" cortex-server"
100105 DATA_DIR=" $USER_HOME /cortexcpp"
101106 UNINSTALL_SCRIPT=" /usr/bin/cortex-uninstall.sh"
102- UPDATER_SCRIPT=" /usr/bin/cortex-updater.sh"
103107 CONFIGURATION_FILE=" $USER_HOME /.cortexrc"
108+ DEB_APP_NAME=" cortexcpp"
104109 ;;
105110 beta)
106111 CLI_BINARY_NAME=" cortex-beta"
107112 SERVER_BINARY_NAME=" cortex-server-beta"
108113 DATA_DIR=" $USER_HOME /cortexcpp-beta"
109114 UNINSTALL_SCRIPT=" /usr/bin/cortex-beta-uninstall.sh"
110- UPDATER_SCRIPT=" /usr/bin/cortex-beta-updater.sh"
111115 CONFIGURATION_FILE=" $USER_HOME /.cortexrc-beta"
116+ DEB_APP_NAME=" cortexcpp-beta"
112117 ;;
113118 nightly)
114119 CLI_BINARY_NAME=" cortex-nightly"
115120 SERVER_BINARY_NAME=" cortex-server-nightly"
116121 DATA_DIR=" $USER_HOME /cortexcpp-nightly"
117122 UNINSTALL_SCRIPT=" /usr/bin/cortex-nightly-uninstall.sh"
118- UPDATER_SCRIPT=" /usr/bin/cortex-nightly-updater.sh"
119123 CONFIGURATION_FILE=" $USER_HOME /.cortexrc-nightly"
124+ DEB_APP_NAME=" cortexcpp-nightly"
120125 ;;
121126 * )
122127 echo " Invalid channel specified."
@@ -130,34 +135,67 @@ INSTALL_DIR="/usr/bin"
130135install_cortex () {
131136 local channel=$1
132137 local version=$2
133- local url=" "
138+ local is_deb=$3
139+ local url_binary=" "
140+ local url_deb_local=" "
141+ local url_deb_network=" "
134142
135143 case $channel in
136144 stable)
137- url=" https://github.com/janhq/cortex.cpp/releases/download/v${version} /cortex-${version} -linux-amd64.tar.gz"
145+ url_binary=" https://github.com/janhq/cortex.cpp/releases/download/v${version} /cortex-${version} -linux-amd64.tar.gz"
146+ url_deb_local=" https://github.com/janhq/cortex.cpp/releases/download/v${version} /cortex-${version} -linux-amd64-local-installer.deb"
147+ url_deb_network=" https://github.com/janhq/cortex.cpp/releases/download/v${version} /cortex-${version} -linux-amd64-network-installer.deb"
138148 ;;
139149 beta)
140- url=" https://github.com/janhq/cortex.cpp/releases/download/v${version} /cortex-${version} -linux-amd64.tar.gz"
150+ url_binary=" https://github.com/janhq/cortex.cpp/releases/download/v${version} /cortex-${version} -linux-amd64.tar.gz"
151+ url_deb_local=" https://github.com/janhq/cortex.cpp/releases/download/v${version} /cortex-${version} -linux-amd64-local-installer.deb"
152+ url_deb_network=" https://github.com/janhq/cortex.cpp/releases/download/v${version} /cortex-${version} -linux-amd64-network-installer.deb"
141153 ;;
142154 nightly)
143- url=" https://delta.jan.ai/cortex/v${version} /linux-amd64/cortex-nightly.tar.gz"
155+ url_binary=" https://delta.jan.ai/cortex/v${version} /linux-amd64/cortex-nightly.tar.gz"
156+ url_deb_local=" https://delta.jan.ai/cortex/v${version} /linux-amd64/cortex-${version} -linux-amd64-local-installer.deb"
157+ url_deb_network=" https://delta.jan.ai/cortex/v${version} /linux-amd64/cortex-${version} -linux-amd64-network-installer.deb"
144158 ;;
145159 esac
146- echo " Downloading cortex $channel version $version from $url "
147- curl -L $url -o /tmp/cortex.tar.gz
148- tar -xzvf /tmp/cortex.tar.gz -C /tmp
149- chmod +x /tmp/cortex/*
150- cp /tmp/cortex/* /usr/bin/
151- # Check is update or not
152- if [ " $IS_UPDATE " = " false" ]; then
153- su -c " $INSTALL_DIR /$CLI_BINARY_NAME engines install llama-cpp" $USER_TO_RUN_AS
154- su -c " $INSTALL_DIR /$CLI_BINARY_NAME stop > /dev/null 2>&1" $USER_TO_RUN_AS
160+
161+ if [ " $is_deb " = " true" ]; then
162+ # Download the deb package
163+ if [ " $DEB_LOCAL " = " true" ]; then
164+ echo " Downloading cortex $channel version $version from $url_deb_local "
165+ curl -L $url_deb_local -o /tmp/cortex.deb
166+ else
167+ echo " Downloading cortex $channel version $version from $url_deb_network "
168+ curl -L $url_deb_network -o /tmp/cortex.deb
169+ fi
170+
171+ # Install the deb package
172+ if [ " $IS_UPDATE " = " false" ]; then
173+ apt-get install -y /tmp/cortex.deb
174+ else
175+ echo -e " n\n" | SKIP_POSTINSTALL=true apt-get install -y --allow-downgrades /tmp/cortex.deb
176+ fi
177+ rm -f /tmp/cortex.deb
178+ else
179+ echo " Downloading cortex $channel version $version from $url_binary "
180+ curl -L $url_binary -o /tmp/cortex.tar.gz
181+ tar -xzvf /tmp/cortex.tar.gz -C /tmp
182+ chmod +x /tmp/cortex/*
183+ cp /tmp/cortex/* /usr/bin/
184+ # Check is update or not
185+ if [ " $IS_UPDATE " = " false" ]; then
186+ su -c " $INSTALL_DIR /$CLI_BINARY_NAME engines install llama-cpp" $USER_TO_RUN_AS
187+ su -c " $INSTALL_DIR /$CLI_BINARY_NAME stop > /dev/null 2>&1" $USER_TO_RUN_AS
188+ fi
189+ rm -rf /tmp/cortex
190+ rm -f /tmp/cortex.tar.gz
155191 fi
156192}
157193
158194# Function to create uninstall script
159195create_uninstall_script () {
160- cat << EOF > $UNINSTALL_SCRIPT
196+ local is_deb=$1
197+ if [ " $is_deb " = " false" ]; then
198+ cat << EOF > $UNINSTALL_SCRIPT
161199#!/bin/bash
162200# Check for root privileges
163201if [ "\$ (id -u)" != "0" ]; then
167205
168206echo "Stopping cortex..."
169207su -c "$INSTALL_DIR /$CLI_BINARY_NAME stop > /dev/null 2>&1" $USER_TO_RUN_AS
170- rm -rf $INSTALL_DIR /$CLI_BINARY_NAME
171- rm -rf $INSTALL_DIR /$SERVER_BINARY_NAME
208+ rm -f $INSTALL_DIR /$CLI_BINARY_NAME
209+ rm -f $INSTALL_DIR /$SERVER_BINARY_NAME
172210rm -f $UNINSTALL_SCRIPT
173- rm -f $UPDATER_SCRIPT
174211
175212echo "Do you want to delete the ~/$DATA_DIR data folder and file ~/$CONFIGURATION_FILE ? (yes/no) [default: no]"
176213read -r answer
@@ -200,31 +237,45 @@ while true; do
200237done
201238
202239EOF
203- chmod +x $UNINSTALL_SCRIPT
204- echo " Uninstall script created at $UNINSTALL_SCRIPT "
205- }
206240
207- # Function to create updater script
208- create_updater_script () {
209- cat << EOF > $UPDATER_SCRIPT
241+ else
242+ cat << EOF > $UNINSTALL_SCRIPT
210243#!/bin/bash
211244# Check for root privileges
212245if [ "\$ (id -u)" != "0" ]; then
213246 echo "This script must be run as root. Please run again with sudo."
214247 exit 1
215248fi
216- echo "Stopping cortex for update..."
217- su -c " $INSTALL_DIR / $CLI_BINARY_NAME stop > /dev/null 2>&1" $USER_TO_RUN_AS
218- curl -s https://raw.githubusercontent.com/janhq/cortex/feat/linux-bash-install-script/engine/templates/linux/install.sh | bash -s -- --channel $CHANNEL --is_update
249+
250+ apt-get remove -y $DEB_APP_NAME
251+ rm -f $UNINSTALL_SCRIPT
219252EOF
220- chmod +x $UPDATER_SCRIPT
221- echo " Updater script created at $UPDATER_SCRIPT "
253+ fi
254+
255+ chmod +x $UNINSTALL_SCRIPT
256+ echo " Uninstall script created at $UNINSTALL_SCRIPT "
222257}
223258
224259# Run installation
225260check_install_jq_tar
226- install_cortex $CHANNEL $VERSION
227- create_uninstall_script
228- create_updater_script
229261
230- echo " Installation complete. Run cortex-uninstall.sh to uninstall and cortex-updater.sh to update."
262+ IS_DEB=" false"
263+
264+ # Check if apt-get command is available
265+ if command -v apt-get & > /dev/null; then
266+ if [ " $IS_UPDATE " = " true" ]; then
267+ # check if cortexcpp deb package is installed
268+ if dpkg -l | grep -q $DEB_APP_NAME ; then
269+ IS_DEB=" true"
270+ else
271+ IS_DEB=" false"
272+ fi
273+ else
274+ IS_DEB=" true"
275+ fi
276+ fi
277+
278+ install_cortex $CHANNEL $VERSION $IS_DEB
279+ create_uninstall_script $IS_DEB
280+
281+ echo " Installation complete. Run cortex-uninstall.sh to uninstall."
0 commit comments