106 lines
3.4 KiB
Bash
106 lines
3.4 KiB
Bash
#!/bin/bash
|
|
|
|
# Définir le nom de l'utilisateur
|
|
APXTRI_USER="apxtri"
|
|
|
|
|
|
|
|
# Update and useful tools
|
|
apt update
|
|
apt install -y curl git build-essential
|
|
|
|
# Check if Caddy exist
|
|
echo "Checking if Caddy is already running..."
|
|
if pgrep -x caddy >/dev/null; then
|
|
echo "Caddy appears to be running."
|
|
|
|
existing_routes=$(curl -s http://localhost:2019/config/ | jq -r '.apps.http.servers | keys[]?' 2>/dev/null)
|
|
|
|
if [ -n "$existing_routes" ] && [ "$existing_routes" != "srv0" ]; then
|
|
echo "Caddy is configured with non-default routes: $existing_routes"
|
|
read -p "Do you want to overwrite the current Caddy configuration? [y/N]: " confirm
|
|
if [[ "$confirm" != "y" && "$confirm" != "Y" ]]; then
|
|
echo "Installation aborted to preserve existing Caddy setup."
|
|
exit 1
|
|
fi
|
|
else
|
|
echo "Caddy is running but appears to use the default config."
|
|
fi
|
|
fi
|
|
|
|
# Check default ports in
|
|
echo "Check if default ports are already in use..."
|
|
PORTS=(3021 3031)
|
|
for PORT in "${PORTS[@]}"; do
|
|
if ss -tuln | grep -q ":$PORT "; then
|
|
echo "Port $PORT is already in use. This may conflict with apXtri."
|
|
read -p "Do you want to continue and risk overwriting services on port $PORT? [y/N]: " port_confirm
|
|
if [[ "$port_confirm" != "y" && "$port_confirm" != "Y" ]]; then
|
|
echo "Installation aborted to avoid port conflict."
|
|
exit 1
|
|
fi
|
|
fi
|
|
done
|
|
|
|
echo "Installing Caddy web server..."
|
|
|
|
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 | 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" | tee /etc/apt/sources.list.d/caddy-stable.list
|
|
apt install -y caddy
|
|
|
|
# Add admin.apxtri domain to /etc/hosts
|
|
if ! grep -q "admin.apxtri.farm.ants" /etc/hosts; then
|
|
echo "127.0.0.1 admin.apxtri.farm.ants" | tee -a /etc/hosts
|
|
else
|
|
echo "admin.apxtri already present in /etc/hosts"
|
|
fi
|
|
|
|
# Installer NVM
|
|
export NVM_VERSION="v0.39.7"
|
|
echo "Installing NVM version $NVM_VERSION..."
|
|
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/$NVM_VERSION/install.sh | bash
|
|
|
|
# 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..."
|
|
nvm install --lts
|
|
nvm use --lts
|
|
nvm alias default 'lts/*'
|
|
|
|
# Vérification
|
|
node -v
|
|
npm -v
|
|
|
|
echo "Installing Yarn..."
|
|
npm install -g corepack
|
|
corepack enable
|
|
corepack prepare yarn@stable --activate
|
|
yarn --version
|
|
|
|
# Vérifier si l'utilisateur existe déjà
|
|
if id "$APXTRI_USER" &>/dev/null; then
|
|
echo "L'utilisateur $APXTRI_USER existe déjà."
|
|
else
|
|
# Créer l'utilisateur apxtri
|
|
echo "Création de l'utilisateur $APXTRI_USER..."
|
|
sudo useradd -m -s /bin/bash "$APXTRI_USER"
|
|
DEFAULT_PASSWORD="malayme42"
|
|
echo "$APXTRI_USER:$DEFAULT_PASSWORD" | sudo chpasswd
|
|
fi
|
|
|
|
sudo -u $APXTRI_USER bash -c "
|
|
cd ~
|
|
wget https://gitea.ndda.fr/apxtri/apxtri/raw/branch/main/setup/install.sh
|
|
chmod +x install.sh
|
|
source ~/.bashrc
|
|
./install.sh
|
|
"
|