|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -eu -o pipefail |
| 4 | + |
| 5 | +if [ "$(id -u)" -ne 0 ]; then |
| 6 | + echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' |
| 7 | + exit 1 |
| 8 | +fi |
| 9 | + |
| 10 | +add_global_run_command() { |
| 11 | + local command=$1 |
| 12 | + |
| 13 | + if [ -f "/etc/os-release" ] && grep "ID_LIKE=.*alpine.*\|ID=.*alpine.*" /etc/os-release; then |
| 14 | + if [ -f "/etc/profile" ] && [[ "$(cat /etc/profile)" != *"${command}"* ]]; then |
| 15 | + echo "Add ${command} to /etc/profile" |
| 16 | + echo -e "${command}" >>/etc/profile |
| 17 | + fi |
| 18 | + fi |
| 19 | + |
| 20 | + if [ -f "/etc/bash.bashrc" ] && [[ "$(cat /etc/bash.bashrc)" != *"${command}"* ]]; then |
| 21 | + echo "Add ${command} to /etc/bash.bashrc" |
| 22 | + echo -e "${command}" >>/etc/bash.bashrc |
| 23 | + fi |
| 24 | + |
| 25 | + if [ -f "/etc/zsh/zshrc" ] && [[ "$(cat /etc/zsh/zshrc)" != *"${command}"* ]]; then |
| 26 | + echo "Add ${command} to /etc/zsh/zshrc" |
| 27 | + echo -e "${command}" >>/etc/zsh/zshrc |
| 28 | + fi |
| 29 | +} |
| 30 | + |
| 31 | +install_aqua_binary() { |
| 32 | + local aquq_root_dir=$1 |
| 33 | + local aqua_installer_version=$2 |
| 34 | + local aqua_version=$3 |
| 35 | + |
| 36 | + mkdir -p "${aquq_root_dir}" |
| 37 | + |
| 38 | + local aqua_installer_ref='main' |
| 39 | + if [ -n "${aqua_installer_version}" ] && [ "${aqua_installer_version}" != 'latest' ]; then |
| 40 | + aqua_installer_ref="v${aqua_installer_version##v}" |
| 41 | + fi |
| 42 | + local aqua_installer_url="https://raw.githubusercontent.com/aquaproj/aqua-installer/${aqua_installer_ref}/aqua-installer" |
| 43 | + |
| 44 | + local command="curl -fsSL \"${aqua_installer_url}\" | AQUA_ROOT_DIR=\"${aquq_root_dir}\" bash -s --" |
| 45 | + if [ -n "${aqua_version}" ] && [ "${aqua_version}" != 'latest' ]; then |
| 46 | + command="${command} -v v${aqua_version##v}" |
| 47 | + fi |
| 48 | + |
| 49 | + bash -c "${command}" |
| 50 | +} |
| 51 | + |
| 52 | +make_aqua_user_writable() { |
| 53 | + local aquq_root_dir=$1 |
| 54 | + local aqua_user_name=$2 |
| 55 | + |
| 56 | + groupadd aqua |
| 57 | + gpasswd -a "${aqua_user_name}" aqua |
| 58 | + chgrp -R aqua "${aquq_root_dir}" |
| 59 | + chmod -R g+rws "${aquq_root_dir}" |
| 60 | +} |
| 61 | + |
| 62 | +add_aqua_environment_variables() { |
| 63 | + local aquq_root_dir=$1 |
| 64 | + |
| 65 | + add_global_run_command "export AQUA_ROOT_DIR=\"${aquq_root_dir}\"" |
| 66 | + add_global_run_command "if [[ \"\${PATH}\" != *\"\${AQUA_ROOT_DIR}/bin\"* ]]; then export PATH=\"\${PATH}:\${AQUA_ROOT_DIR}/bin\"; fi" |
| 67 | +} |
| 68 | + |
| 69 | +install() { |
| 70 | + local aqua_root_dir=$1 |
| 71 | + local aqua_installer_version=$2 |
| 72 | + local aqua_version=$3 |
| 73 | + local aqua_user_name=$4 |
| 74 | + |
| 75 | + install_aqua_binary "${aqua_root_dir}" "${aqua_installer_version}" "${aqua_version}" |
| 76 | + make_aqua_user_writable "${aqua_root_dir}" "${aqua_user_name}" |
| 77 | + add_aqua_environment_variables "${aqua_root_dir}" |
| 78 | +} |
| 79 | + |
| 80 | +install "${AQUAROOTDIR:-/usr/local/share/aquaproj-aqua}" "${INSTALLERVERSION:-latest}" "${VERSION:-latest}" "${_REMOTE_USER:-root}" |
| 81 | + |
| 82 | +echo "Done!" |
0 commit comments