|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +################################################## |
| 4 | +# Environment |
| 5 | +################################################## |
| 6 | + |
| 7 | +export DEBIAN_FRONTEND="noninteractive" |
| 8 | + |
| 9 | +################################################## |
| 10 | +# Function |
| 11 | +################################################## |
| 12 | + |
| 13 | +logger() { |
| 14 | + local type="${1}" |
| 15 | + local message="${2}" |
| 16 | + timestamp=$(date --rfc-3339=seconds) |
| 17 | + local timestamp |
| 18 | + |
| 19 | + case "${type}" in |
| 20 | + err | error) |
| 21 | + echo "${timestamp} [ERROR] ${message}" |
| 22 | + ;; |
| 23 | + info | information) |
| 24 | + echo "${timestamp} [INFO] ${message}" |
| 25 | + ;; |
| 26 | + warn | warning) |
| 27 | + echo "${timestamp} [WARN] ${message}" |
| 28 | + ;; |
| 29 | + esac |
| 30 | +} |
| 31 | + |
| 32 | +get_system_architecture() { |
| 33 | + systemArchitecture="$(uname -m)" |
| 34 | + export systemArchitecture |
| 35 | + |
| 36 | + case ${systemArchitecture} in |
| 37 | + x86_64) |
| 38 | + logger "info" "Architecture is x86_64" |
| 39 | + export ARCHITECTURE="amd64" |
| 40 | + ;; |
| 41 | + aarch64 | armv8*) |
| 42 | + logger "info" "Architecture is aarch64 or armv8" |
| 43 | + export ARCHITECTURE="arm64" |
| 44 | + ;; |
| 45 | + *) |
| 46 | + logger "error" "Architecture ${systemArchitecture} is not supported" |
| 47 | + exit 1 |
| 48 | + ;; |
| 49 | + esac |
| 50 | +} |
| 51 | + |
| 52 | +get_github_latest_tag() { |
| 53 | + local repository="${1}" |
| 54 | + |
| 55 | + repositoryLatestTag="$(curl --silent https://api.github.com/repos/"${repository}"/releases/latest | jq -r '.tag_name')" |
| 56 | + export repositoryLatestTag |
| 57 | + |
| 58 | + repositoryLatestTagStripV=${repositoryLatestTag//v/} |
| 59 | + |
| 60 | + logger "info" "GitHub latest tag for ${repository} is ${repositoryLatestTag}" |
| 61 | + export GITHUB_LATEST_TAG="${repositoryLatestTag}" |
| 62 | + export GITHUB_LATEST_TAG_STRIP_V="${repositoryLatestTagStripV}" |
| 63 | +} |
| 64 | + |
| 65 | +apt_install() { |
| 66 | + local packages="${1}" |
| 67 | + |
| 68 | + apt-get update --yes |
| 69 | + |
| 70 | + apt-get install --yes --no-install-recommends "${packages}" |
| 71 | + |
| 72 | + apt-get clean |
| 73 | + |
| 74 | + rm --force --recursive /var/lib/apt/lists/* |
| 75 | +} |
| 76 | + |
| 77 | +pip_install() { |
| 78 | + local packages="${1}" |
| 79 | + |
| 80 | + python3 -m pip install --no-cache-dir --upgrade "${packages}" |
| 81 | +} |
0 commit comments