install nvm sous apxtri

This commit is contained in:
2025-07-24 12:47:25 +00:00
parent 00b717aeee
commit 957713ee77

View File

@@ -14,11 +14,11 @@ echo "Welcome to the setup of apXtri ! Thank you for choosing us!"
sleep 1
echo "Starting up the installation..."
# Update and install useful tools
# Update and useful tools
sudo apt update
sudo apt install -y curl git build-essential
# Create necessary directories and apply proper permissions
# Create necessaries reposetories and apply good permissions
sudo mkdir -p "$APP_DIR"
sudo mkdir -p "$DATAPATH"
sudo mkdir -p "$LOGPATH"
@@ -26,7 +26,7 @@ sudo chown -R "$APXTRI_USER":"$APXTRI_USER" "$NODEPATH"
sudo chown -R "$APXTRI_USER":"$APXTRI_USER" "$DATAPATH"
sudo chown -R "$APXTRI_USER":"$APXTRI_USER" "$LOGPATH"
# Check if Caddy is already running
# Check if Caddy exist
echo "Checking if Caddy is already running..."
if pgrep -x caddy > /dev/null; then
echo "Caddy appears to be running."
@@ -45,7 +45,7 @@ if pgrep -x caddy > /dev/null; then
fi
fi
# Check if default ports are already in use
# Check default ports in
echo "Check if default ports are already in use..."
PORTS=(3021 3031)
for PORT in "${PORTS[@]}"; do
@@ -59,9 +59,12 @@ for PORT in "${PORTS[@]}"; do
fi
done
# Install Caddy
echo "Installing Caddy web server..."
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl jq
#curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo tee /etc/apt/trusted.gpg.d/caddy.gpg > /dev/null
#curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy.list
curl -fsSL https://dl.cloudsmith.io/public/caddy/stable/gpg.key | gpg --dearmor | sudo tee /etc/apt/keyrings/caddy-stable.gpg > /dev/null
echo "deb [signed-by=/etc/apt/keyrings/caddy-stable.gpg] https://dl.cloudsmith.io/public/caddy/stable/deb/debian any-version main" | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
@@ -74,7 +77,7 @@ else
echo "admin.apxtri already present in /etc/hosts"
fi
# Create user apxtri if not existing
# Create user apxtri if not existing
if id "$APXTRI_USER" &>/dev/null; then
echo "User $APXTRI_USER already exists."
else
@@ -82,9 +85,11 @@ else
sudo useradd -m -s /bin/bash "$APXTRI_USER"
echo "Set password for $APXTRI_USER:"
sudo passwd "$APXTRI_USER"
#sudo usermod -aG sudo "$APXTRI_USER"
fi
# Clone repos
sudo su "$APXTRI_USER" #changer mdp
echo "Cloning objects into $DATAPATH/data/objects..."
mkdir -p "$DATAPATH/data"
cd $DATAPATH/data
@@ -94,50 +99,46 @@ echo "Creating useful repos..."
mkdir -p "$DATAPATH/data/apxtri/logs"
mkdir -p "$DATAPATH/data/apxtri/backups"
mkdir -p "$DATAPATH/data/apxtri/tmp"
# Switch user to apxtri and install packages
echo "Switch user to $APXTRI_USER for install packages..."
echo "Cloning apXtri into $APP_DIR..."
cd $APP_DIR
git clone $REPO_APXTRI
cd apxtri
# Installer NVM dans le répertoire de l'utilisateur apxtri (pas root)
# Installer NVM
export NVM_VERSION="v0.39.7"
echo "Installing NVM version $NVM_VERSION..."
sudo -u "$APXTRI_USER" bash -c "
export NVM_VERSION=\"v0.39.7\" &&
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/$NVM_VERSION/install.sh | bash
"
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/$NVM_VERSION/install.sh | bash
# Charger NVM dans le shell de l'utilisateur apxtri
echo "NVM loading for user $APXTRI_USER..."
sudo -u "$APXTRI_USER" bash -c "
export NVM_DIR=\"\$HOME/.nvm\" &&
[ -s \"\$NVM_DIR/nvm.sh\" ] && . \"\$NVM_DIR/nvm.sh\"
"
# Charger NVM dans le shell courant
export NVM_DIR="$HOME/.nvm"
# Source le script nvm.sh si disponible
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
echo "NVM loaded from $NVM_DIR"
echo "Installing Node.js LTS version..."
sudo -u "$APXTRI_USER" bash -c "
nvm install --lts &&
nvm use --lts &&
nvm alias default 'lts/*'
"
nvm install --lts
nvm use --lts
nvm alias default 'lts/*'
# Vérification
sudo -u "$APXTRI_USER" bash -c "node -v && npm -v"
node -v
npm -v
echo "Installing Yarn..."
sudo -u "$APXTRI_USER" bash -c "
npm install -g corepack &&
corepack enable &&
corepack prepare yarn@stable --activate &&
yarn --version
"
npm install -g corepack
corepack enable
corepack prepare yarn@stable --activate
yarn --version
echo "Installing dependencies with Yarn..."
sudo -u "$APXTRI_USER" bash -c "yarn install"
yarn install
echo "Installing dependencies with Yarn..."
yarn install
# Génération du fichier .env
echo "Generating .env file..."
cat << EOL > ".env"
TOWN=$TOWN
@@ -156,8 +157,7 @@ CADDYAPIURL=http://localhost:2019/
# Personalised install
EOL
# Exécution de la commande yarn dev en tant qu'utilisateur apxtri
echo "Launching apXtri as $APXTRI_USER..."
sudo -u "$APXTRI_USER" bash -c "source $HOME/.nvm/nvm.sh && yarn dev"
yarn dev
echo "Installation complete!"