mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-03 15:02:34 +00:00
use blade as conmmands template (#444)
* use blade as conmmands template * fix lint * fix ssl
This commit is contained in:
@ -2,15 +2,13 @@
|
||||
|
||||
namespace App\SSH\Services\NodeJS;
|
||||
|
||||
use App\SSH\HasScripts;
|
||||
use App\Exceptions\SSHError;
|
||||
use App\SSH\Services\AbstractService;
|
||||
use Closure;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class NodeJS extends AbstractService
|
||||
{
|
||||
use HasScripts;
|
||||
|
||||
public function creationRules(array $input): array
|
||||
{
|
||||
return [
|
||||
@ -41,34 +39,43 @@ function (string $attribute, mixed $value, Closure $fail) {
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SSHError
|
||||
*/
|
||||
public function install(): void
|
||||
{
|
||||
$server = $this->service->server;
|
||||
$server->ssh()->exec(
|
||||
$this->getScript('install-nodejs.sh', [
|
||||
view('ssh.services.nodejs.install-nodejs', [
|
||||
'version' => $this->service->version,
|
||||
'user' => $server->getSshUser(),
|
||||
]),
|
||||
'install-nodejs-'.$this->service->version
|
||||
);
|
||||
$this->service->server->os()->cleanup();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SSHError
|
||||
*/
|
||||
public function uninstall(): void
|
||||
{
|
||||
$this->service->server->ssh()->exec(
|
||||
$this->getScript('uninstall-nodejs.sh', [
|
||||
view('ssh.services.nodejs.uninstall-nodejs', [
|
||||
'version' => $this->service->version,
|
||||
'default' => $this->service->is_default,
|
||||
]),
|
||||
'uninstall-nodejs-'.$this->service->version
|
||||
);
|
||||
$this->service->server->os()->cleanup();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SSHError
|
||||
*/
|
||||
public function setDefaultCli(): void
|
||||
{
|
||||
$this->service->server->ssh()->exec(
|
||||
$this->getScript('change-default-nodejs.sh', [
|
||||
view('ssh.services.nodejs.change-default-nodejs', [
|
||||
'version' => $this->service->version,
|
||||
]),
|
||||
'change-default-nodejs'
|
||||
|
@ -1,13 +0,0 @@
|
||||
export NVM_DIR="$HOME/.nvm"
|
||||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
|
||||
|
||||
if ! nvm alias default __version__; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
if ! nvm use default; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
echo "Default Node.js is now:"
|
||||
node -v
|
@ -1,68 +0,0 @@
|
||||
# Download NVM, if not already downloaded
|
||||
if [ ! -d "$HOME/.nvm" ]; then
|
||||
if ! git clone https://github.com/nvm-sh/nvm.git "$HOME/.nvm"; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Checkout the latest stable version of NVM
|
||||
if ! git -C "$HOME/.nvm" checkout v0.40.1; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
# Load NVM
|
||||
export NVM_DIR="$HOME/.nvm"
|
||||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
|
||||
|
||||
# Define the NVM initialization script
|
||||
NVM_INIT='
|
||||
export NVM_DIR="$HOME/.nvm"
|
||||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
|
||||
'
|
||||
|
||||
# List of potential configuration files
|
||||
CONFIG_FILES=("$HOME/.bash_profile" "$HOME/.bash_login" "$HOME/.profile")
|
||||
|
||||
# Flag to track if at least one file exists
|
||||
FILE_EXISTS=false
|
||||
|
||||
# Loop through each configuration file and check if it exists
|
||||
for config_file in "${CONFIG_FILES[@]}"; do
|
||||
if [ -f "$config_file" ]; then
|
||||
FILE_EXISTS=true
|
||||
# Check if the NVM initialization is already present
|
||||
if ! grep -q 'export NVM_DIR="$HOME/.nvm"' "$config_file"; then
|
||||
echo "Adding NVM initialization to $config_file"
|
||||
echo "$NVM_INIT" >> "$config_file"
|
||||
else
|
||||
echo "NVM initialization already exists in $config_file"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
# If no file exists, fallback to .profile
|
||||
if [ "$FILE_EXISTS" = false ]; then
|
||||
FALLBACK_FILE="$HOME/.profile"
|
||||
echo "No configuration files found. Creating $FALLBACK_FILE and adding NVM initialization."
|
||||
echo "$NVM_INIT" >> "$FALLBACK_FILE"
|
||||
fi
|
||||
|
||||
echo "NVM initialization process completed."
|
||||
|
||||
# Install NVM if not already installed
|
||||
if ! command -v nvm > /dev/null 2>&1; then
|
||||
if ! bash "$HOME/.nvm/install.sh"; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Install the requested Node.js version
|
||||
if ! nvm install __version__; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
echo "Node.js version __version__ installed successfully!"
|
||||
|
||||
echo "Node version:" && node -v
|
||||
echo "NPM version:" && npm -v
|
||||
echo "NPX version:" && npx -v
|
@ -1,6 +0,0 @@
|
||||
export NVM_DIR="$HOME/.nvm"
|
||||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
|
||||
|
||||
if ! nvm uninstall __version__; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
Reference in New Issue
Block a user