From 632cbff69fe64af26b45f26762ec1190445249c9 Mon Sep 17 00:00:00 2001 From: Janos <86970079+janosdebugs@users.noreply.github.com> Date: Tue, 27 Feb 2024 13:53:10 +0100 Subject: [PATCH] Removing erroneously added stuff (#1314) Signed-off-by: Janos <86970079+janosdebugs@users.noreply.github.com> --- website/docs/intro/install/.gitignore | 1 + .../install/DO_NOT_ADD_LICENSE_HEADERS.txt | 2 + .../docs/intro/install/alpine-convenience.sh | 5 - website/docs/intro/install/alpine-manual.sh | 5 - website/docs/intro/install/alpine.sh | 5 - website/docs/intro/install/brew-install.sh | 5 - website/docs/intro/install/brew.sh | 5 - website/docs/intro/install/deb-convenience.sh | 5 - website/docs/intro/install/deb-step1.sh | 5 - website/docs/intro/install/deb-step2.sh | 5 - website/docs/intro/install/deb-step3.sh | 5 - website/docs/intro/install/deb-step4.sh | 5 - website/docs/intro/install/deb.sh | 5 - .../docs/intro/install/install-opentofu.sh | 1249 ----------------- website/docs/intro/install/install-yum.sh | 5 - website/docs/intro/install/install-zypper.sh | 5 - website/docs/intro/install/repo-yum.sh | 5 - website/docs/intro/install/repo-zypper.sh | 5 - website/docs/intro/install/rpm-convenience.sh | 5 - website/docs/intro/install/rpm.sh | 5 - .../docs/intro/install/standalone-install.ps1 | 5 - .../docs/intro/install/standalone-install.sh | 5 - .../install/test-install-instructions.sh | 5 - .../intro/install/verify-checksum-linux.sh | 5 - .../intro/install/verify-checksum-macos.sh | 5 - .../docs/intro/install/verify-checksum.ps1 | 15 +- website/docs/intro/install/verify-cosign.ps1 | 5 - website/docs/intro/install/verify-cosign.sh | 5 - 28 files changed, 8 insertions(+), 1379 deletions(-) create mode 100644 website/docs/intro/install/.gitignore create mode 100644 website/docs/intro/install/DO_NOT_ADD_LICENSE_HEADERS.txt delete mode 100755 website/docs/intro/install/install-opentofu.sh diff --git a/website/docs/intro/install/.gitignore b/website/docs/intro/install/.gitignore new file mode 100644 index 0000000000..de6b3c01d2 --- /dev/null +++ b/website/docs/intro/install/.gitignore @@ -0,0 +1 @@ +install-opentofu.sh \ No newline at end of file diff --git a/website/docs/intro/install/DO_NOT_ADD_LICENSE_HEADERS.txt b/website/docs/intro/install/DO_NOT_ADD_LICENSE_HEADERS.txt new file mode 100644 index 0000000000..0880c64b49 --- /dev/null +++ b/website/docs/intro/install/DO_NOT_ADD_LICENSE_HEADERS.txt @@ -0,0 +1,2 @@ +Please do not add license headers and end-of-file line breaks to the examples in this folder. +They are embedded in the website, and it makes for really hard reading to have license headers 5-6 times in a page. \ No newline at end of file diff --git a/website/docs/intro/install/alpine-convenience.sh b/website/docs/intro/install/alpine-convenience.sh index 7dc0147113..18411c112a 100644 --- a/website/docs/intro/install/alpine-convenience.sh +++ b/website/docs/intro/install/alpine-convenience.sh @@ -1,8 +1,3 @@ -# Copyright (c) The OpenTofu Authors -# SPDX-License-Identifier: MPL-2.0 -# Copyright (c) 2023 HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - # Download the installer script: curl --proto '=https' --tlsv1.2 -fsSL https://get.opentofu.org/install-opentofu.sh -o install-opentofu.sh # Alternatively: wget --secure-protocol=TLSv1_2 --https-only https://get.opentofu.org/install-opentofu.sh -O install-opentofu.sh diff --git a/website/docs/intro/install/alpine-manual.sh b/website/docs/intro/install/alpine-manual.sh index 3570b0c1d7..a3ce5bdac9 100644 --- a/website/docs/intro/install/alpine-manual.sh +++ b/website/docs/intro/install/alpine-manual.sh @@ -1,7 +1,2 @@ -# Copyright (c) The OpenTofu Authors -# SPDX-License-Identifier: MPL-2.0 -# Copyright (c) 2023 HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - echo '@community https://dl-cdn.alpinelinux.org/alpine/edge/community' >> /etc/apk/repositories apk add opentofu@community diff --git a/website/docs/intro/install/alpine.sh b/website/docs/intro/install/alpine.sh index 2b104fb408..1d050e52c7 100755 --- a/website/docs/intro/install/alpine.sh +++ b/website/docs/intro/install/alpine.sh @@ -1,9 +1,4 @@ #!/bin/sh -# Copyright (c) The OpenTofu Authors -# SPDX-License-Identifier: MPL-2.0 -# Copyright (c) 2023 HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - set -e diff --git a/website/docs/intro/install/brew-install.sh b/website/docs/intro/install/brew-install.sh index 79c1991d0d..540ac9d075 100644 --- a/website/docs/intro/install/brew-install.sh +++ b/website/docs/intro/install/brew-install.sh @@ -1,7 +1,2 @@ -# Copyright (c) The OpenTofu Authors -# SPDX-License-Identifier: MPL-2.0 -# Copyright (c) 2023 HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - brew update brew install opentofu \ No newline at end of file diff --git a/website/docs/intro/install/brew.sh b/website/docs/intro/install/brew.sh index 4fed7ef325..291d8a4f71 100755 --- a/website/docs/intro/install/brew.sh +++ b/website/docs/intro/install/brew.sh @@ -1,9 +1,4 @@ #!/bin/bash -# Copyright (c) The OpenTofu Authors -# SPDX-License-Identifier: MPL-2.0 -# Copyright (c) 2023 HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - set -ex diff --git a/website/docs/intro/install/deb-convenience.sh b/website/docs/intro/install/deb-convenience.sh index 1aae19fdd6..80ef978ddb 100644 --- a/website/docs/intro/install/deb-convenience.sh +++ b/website/docs/intro/install/deb-convenience.sh @@ -1,8 +1,3 @@ -# Copyright (c) The OpenTofu Authors -# SPDX-License-Identifier: MPL-2.0 -# Copyright (c) 2023 HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - # Download the installer script: curl --proto '=https' --tlsv1.2 -fsSL https://get.opentofu.org/install-opentofu.sh -o install-opentofu.sh # Alternatively: wget --secure-protocol=TLSv1_2 --https-only https://get.opentofu.org/install-opentofu.sh -O install-opentofu.sh diff --git a/website/docs/intro/install/deb-step1.sh b/website/docs/intro/install/deb-step1.sh index f4657e4b26..b9aaf284a7 100644 --- a/website/docs/intro/install/deb-step1.sh +++ b/website/docs/intro/install/deb-step1.sh @@ -1,7 +1,2 @@ -# Copyright (c) The OpenTofu Authors -# SPDX-License-Identifier: MPL-2.0 -# Copyright (c) 2023 HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - sudo apt-get update sudo apt-get install -y apt-transport-https ca-certificates curl gnupg \ No newline at end of file diff --git a/website/docs/intro/install/deb-step2.sh b/website/docs/intro/install/deb-step2.sh index d854cf7f05..cb8ab3b315 100644 --- a/website/docs/intro/install/deb-step2.sh +++ b/website/docs/intro/install/deb-step2.sh @@ -1,8 +1,3 @@ -# Copyright (c) The OpenTofu Authors -# SPDX-License-Identifier: MPL-2.0 -# Copyright (c) 2023 HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - sudo install -m 0755 -d /etc/apt/keyrings curl -fsSL https://get.opentofu.org/opentofu.gpg | sudo tee /etc/apt/keyrings/opentofu.gpg >/dev/null curl -fsSL https://packages.opentofu.org/opentofu/tofu/gpgkey | sudo gpg --no-tty --batch --dearmor -o /etc/apt/keyrings/opentofu-repo.gpg >/dev/null diff --git a/website/docs/intro/install/deb-step3.sh b/website/docs/intro/install/deb-step3.sh index 989fb27f89..10b1f9104c 100644 --- a/website/docs/intro/install/deb-step3.sh +++ b/website/docs/intro/install/deb-step3.sh @@ -1,8 +1,3 @@ -# Copyright (c) The OpenTofu Authors -# SPDX-License-Identifier: MPL-2.0 -# Copyright (c) 2023 HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - echo \ "deb [signed-by=/etc/apt/keyrings/opentofu.gpg,/etc/apt/keyrings/opentofu-repo.gpg] https://packages.opentofu.org/opentofu/tofu/any/ any main deb-src [signed-by=/etc/apt/keyrings/opentofu.gpg,/etc/apt/keyrings/opentofu-repo.gpg] https://packages.opentofu.org/opentofu/tofu/any/ any main" | \ diff --git a/website/docs/intro/install/deb-step4.sh b/website/docs/intro/install/deb-step4.sh index e84ae8a9a2..8297acb836 100644 --- a/website/docs/intro/install/deb-step4.sh +++ b/website/docs/intro/install/deb-step4.sh @@ -1,7 +1,2 @@ -# Copyright (c) The OpenTofu Authors -# SPDX-License-Identifier: MPL-2.0 -# Copyright (c) 2023 HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - sudo apt-get update sudo apt-get install -y tofu \ No newline at end of file diff --git a/website/docs/intro/install/deb.sh b/website/docs/intro/install/deb.sh index 8e42bd7858..cd60764956 100755 --- a/website/docs/intro/install/deb.sh +++ b/website/docs/intro/install/deb.sh @@ -1,9 +1,4 @@ #!/bin/bash -# Copyright (c) The OpenTofu Authors -# SPDX-License-Identifier: MPL-2.0 -# Copyright (c) 2023 HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - set -e diff --git a/website/docs/intro/install/install-opentofu.sh b/website/docs/intro/install/install-opentofu.sh deleted file mode 100755 index f87f7b0247..0000000000 --- a/website/docs/intro/install/install-opentofu.sh +++ /dev/null @@ -1,1249 +0,0 @@ -#!/bin/sh -# Copyright (c) The OpenTofu Authors -# SPDX-License-Identifier: MPL-2.0 -# Copyright (c) 2023 HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - - -# OpenTofu Installer -# -# This script installs OpenTofu via any of the supported methods. - -export TOFU_INSTALL_EXIT_CODE_OK=0 -export TOFU_INSTALL_EXIT_CODE_INSTALL_REQUIREMENTS_NOT_MET=1 -export TOFU_INSTALL_EXIT_CODE_INSTALL_FAILED=2 -export TOFU_INSTALL_EXIT_CODE_INVALID_ARGUMENT=3 - -export TOFU_INSTALL_RETURN_CODE_COMMAND_NOT_FOUND=11 -export TOFU_INSTALL_RETURN_CODE_DOWNLOAD_FAILED=13 - -bold="" -normal="" -red="" -green="" -yellow="" -blue="" -magenta="" -cyan="" -gray="" -if [ -t 1 ]; then - if command -v "tput" >/dev/null 2>&1; then - colors=$(tput colors) - else - colors=2 - fi - - if [ "${colors}" -ge 8 ]; then - bold="$(tput bold)" - normal="$(tput sgr0)" - red="$(tput setaf 1)" - green="$(tput setaf 2)" - yellow="$(tput setaf 3)" - blue="$(tput setaf 4)" - magenta="$(tput setaf 5)" - cyan="$(tput setaf 6)" - gray="$(tput setaf 245)" - fi -fi - -ROOT_METHOD=auto -INSTALL_METHOD="" -DEFAULT_INSTALL_PATH=/opt/opentofu -INSTALL_PATH="${DEFAULT_INSTALL_PATH}" -DEFAULT_SYMLINK_PATH=/usr/local/bin -SYMLINK_PATH="${DEFAULT_SYMLINK_PATH}" -DEFAULT_OPENTOFU_VERSION=latest -OPENTOFU_VERSION="${DEFAULT_OPENTOFU_VERSION}" -DEFAULT_DEB_GPG_URL=https://get.opentofu.org/opentofu.gpg -DEB_GPG_URL="${DEFAULT_DEB_GPG_URL}" -DEFAULT_DEB_REPO_GPG_URL=https://packages.opentofu.org/opentofu/tofu/gpgkey -DEB_REPO_GPG_URL="${DEFAULT_DEB_REPO_GPG_URL}" -DEFAULT_DEB_REPO_URL=https://packages.opentofu.org/opentofu/tofu/any/ -DEB_REPO_URL=${DEFAULT_DEB_REPO_URL} -DEFAULT_DEB_REPO_SUITE=any -DEB_REPO_SUITE="${DEFAULT_DEB_REPO_SUITE}" -DEFAULT_DEB_REPO_COMPONENTS=main -DEB_REPO_COMPONENTS="${DEFAULT_DEB_REPO_COMPONENTS}" -DEFAULT_RPM_REPO_URL=https://packages.opentofu.org/opentofu/tofu/rpm_any/rpm_any/ - -RPM_REPO_URL=${DEFAULT_RPM_REPO_URL} -DEFAULT_RPM_REPO_GPG_URL=https://packages.opentofu.org/opentofu/tofu/gpgkey -DEFAULT_RPM_GPG_URL=https://get.opentofu.org/opentofu.asc -RPM_GPG_URL="${DEFAULT_RPM_GPG_URL}" -RPM_REPO_GPG_URL="${DEFAULT_RPM_REPO_GPG_URL}" -#TODO once the package makes it into stable change this to "-" -DEFAULT_APK_REPO_URL="@testing https://dl-cdn.alpinelinux.org/alpine/edge/testing" -APK_REPO_URL=${DEFAULT_APK_REPO_URL} -DEFAULT_APK_PACKAGE="opentofu@testing" -APK_PACKAGE="${DEFAULT_APK_PACKAGE}" -DEFAULT_COSIGN_PATH=cosign -COSIGN_PATH=${DEFAULT_COSIGN_PATH} -DEFAULT_COSIGN_IDENTITY=autodetect -COSIGN_IDENTITY=${DEFAULT_COSIGN_IDENTITY} -DEFAULT_COSIGN_OIDC_ISSUER=https://token.actions.githubusercontent.com -COSIGN_OIDC_ISSUER=${DEFAULT_COSIGN_OIDC_ISSUER} -SKIP_VERIFY=0 - -# region ZSH -if [ -n "${ZSH_VERSION}" ]; then - ## Enable POSIX-style word splitting: - setopt SH_WORD_SPLIT >/dev/null 2>&1 -fi -# endregion - -log_success() { - if [ -z "$1" ]; then - return - fi - echo "${green}$1${normal}" 1>&2 -} - -log_warning() { - if [ -z "$1" ]; then - return - fi - echo "${yellow}$1${normal}" 1>&2 -} - -log_info() { - if [ -z "$1" ]; then - return - fi - echo "${cyan}$1${normal}" 1>&2 -} - -log_debug() { - if [ -z "$1" ]; then - return - fi - if [ -z "${LOG_DEBUG}" ]; then - return - fi - echo "${gray}$1${normal}" 1>&2 -} - -log_error() { - if [ -z "$1" ]; then - return - fi - echo "${red}$1${normal}" 1>&2 -} - -# This function checks if the command specified in $1 exists. -command_exists() { - log_debug "Determining if the ${1} command is available..." - if [ -z "$1" ]; then - log_error "Bug: no command supplied to command_exists()" - return "${TOFU_INSTALL_EXIT_CODE_INVALID_ARGUMENT}" - fi - if ! command -v "$1" >/dev/null 2>&1; then - log_debug "The ${1} command is not available." - return "${TOFU_INSTALL_RETURN_CODE_COMMAND_NOT_FOUND}" - fi - log_debug "The ${1} command is available." - return "${TOFU_INSTALL_EXIT_CODE_OK}" -} - -is_root() { - if [ "$(id -u || true)" -eq 0 ]; then - return 0 - fi - return 1 -} - -# This function runs the specified command as root. -as_root() { - # shellcheck disable=SC2145 - log_debug "Running command as root: $*" - case "${ROOT_METHOD}" in - auto) - log_debug "Automatically determining root method..." - if is_root; then - log_debug "We are already root, no user change needed." - "$@" - elif command_exists "sudo"; then - log_debug "Running command using sudo." - sudo "$@" - elif command_exists "su"; then - log_debug "Running command using su." - su root "$@" - else - log_error "Neither su nor sudo is installed, cannot obtain root privileges." - return "${TOFU_INSTALL_RETURN_CODE_COMMAND_NOT_FOUND}" - fi - return $? - ;; - none) - log_debug "Using manual root method 'none'." - "$@" - return $? - ;; - sudo) - log_debug "Using manual root method 'sudo'." - sudo "$@" - return $? - ;; - su) - log_debug "Using manual root method 'su'." - su root "$@" - return $? - ;; - *) - log_error "Bug: invalid root method value: $1" - return "${TOFU_INSTALL_EXIT_CODE_INVALID_ARGUMENT}" - esac -} - -# This function attempts to execute a function as the current user and switches to root if it fails. -maybe_root() { - if ! "$@" >/dev/null 2>&1; then - if ! as_root "$@"; then - return "${TOFU_INSTALL_EXIT_CODE_INSTALL_FAILED}" - fi - fi - return "${TOFU_INSTALL_EXIT_CODE_OK}" -} - -# This function verifies if one of the supported download tools is installed and returns with -# $TOFU_INSTALL_EXIT_CODE_INSTALL_REQUIREMENTS_NOT_MET if that is not th ecase. -download_tool_exists() { - log_debug "Determining if a supported download tool is installed..." - if command_exists "wget"; then - log_debug "wget is installed." - return "${TOFU_INSTALL_EXIT_CODE_OK}" - elif command_exists "curl"; then - log_debug "curl is installed." - return "${TOFU_INSTALL_EXIT_CODE_OK}" - else - log_debug "No supported download tool is installed." - return "${TOFU_INSTALL_EXIT_CODE_INSTALL_REQUIREMENTS_NOT_MET}" - fi -} - -# This function downloads the URL specified in $1 into the file specified in $2. -# It returns $TOFU_INSTALL_EXIT_CODE_INSTALL_REQUIREMENTS_NOT_MET if no supported download tool is installed, or $TOFU_INSTALL_RETURN_CODE_DOWNLOAD_FAILED -# if the download failed. -download_file() { - if [ -z "$1" ]; then - log_error "Bug: no URL supplied to download_file()" - return "${TOFU_INSTALL_EXIT_CODE_INVALID_ARGUMENT}" - fi - if [ -z "$2" ]; then - log_error "Bug: no destination file supplied to download_file()" - return "${TOFU_INSTALL_EXIT_CODE_INVALID_ARGUMENT}" - fi - log_debug "Downloading URL ${1} to ${2}..." - IS_GITHUB=0 - if [ -n "${GITHUB_TOKEN}" ]; then - if [ "$(echo "$1" | grep -c "api.github.com" || true)" -ne 0 ]; then - IS_GITHUB=1 - fi - fi - if command_exists "wget"; then - if [ "${IS_GITHUB}" -eq 1 ]; then - log_debug "Downloading using wget with GITHUB_TOKEN..." - if ! wget -q --header="Authorization: token ${GITHUB_TOKEN}" -O "$2" "$1"; then - log_debug "Download failed." - return "${TOFU_INSTALL_RETURN_CODE_DOWNLOAD_FAILED}" - fi - else - log_debug "Downloading using wget without GITHUB_TOKEN, this may lead to rate limit issues..." - if ! wget -q -O "$2" "$1"; then - log_debug "Download failed, please try specifying the GITHUB_TOKEN environment variable." - return "${TOFU_INSTALL_RETURN_CODE_DOWNLOAD_FAILED}" - fi - fi - elif command_exists "curl"; then - if [ "${IS_GITHUB}" -eq 1 ]; then - log_debug "Downloading using curl with GITHUB_TOKEN..." - if ! curl --proto '=https' --tlsv1.2 -fsSL -H "Authorization: token ${GITHUB_TOKEN}" -o "$2" "$1"; then - log_debug "Download failed." - return "${TOFU_INSTALL_RETURN_CODE_DOWNLOAD_FAILED}" - fi - else - log_debug "Downloading using curl without GITHUB_TOKEN, this may lead to rate limit issues..." - if ! curl --proto '=https' --tlsv1.2 -fsSL -o "$2" "$1"; then - log_debug "Download failed, please try specifying the GITHUB_TOKEN environment variable." - return "${TOFU_INSTALL_RETURN_CODE_DOWNLOAD_FAILED}" - fi - fi - else - log_error "Neither wget nor curl are available on your system. Please install one of them to proceed." - return "${TOFU_INSTALL_EXIT_CODE_INSTALL_REQUIREMENTS_NOT_MET}" - fi - log_debug "Download successful." - return "${TOFU_INSTALL_EXIT_CODE_OK}" -} - -# This function downloads the OpenTofu GPG key from the specified URL to the specified location. Setting the third -# parameter to 1 causes the file to be moved as root. It returns $TOFU_INSTALL_RETURN_CODE_DOWNLOAD_FAILED if the -# download fails, or $TOFU_INSTALL_EXIT_CODE_INSTALL_REQUIREMENTS_NOT_MET if no download tool is available. -download_gpg() { - if [ -z "$1" ]; then - log_error "Bug: no URL passed to download_gpg." - return "${TOFU_INSTALL_EXIT_CODE_INVALID_ARGUMENT}" - fi - if [ -z "$2" ]; then - log_error "Bug: no destination passed to download_gpg." - return "${TOFU_INSTALL_EXIT_CODE_INVALID_ARGUMENT}" - fi - if ! command_exists "gpg"; then - log_error "Missing gpg binary." - return "${TOFU_INSTALL_EXIT_CODE_INSTALL_REQUIREMENTS_NOT_MET}" - fi - log_debug "Downloading GPG key from ${1} to ${2}..." - if ! download_tool_exists; then - return "${TOFU_INSTALL_EXIT_CODE_INSTALL_REQUIREMENTS_NOT_MET}" - fi - log_debug "Creating temporary directory..." - TEMPDIR=$(mktemp -d) - if [ -z "${TEMPDIR}" ]; then - log_error "Failed to create temporary directory for GPG download." - return "${TOFU_INSTALL_EXIT_CODE_INSTALL_FAILED}" - fi - TEMPFILE="${TEMPDIR}/opentofu.gpg" - - if ! download_file "${1}" "${TEMPFILE}"; then - log_debug "Removing temporary directory..." - rm -rf "${TEMPFILE}" - return "${TOFU_INSTALL_RETURN_CODE_DOWNLOAD_FAILED}" - fi - if [ "$(grep 'BEGIN PGP PUBLIC KEY BLOCK' -c "${TEMPFILE}" || true)" -ne 0 ]; then - log_debug "Performing GPG dearmor on ${TEMPFILE}" - if ! gpg --no-tty --batch --dearmor -o "${TEMPFILE}.tmp" <"${TEMPFILE}"; then - log_error "Failed to GPG dearmor ${TEMPFILE}." - return "${TOFU_INSTALL_EXIT_CODE_INSTALL_FAILED}" - fi - if ! mv "${TEMPFILE}.tmp" "${TEMPFILE}"; then - log_error "Failed to move ${TEMPFILE}.tmp to ${TEMPFILE}." - return "${TOFU_INSTALL_EXIT_CODE_INSTALL_FAILED}" - fi - fi - if [ "$3" = "1" ]; then - log_debug "Moving GPG file as root..." - if ! as_root mv "${TEMPFILE}" "${2}"; then - log_error "Failed to move ${TEMPFILE} to ${2}." - rm -rf "${TEMPFILE}" - return "${TOFU_INSTALL_EXIT_CODE_INSTALL_FAILED}" - fi - else - log_debug "Moving GPG file as the current user..." - if ! mv "${TEMPFILE}" "${2}"; then - log_error "Failed to move ${TEMPFILE} to ${2}." - rm -rf "${TEMPFILE}" - return "${TOFU_INSTALL_EXIT_CODE_INSTALL_FAILED}" - fi - fi - - log_debug "Removing temporary directory..." - rm -rf "${TEMPFILE}" - return "${TOFU_INSTALL_EXIT_CODE_OK}" -} - -# This is a helper function that downloads a GPG URL to the specified file. -deb_download_gpg() { - DEB_GPG_URL="${1}" - GPG_FILE="${2}" - if [ -z "${DEB_GPG_URL}" ]; then - log_error "Bug: no GPG URL specified for deb_download_gpg." - return "${TOFU_INSTALL_EXIT_CODE_INVALID_ARGUMENT}" - fi - if [ -z "${GPG_FILE}" ]; then - log_error "Bug: no destination path specified for deb_download_gpg." - return "${TOFU_INSTALL_EXIT_CODE_INVALID_ARGUMENT}" - fi - if ! download_gpg "${DEB_GPG_URL}" "${GPG_FILE}" 1; then - log_error "Failed to download GPG key from ${DEB_GPG_URL}." - return "${TOFU_INSTALL_EXIT_CODE_INSTALL_FAILED}" - fi - log_debug "Changing ownership and permissions of ${GPG_FILE}..." - if ! as_root chown root:root "${GPG_FILE}"; then - log_error "Failed to chown ${GPG_FILE}." - rm -rf "${GPG_FILE}" - return "${TOFU_INSTALL_EXIT_CODE_INSTALL_FAILED}" - fi - if ! as_root chmod a+r "${GPG_FILE}"; then - log_error "Failed to chmod ${GPG_FILE}." - rm -rf "${GPG_FILE}" - return "${TOFU_INSTALL_EXIT_CODE_INSTALL_FAILED}" - fi - return "${TOFU_INSTALL_EXIT_CODE_OK}" -} - -# This function installs OpenTofu via a Debian repository. It returns -# $TOFU_INSTALL_EXIT_CODE_INSTALL_REQUIREMENTS_NOT_MET if this is not a Debian system. -install_deb() { - log_info "Attempting installation via Debian repository..." - if ! command_exists apt-get; then - log_info "The apt-get command is not available, skipping Debian repository installation." - return "${TOFU_INSTALL_EXIT_CODE_INSTALL_REQUIREMENTS_NOT_MET}" - fi - - if ! is_root; then - log_info "Root privileges are required to install OpenTofu as a Debian package." - log_info "The installer will now verify if it can correctly assume root privileges." - log_info "${bold}You may be asked to enter your password.${normal}" - if ! as_root echo -n ""; then - log_error "Cannot assume root privileges." - log_info "Please set up either '${bold}su${normal}' or '${bold}sudo${normal}'." - log_info "Alternatively, run this script with ${bold}-h${normal} for other installation methods." - fi - fi - - log_info "Updating package list..." - if ! as_root apt-get update; then - log_error "Failed to update apt package list." - return "${TOFU_INSTALL_EXIT_CODE_INSTALL_FAILED}" - fi - - log_debug "Determining packages to install..." - PACKAGE_LIST="apt-transport-https ca-certificates" - if [ "${SKIP_VERIFY}" -ne "1" ]; then - PACKAGE_LIST="${PACKAGE_LIST} gnupg" - fi - if ! download_tool_exists; then - log_debug "No download tool present, adding curl to the package list..." - PACKAGE_LIST="${PACKAGE_LIST} curl" - fi - - log_info "Installing necessary packages for installation..." - log_debug "Installing ${PACKAGE_LIST}..." - # shellcheck disable=SC2086 - if ! as_root apt-get install -y ${PACKAGE_LIST}; then - log_error "Failed to install requisite packages for Debian repository installation." - return "${TOFU_INSTALL_EXIT_CODE_INSTALL_FAILED}" - fi - log_debug "Necessary packages installed." - - if [ "${SKIP_VERIFY}" -ne "1" ]; then - log_info "Installing the OpenTofu GPG keys..." - log_debug "Creating /etc/apt/keyrings..." - if ! as_root install -m 0755 -d /etc/apt/keyrings; then - log_error "Failed to create /etc/apt/keyrings." - return "${TOFU_INSTALL_EXIT_CODE_INSTALL_FAILED}" - fi - log_debug "Created /etc/apt/keyrings." - - PACKAGE_GPG_FILE=/etc/apt/keyrings/opentofu.gpg - log_debug "Downloading the GPG key from ${DEB_GPG_URL}.." - if ! deb_download_gpg "${DEB_GPG_URL}" "${PACKAGE_GPG_FILE}"; then - log_error "Failed to download GPG key from ${DEB_GPG_URL}." - return "${TOFU_INSTALL_EXIT_CODE_INSTALL_FAILED}" - fi - if [ -n "${DEB_REPO_GPG_URL}" ] && [ "${DEB_REPO_GPG_URL}" != "-" ]; then - log_debug "Downloading the repo GPG key from ${DEB_REPO_GPG_URL}.." - REPO_GPG_FILE=/etc/apt/keyrings/opentofu-repo.gpg - if ! deb_download_gpg "${DEB_REPO_GPG_URL}" "${REPO_GPG_FILE}" 1; then - log_error "Failed to download GPG key from ${DEB_REPO_GPG_URL}." - return "${TOFU_INSTALL_EXIT_CODE_INSTALL_FAILED}" - fi - fi - fi - - log_info "Creating OpenTofu sources list..." - if [ "${SKIP_VERIFY}" -ne "1" ]; then - if [ -n "${REPO_GPG_FILE}" ]; then - if ! as_root tee /etc/apt/sources.list.d/opentofu.list; then - log_error "Failed to create /etc/apt/sources.list.d/opentofu.list." - return "${TOFU_INSTALL_EXIT_CODE_INSTALL_FAILED}" - fi < /dev/null; then - log_error "Failed to run tofu after installation." - return "${TOFU_INSTALL_EXIT_CODE_INSTALL_FAILED}" - fi - return "${TOFU_INSTALL_EXIT_CODE_OK}" -} - -# This function installs OpenTofu via the zypper command line utility. It returns -# $TOFU_INSTALL_EXIT_CODE_INSTALL_REQUIREMENTS_NOT_MET if zypper is not available. -install_zypper() { - if ! command_exists "zypper"; then - return "${TOFU_INSTALL_EXIT_CODE_INSTALL_REQUIREMENTS_NOT_MET}" - fi - log_info "Installing OpenTofu using zypper..." - if [ "${SKIP_VERIFY}" -ne "1" ]; then - GPGCHECK=1 - GPG_URL="${RPM_GPG_URL}" - if [ "${RPM_REPO_GPG_URL}" != "-" ]; then - GPG_URL=$(cat </dev/null 2>&1; then - log_error "Cannot move ${ZIPDIR} contents to ${INSTALL_PATH}. Please check the permissions on the target directory." - return "${TOFU_INSTALL_EXIT_CODE_INSTALL_FAILED}" - fi - - if [ "${SYMLINK_PATH}" != "-" ]; then - log_info "Creating tofu symlink at ${SYMLINK_PATH}/tofu..." - if ! maybe_root ln -sf "${INSTALL_PATH}/tofu" "${SYMLINK_PATH}/tofu"; then - log_error "Failed to create symlink at ${INSTALL_PATH}/tofu." - return "${TOFU_INSTALL_EXIT_CODE_INSTALL_FAILED}" - fi - fi - log_info "Checking if OpenTofu is installed correctly..." - if [ "${SYMLINK_PATH}" != "-" ]; then - if ! "${SYMLINK_PATH}/tofu" --version; then - log_error "Failed to run ${SYMLINK_PATH}/tofu after installation." - return "${TOFU_INSTALL_EXIT_CODE_INSTALL_FAILED}" - fi - else - if ! "${INSTALL_PATH}/tofu" --version; then - log_error "Failed to run ${INSTALL_PATH}/tofu after installation." - return "${TOFU_INSTALL_EXIT_CODE_INSTALL_FAILED}" - fi - fi - log_success "Installation complete." - return "${TOFU_INSTALL_EXIT_CODE_OK}" -} - -usage() { - if [ -n "$1" ]; then - log_error "Error: $1" - fi - cat </etc/yum.repos.d/opentofu.repo </etc/zypp/repos.d/opentofu.repo <