| 1 | #!/usr/bin/env bash |
| 2 | # Package tree used for installing netdata on distribution: |
| 3 | # << FreeBSD >> |
| 4 | |
| 5 | set -e |
| 6 | |
| 7 | NON_INTERACTIVE=0 |
| 8 | DONT_WAIT=0 |
| 9 | |
| 10 | package_tree=" |
| 11 | bison |
| 12 | cmake |
| 13 | curl |
| 14 | e2fsprogs-libuuid |
| 15 | flex |
| 16 | git |
| 17 | gzip |
| 18 | json-c |
| 19 | liblz4 |
| 20 | libuv |
| 21 | libyaml |
| 22 | lzlib |
| 23 | openssl |
| 24 | pkgconf |
| 25 | python3 |
| 26 | " |
| 27 | |
| 28 | prompt() { |
| 29 | if [ "${NON_INTERACTIVE}" -eq 1 ]; then |
| 30 | echo >&2 "Running in non-interactive mode, assuming yes (y)" |
| 31 | echo >&2 " > Would have prompted for ${1} ..." |
| 32 | return 0 |
| 33 | fi |
| 34 | |
| 35 | while true; do |
| 36 | read -r -p "${1} [y/n] " yn |
| 37 | case $yn in |
| 38 | [Yy]*) return 0 ;; |
| 39 | [Nn]*) return 1 ;; |
| 40 | *) echo >&2 "Please answer with yes (y) or no (n)." ;; |
| 41 | esac |
| 42 | done |
| 43 | } |
| 44 | |
| 45 | usage() { |
| 46 | cat << EOF |
| 47 | OPTIONS: |
| 48 | [--dont-wait] [--non-interactive] [ ] |
| 49 | EOF |
| 50 | } |
| 51 | |
| 52 | check_flags() { |
| 53 | while [ -n "${1}" ]; do |
| 54 | case "${1}" in |
| 55 | dont-wait | --dont-wait | -n) |
| 56 | DONT_WAIT=1 |
| 57 | ;; |
| 58 | |
| 59 | non-interactive | --non-interactive | -y) |
| 60 | NON_INTERACTIVE=1 |
| 61 | ;; |
| 62 | |
| 63 | help | -h | --help) |
| 64 | usage |
| 65 | exit 1 |
| 66 | ;; |
| 67 | *) |
| 68 | echo >&2 "ERROR: Cannot understand option '${1}'" |
| 69 | echo >&2 |
| 70 | usage |
| 71 | exit 1 |
| 72 | ;; |
| 73 | esac |
| 74 | shift |
| 75 | done |
| 76 | |
| 77 | if [ "${DONT_WAIT}" -eq 0 ] && [ "${NON_INTERACTIVE}" -eq 0 ]; then |
| 78 | read -r -p "Press ENTER to run it > " || exit 1 |
| 79 | fi |
| 80 | } |
| 81 | |
| 82 | validate_tree_freebsd() { |
| 83 | opts= |
| 84 | if [ "${NON_INTERACTIVE}" -eq 1 ]; then |
| 85 | echo >&2 "Running in non-interactive mode" |
| 86 | opts="-y" |
| 87 | fi |
| 88 | |
| 89 | echo >&2 " > Checking for gmake ..." |
| 90 | if ! pkg query %n-%v | grep -q gmake; then |
| 91 | if prompt "gmake is required to build on FreeBSD and is not installed. Shall I install it?"; then |
| 92 | pkg install ${opts} gmake |
| 93 | fi |
| 94 | fi |
| 95 | } |
| 96 | |
| 97 | enable_repo () { |
| 98 | if ! dnf repolist | grep -q codeready; then |
| 99 | cat >> /etc/yum.repos.d/oracle-linux-ol8.repo <<-EOF |
| 100 | |
| 101 | [ol8_codeready_builder] |
| 102 | name=Oracle Linux \$releasever CodeReady Builder (\$basearch) |
| 103 | baseurl=http://yum.oracle.com/repo/OracleLinux/OL8/codeready/builder/\$basearch |
| 104 | gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle |
| 105 | gpgcheck=1 |
| 106 | enabled=1 |
| 107 | EOF |
| 108 | else |
| 109 | echo "Something went wrong!" |
| 110 | exit 1 |
| 111 | fi |
| 112 | } |
| 113 | |
| 114 | # shellcheck disable=SC2068 |
| 115 | check_flags ${@} |
| 116 | validate_tree_freebsd |
| 117 | |
| 118 | packages_to_install= |
| 119 | |
| 120 | for package in $package_tree; do |
| 121 | if pkg info -Ix "$package" &> /dev/null; then |
| 122 | echo "Package '${package}' is installed" |
| 123 | else |
| 124 | echo "Package '${package}' is NOT installed" |
| 125 | packages_to_install="$packages_to_install $package" |
| 126 | fi |
| 127 | done |
| 128 | |
| 129 | if [[ -z "$packages_to_install" ]]; then |
| 130 | echo "All required packages are already installed. Skipping .." |
| 131 | else |
| 132 | echo "packages_to_install:" "$packages_to_install" |
| 133 | opts= |
| 134 | if [ "${NON_INTERACTIVE}" -eq 1 ]; then |
| 135 | echo >&2 "Running in non-interactive mode" |
| 136 | opts="-y" |
| 137 | fi |
| 138 | # shellcheck disable=SC2086 |
| 139 | pkg install ${opts} $packages_to_install |
| 140 | fi |