taler-deployment

Deployment scripts and configuration files
Log | Files | Refs | README

functions.sh (1268B)


      1 #!/bin/bash
      2 
      3 notify_err() {
      4   say "errexit on line $(caller)"
      5   say "Error messages can be found at the end of setup.log"
      6   exit 1
      7 }
      8 
      9 trap notify_err ERR
     10 
     11 # Message
     12 function say() {
     13   echo "TALER: " "$@" >> setup.log
     14   echo "TALER: " "$@"
     15 }
     16 
     17 # Check user if the user is root
     18 function check_user() {
     19   if [ "$(whoami)" != "root" ]; then
     20     say "Please run this script as root"
     21     exit 1
     22   fi
     23 }
     24 
     25 # Set DISTRO to the detected distro or return non-zero
     26 # status if distro not supported.
     27 function detect_distro() {
     28   unset DISTRO
     29   [[ -f /etc/os-release ]] && source /etc/os-release
     30   # shellcheck disable=SC2034
     31   echo $NAME | grep Ubuntu >/dev/null && DISTRO=ubuntu && return 0
     32   # shellcheck disable=SC2034
     33   echo $NAME | grep Debian >/dev/null && DISTRO=debian && return 0
     34   echo "Unsupported distro, should be either ubuntu or debian" >&2
     35   return 1
     36 }
     37 
     38 # Fails if some required variables are not set
     39 function expect_vars() {
     40   for VAR_NAME in "$@"; do
     41     if test -z "${!VAR_NAME:-}"; then
     42       say "Error: ${VAR_NAME} not set"
     43       exit 1
     44     fi
     45   done
     46 }
     47 
     48 # Load dynamic and encrypted configuration using a python script
     49 function load_config() {
     50   {
     51     trap notify_err ERR
     52     CONF=$(./config.py 3>&1 1>&4 2>&5 4>&- 5>&-)
     53     eval "$CONF"
     54   } 4>&1 5>>setup.log
     55 }