Просмотр исходного кода

Chore/config updates (#4470)

* Bugfix: Initial Node.js setup

* Cleanup tmp directory after app install

* Streamline Node.js installation when needed

* Run NPM run format

---------

Co-authored-by: Jaap Marcus <9754650+jaapmarcus@users.noreply.github.com>
Alexandros Ioannides 1 год назад
Родитель
Сommit
82d063ea9d

+ 20 - 9
bin/v-add-sys-web-terminal

@@ -36,21 +36,32 @@ check_hestia_demo_mode
 # Updating WEB_TERMINAL value
 $BIN/v-change-sys-config-value "WEB_TERMINAL" "true"
 
-# Check if Node.js is installed if not install repo
+# Detect and install Node.js if necessary
 apt="/etc/apt/sources.list.d"
-codename="$(lsb_release -s -c)"
+node_v="20"
 
-if [ ! -z $(which "node") ]; then
-	echo "Adding Node.js 20.x repo..."
-	echo "deb [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x $codename main" > $apt/nodesource.list
-	echo "deb-src [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x $codename main" >> $apt/nodesource.list
-	curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor | tee /usr/share/keyrings/nodesource.gpg > /dev/null 2>&1
+if [ $(uname -m) = "x86_64" ]; then
+	ARCH=amd64
+elif [ $(uname -m) = "aarch64" ]; then
+	ARCH=arm64
+fi
+
+if [ -z $(which "node") ]; then
+	echo "Installing Node.js $node_v"
+	echo "deb [arch=$ARCH signed-by=/usr/share/keyrings/nodejs.gpg] https://deb.nodesource.com/node_$node_v.x nodistro main" > $apt/nodejs.list
+	curl -s https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor | tee /usr/share/keyrings/nodejs.gpg > /dev/null 2>&1
+	apt-get -qq install nodejs -y
+else
+	node_v_installed=$(/usr/bin/node -v | cut -f1 -d'.' | sed 's/v//g')
+	if [ "$node_v_installed" -lt "$node_v" ]; then
+		echo "Web Terminal requires Node.js 20.x or higher"
+		exit 1
+	fi
 fi
 
 if [ ! -f "$HESTIA/web-terminal/server.js" ]; then
-	# Install hestia-web-terminal package + nodejs
 	apt-get -qq update
-	apt-get -qq install nodejs hestia-web-terminal -y
+	apt-get -qq install hestia-web-terminal -y
 else
 	# Starting web terminal websocket server
 	$BIN/v-start-service "hestia-web-terminal"

+ 10 - 11
bin/v-update-sys-hestia-git

@@ -20,24 +20,23 @@ source /etc/hestiacp/hestia.conf
 source $HESTIA/func/main.sh
 # load config file
 source_conf "$HESTIA/conf/hestia.conf"
-# define Node.js version for download (required for building JS/CSS)
-NODE_MAJOR=20
 
 # Perform verification if read-only mode is enabled
 check_hestia_demo_mode
 
 # Detect and install Node.js if necessary
 if [ -z $(which "node") ]; then
-	read -p "Node.js not found. Install now to proceed? [Y/n] " answer
-	if [ "$answer" = 'y' ] || [ "$answer" = 'Y' ]; then
-		sudo mkdir -p /etc/apt/keyrings
-		curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
-
-		echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
-		sudo apt-get install -y nodejs
-	else
-		exit 0
+	echo "Installing Node.js $node_v"
+	apt="/etc/apt/sources.list.d"
+	node_v="20"
+	if [ $(uname -m) = "x86_64" ]; then
+		ARCH=amd64
+	elif [ $(uname -m) = "aarch64" ]; then
+		ARCH=arm64
 	fi
+	echo "deb [arch=$ARCH signed-by=/usr/share/keyrings/nodejs.gpg] https://deb.nodesource.com/node_$node_v.x nodistro main" > $apt/nodejs.list
+	curl -s https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor | tee /usr/share/keyrings/nodejs.gpg > /dev/null 2>&1
+	apt-get -qq install nodejs -y
 fi
 
 # Define download function

+ 2 - 2
install/hst-install-debian.sh

@@ -871,7 +871,7 @@ if [ "$webterminal" = 'yes' ]; then
 	echo "[ * ] Node.js $node_v"
 	echo "deb [arch=$ARCH signed-by=/usr/share/keyrings/nodejs.gpg] https://deb.nodesource.com/node_$node_v.x nodistro main" > $apt/nodejs.list
 	curl -s https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor | tee /usr/share/keyrings/nodejs.gpg > /dev/null 2>&1
-	curl -fsSL https://deb.nodesource.com/setup_$node_v.x | bash -
+	apt-get -y install nodejs > $LOG
 fi
 
 # Installing PostgreSQL repo
@@ -2352,7 +2352,7 @@ chown hestiaweb:hestiaweb /var/spool/cron/crontabs/hestiaweb
 # Enable automatic updates
 $HESTIA/bin/v-add-cron-hestia-autoupdate apt
 
-# Building initital rrd images
+# Building initial rrd images
 $HESTIA/bin/v-update-sys-rrd
 
 # Enabling file system quota

+ 2 - 2
install/hst-install-ubuntu.sh

@@ -841,7 +841,7 @@ if [ "$webterminal" = 'yes' ]; then
 	echo "[ * ] Node.js $node_v"
 	echo "deb [arch=$ARCH signed-by=/usr/share/keyrings/nodejs.gpg] https://deb.nodesource.com/node_$node_v.x nodistro main" > $apt/nodejs.list
 	curl -s https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor | tee /usr/share/keyrings/nodejs.gpg > /dev/null 2>&1
-	curl -fsSL https://deb.nodesource.com/setup_$node_v.x | bash -
+	apt-get -y install nodejs > $LOG
 fi
 
 # Installing PostgreSQL repo
@@ -2346,7 +2346,7 @@ chown hestiaweb:hestiaweb /var/spool/cron/crontabs/hestiaweb
 # Enable automatic updates
 $HESTIA/bin/v-add-cron-hestia-autoupdate apt
 
-# Building initital rrd images
+# Building initial rrd images
 $HESTIA/bin/v-update-sys-rrd
 
 # Enabling file system quota

+ 1 - 13
install/upgrade/versions/1.9.0.sh

@@ -27,18 +27,6 @@ upgrade_config_set_value 'UPGRADE_UPDATE_FILEMANAGER_CONFIG' 'false'
 $BIN/v-delete-sys-sftp-jail
 $BIN/v-add-sys-sftp-jail
 
-codename="$(lsb_release -s -c)"
-apt=/etc/apt/sources.list.d
-
-# Installing Node.js repo
-if [ "$webterminal" = 'yes' ]; then
-	node_v="20"
-	echo "[ * ] Adding Node.js $node_v repo and install"
-	echo "deb [arch=$ARCH signed-by=/usr/share/keyrings/nodejs.gpg] https://deb.nodesource.com/node_$node_v.x nodistro main" > $apt/nodejs.list
-	curl -s https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor | tee /usr/share/keyrings/nodejs.gpg > /dev/null 2>&1
-	curl -fsSL https://deb.nodesource.com/setup_$node_v.x | bash -
-fi
-
 # Check if hestiaweb exists
 if [ -z "$(grep ^hestiaweb: /etc/passwd)" ]; then
 	# Generate a random password
@@ -50,7 +38,7 @@ if [ -z "$(grep ^hestiaweb: /etc/passwd)" ]; then
 	cp $HESTIA_COMMON_DIR/sudo/hestiaweb /etc/sudoers.d/
 	# Keep enabled for now
 	# Remove sudo permissions admin user
-	#rm /etc/sudoers.d/admin/
+	# rm /etc/sudoers.d/admin/
 fi
 
 # Check if cronjobs have been migrated

+ 13 - 0
web/src/app/System/HestiaApp.php

@@ -350,4 +350,17 @@ class HestiaApp {
 
 		return $result;
 	}
+
+	public function cleanupTmpDir(): void {
+		$files = glob(self::TMPDIR_DOWNLOADS . "/*");
+		foreach ($files as $file) {
+			if (is_file($file)) {
+				unlink($file);
+			}
+		}
+	}
+
+	public function __destruct() {
+		$this->cleanupTmpDir();
+	}
 }