taler-windows

Windows packaging
Log | Files | Refs

install-taler-from-apt.sh (6326B)


      1 #!/bin/bash
      2 # This file is part of GNU Taler.
      3 # Copyright (C) 2025 Taler Systems SA
      4 #
      5 # Author: Léa Oualli
      6 
      7 set -e
      8 set -x
      9 trap 'echo "Error occurred on line $LINENO." >&2' ERR
     10 
     11 LOGFILE="/mnt/c/Users/Public/taler-sh.log"
     12 exec > >(tee -a "$LOGFILE") 2>&1
     13 
     14 mkdir -p /home/taleruser/taler-installer
     15 
     16 WSL_USER="taleruser"
     17 TALER_DB_USER="taler-merchant-httpd"
     18 
     19 #############################################
     20 # -------- HTTPS / Reverse Proxy -----------#
     21 #############################################
     22 # Si le script est appelé avec "8" et un domaine, on ne fait QUE la config HTTPS/proxy :
     23 if [ "$1" = "8" ] && [ -n "$2" ]; then
     24   DOMAIN="$2"
     25   echo "Configuring HTTPS reverse proxy for domain: $DOMAIN"
     26   if ! sudo taler-merchant-rproxy-setup --domain "$DOMAIN" --apache --httpsonly; then
     27     echo "WARNING: Impossible d’obtenir un certificat HTTPS valide pour $DOMAIN (vérifie le DNS, les ports 80/443, et Internet)" | tee -a "/home/$WSL_USER/taler-installer/install-sh.log"
     28     # On ne bloque pas toute l'install, on log juste le problème
     29     exit 0
     30   fi
     31   echo "HTTPS reverse proxy configured for $DOMAIN" | tee -a "/home/$WSL_USER/taler-installer/install-sh.log"
     32   exit 0
     33 fi
     34 #############################################
     35 
     36 #############################################
     37 # ---- HTTP ONLY / Reverse Proxy HTTP ------#
     38 #############################################
     39 if [ "$1" = "http" ] && [ -n "$2" ]; then
     40   DOMAIN="$2"
     41   echo "Configuring HTTP-only reverse proxy for domain: $DOMAIN"
     42   if ! sudo taler-merchant-rproxy-setup --domain "$DOMAIN" --httponly --apache; then
     43     echo "WARNING: Echec configuration HTTP-only reverse proxy pour $DOMAIN" | tee -a "/home/$WSL_USER/taler-installer/install-sh.log"
     44     exit 1
     45   fi
     46   echo "HTTP-only reverse proxy configured for $DOMAIN" | tee -a "/home/$WSL_USER/taler-installer/install-sh.log"
     47   exit 0
     48 fi
     49 #############################################
     50 
     51 
     52 # Vérification de l'utilisateur système
     53 if ! id "$WSL_USER" &>/dev/null; then
     54   echo "System user $WSL_USER not found. Please create it." >&2
     55   exit 1
     56 fi
     57 
     58 echo "Adding user $WSL_USER to www-data group..."
     59 sudo usermod -aG www-data $WSL_USER || {
     60   echo "Failed to add $WSL_USER to www-data group." >&2
     61   exit 1
     62 }
     63 
     64 sudo apt-get update
     65 sudo apt-get install -y gnupg wget curl lsb-release apt-transport-https ca-certificates || {
     66   echo "Base dependencies installation failed." >&2
     67   exit 1
     68 }
     69 
     70 sudo apt-get install -y postgresql || {
     71   echo "PostgreSQL installation failed." >&2
     72   exit 1
     73 }
     74 
     75 sudo systemctl enable postgresql
     76 sudo systemctl start postgresql
     77 
     78 echo "Creating PostgreSQL user $WSL_USER..."
     79 sudo -u postgres createuser --createdb "$WSL_USER" || echo "User $WSL_USER already exists, continuing..."
     80 
     81 echo "Creating PostgreSQL user $TALER_DB_USER..."
     82 sudo -u postgres createuser --createdb "$TALER_DB_USER" || echo "User $TALER_DB_USER already exists, continuing..."
     83 
     84 echo "Adding GNU Taler repository..."
     85 
     86 # --- DÉTECTION DE LA DISTRIBUTION ET AJOUT DU BON DÉPÔT ---
     87 DISTRO="$(lsb_release -is 2>/dev/null || echo Debian)"
     88 CODENAME="$(lsb_release -cs 2>/dev/null || echo bookworm)"
     89 sudo mkdir -p /etc/apt/keyrings
     90 
     91 # Importe la clé
     92 curl -fsSL https://taler.net/taler-systems.gpg | gpg --dearmor | sudo tee /etc/apt/keyrings/taler-systems.gpg > /dev/null
     93 
     94 if [ "$DISTRO" = "Ubuntu" ]; then
     95   echo "deb [signed-by=/etc/apt/keyrings/taler-systems.gpg] https://deb.taler.net/apt/ubuntu/ $CODENAME main" \
     96     | sudo tee /etc/apt/sources.list.d/taler.list
     97 else
     98   echo "deb [signed-by=/etc/apt/keyrings/taler-systems.gpg] https://deb.taler.net/apt/debian/ $CODENAME main" \
     99     | sudo tee /etc/apt/sources.list.d/taler.list
    100 fi
    101 
    102 # ---------------------------------------------------------
    103 
    104 sudo apt-get update
    105 sudo apt-get install -y taler-merchant || {
    106   echo "GNU Taler installation failed." >&2
    107   exit 1
    108 }
    109 
    110 # Only the "certbot" package is required: taler-merchant-rproxy-setup runs
    111 # "certbot certonly --webroot", which is built into certbot core.  Do NOT
    112 # add python3-certbot-nginx here -- it Depends on nginx, and an nginx
    113 # holding port 80 prevents the apache2 installed in step 8 from starting,
    114 # which in turn makes taler-merchant-rproxy-setup fail.
    115 sudo apt-get install -y certbot || {
    116   echo "Certbot installation failed." >&2
    117   exit 1
    118 }
    119 
    120 # Do NOT overwrite /etc/taler-merchant/taler-merchant.conf.  The package
    121 # ships it as the entry point that pulls in everything else:
    122 #   [paths]                     -> TALER_RUNTIME_DIR, TALER_CONFIG_HOME, ...
    123 #   @inline-matching@ conf.d/*  -> [merchant] SERVE = systemd
    124 #   @inline-secret@ ...         -> [merchantdb-postgres] CONFIG (database)
    125 # Replacing it removed the mandatory SERVE option, so taler-merchant-httpd
    126 # aborted with "serve type (tcp, unix or systemd) required", and removed the
    127 # database configuration.  It also set UNIX_DOMAIN_SOCKETS, which is not an
    128 # option the merchant reads at all.  The shipped defaults are what we want:
    129 # socket activation on /run/taler-merchant/httpd/merchant-http.sock, which
    130 # the Apache vhost shipped by the same package proxies to.  Any override
    131 # belongs in a conf.d/ drop-in, never in this file.
    132 MAIN_CONF="/etc/taler-merchant/taler-merchant.conf"
    133 if [ ! -f "$MAIN_CONF" ]; then
    134   echo "Expected $MAIN_CONF to be shipped by the taler-merchant package." >&2
    135   exit 1
    136 fi
    137 echo "Using packaged configuration at $MAIN_CONF"
    138 
    139 echo "Initializing database with taler-merchant-dbconfig..."
    140 if ! sudo taler-merchant-dbconfig; then
    141   echo "Error during taler-merchant-dbconfig" >&2
    142   exit 1
    143 fi
    144 
    145 # taler-merchant-httpd.service has Requires=taler-merchant-httpd.socket and
    146 # is started through socket activation: enable the socket, not the service.
    147 echo "Enabling taler-merchant-httpd.socket and taler-merchant.target..."
    148 sudo systemctl enable taler-merchant-httpd.socket
    149 sudo systemctl enable taler-merchant.target
    150 sudo systemctl restart taler-merchant.target
    151 
    152 echo "Checking taler-merchant status..."
    153 sudo systemctl status taler-merchant-httpd.service --no-pager || true
    154 sudo systemctl status taler-merchant-httpd.socket --no-pager || true
    155 
    156 mkdir -p "/home/$WSL_USER/taler-installer"
    157 sudo chown -R "$WSL_USER:$WSL_USER" "/home/$WSL_USER/taler-installer"
    158 echo "GNU Taler-Merchant installed successfully via system config" | tee "/home/$WSL_USER/taler-installer/install-sh.log"
    159 
    160 echo "[`date '+%F %T'`] === END OF taler-sh.log ==="
    161 
    162 
    163