github.com/yankunsam/loki/v2@v2.6.3-0.20220817130409-389df5235c27/tools/packaging/promtail-postinstall.sh (about)

     1  #!/bin/sh
     2  
     3  # Based on https://nfpm.goreleaser.com/tips/
     4  
     5  if ! command -V systemctl >/dev/null 2>&1; then
     6    echo "Could not find systemd. Skipping system installation." && exit 0
     7  else
     8      systemd_version=$(systemctl --version | head -1 | sed 's/systemd //g')
     9  fi
    10  
    11  cleanInstall() {
    12      printf "\033[32m Post Install of a clean install\033[0m\n"
    13  
    14      # Create the user
    15      if ! id promtail > /dev/null 2>&1 ; then
    16          adduser --system --shell /bin/false "promtail"
    17      fi
    18  
    19      # rhel/centos7 cannot use ExecStartPre=+ to specify the pre start should be run as root
    20      # even if you want your service to run as non root.
    21      if [ "${systemd_version}" -lt 231 ]; then
    22          printf "\033[31m systemd version %s is less then 231, fixing the service file \033[0m\n" "${systemd_version}"
    23          sed -i "s/=+/=/g" /etc/systemd/system/promtail.service
    24      fi
    25      printf "\033[32m Reload the service unit from disk\033[0m\n"
    26      systemctl daemon-reload ||:
    27      printf "\033[32m Unmask the service\033[0m\n"
    28      systemctl unmask promtail ||:
    29      printf "\033[32m Set the preset flag for the service unit\033[0m\n"
    30      systemctl preset promtail ||:
    31      printf "\033[32m Set the enabled flag for the service unit\033[0m\n"
    32      systemctl enable promtail ||:
    33      systemctl restart promtail ||:
    34  }
    35  
    36  upgrade() {
    37      :
    38      # printf "\033[32m Post Install of an upgrade\033[0m\n"
    39  }
    40  
    41  action="$1"
    42  if  [ "$1" = "configure" ] && [ -z "$2" ]; then
    43    # Alpine linux does not pass args, and deb passes $1=configure
    44    action="install"
    45  elif [ "$1" = "configure" ] && [ -n "$2" ]; then
    46      # deb passes $1=configure $2=<current version>
    47      action="upgrade"
    48  fi
    49  
    50  case "${action}" in
    51    "1" | "install")
    52      cleanInstall
    53      ;;
    54    "2" | "upgrade")
    55      upgrade
    56      ;;
    57    *)
    58      # $1 == version being installed
    59      printf "\033[32m Alpine\033[0m"
    60      cleanInstall
    61      ;;
    62  esac