github.com/grafana/pyroscope@v1.18.0/tools/packaging/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 | awk '/systemd /{print $2}')
     9  fi
    10  
    11  cleanInstall() {
    12      printf "\033[32m Post Install of a clean install\033[0m\n"
    13  
    14      if ! getent group pyroscope >/dev/null 2>&1; then
    15          groupadd --system pyroscope
    16      fi
    17      # Create the user
    18      if ! id pyroscope > /dev/null 2>&1 ; then
    19          adduser --system --home /var/lib/pyroscope --gid $(getent group pyroscope | awk -F ":" '{ print $3 }') --shell /bin/false "pyroscope"
    20      fi
    21      mkdir -p /var/lib/pyroscope
    22      chown pyroscope:pyroscope /var/lib/pyroscope
    23  
    24      # rhel/centos7 cannot use ExecStartPre=+ to specify the pre start should be run as root
    25      # even if you want your service to run as non root.
    26      if [ "${systemd_version}" -lt 231 ]; then
    27          printf "\033[31m systemd version %s is less then 231, fixing the service file \033[0m\n" "${systemd_version}"
    28          sed -i "s/=+/=/g" /etc/systemd/system/pyroscope.service
    29      fi
    30      printf "\033[32m Reload the service unit from disk\033[0m\n"
    31      systemctl daemon-reload ||:
    32      printf "\033[32m Unmask the service\033[0m\n"
    33      systemctl unmask pyroscope ||:
    34      printf "\033[32m Set the preset flag for the service unit\033[0m\n"
    35      systemctl preset pyroscope ||:
    36      printf "\033[32m Set the enabled flag for the service unit\033[0m\n"
    37      systemctl enable pyroscope ||:
    38      systemctl restart pyroscope ||:
    39  }
    40  
    41  upgrade() {
    42      :
    43      # printf "\033[32m Post Install of an upgrade\033[0m\n"
    44  }
    45  
    46  action="$1"
    47  if  [ "$1" = "configure" ] && [ -z "$2" ]; then
    48    # Alpine linux does not pass args, and deb passes $1=configure
    49    action="install"
    50  elif [ "$1" = "configure" ] && [ -n "$2" ]; then
    51      # deb passes $1=configure $2=<current version>
    52      action="upgrade"
    53  fi
    54  
    55  case "${action}" in
    56    "1" | "install")
    57      cleanInstall
    58      ;;
    59    "2" | "upgrade")
    60      upgrade
    61      ;;
    62    *)
    63      # $1 == version being installed
    64      printf "\033[32m Alpine\033[0m"
    65      cleanInstall
    66      ;;
    67  esac