Skip to content

Commit 7bf44b3

Browse files
authored
refactor: improvements to install.sh format (#3)
this changeset is to improve conformance to standards and formatting. - add descriptive comments - use quoting for variables - split long commands w/ line continuation using `\` - consistent error handling w/ `{}` - add spacing between sections - document formatting
1 parent b60cb44 commit 7bf44b3

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

src/tofu/install.sh

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,51 @@ check_packages() {
2222

2323
export DEBIAN_FRONTEND=noninteractive
2424

25+
# OpenTofu version configuration
2526
# https://github.com/opentofu/opentofu/releases
2627
VERSION=${VERSION:-"latest"}
2728

2829
echo "Activating feature 'tofu'"
2930

30-
# Clean up.
31+
# Clean up old package lists
3132
rm -rf /var/lib/apt/lists/*
3233

34+
# Install required dependencies
3335
check_packages ca-certificates curl dirmngr gpg gpg-agent
3436

37+
# Normalize version tag format
3538
case "${VERSION}" in
36-
latest | v*) TAG="$VERSION"; ;;
37-
*) TAG="v${VERSION}"; ;;
39+
latest | v*)
40+
TAG="$VERSION"
41+
;;
42+
*)
43+
TAG="v${VERSION}"
44+
;;
3845
esac
3946

4047
INSTALLER="install-opentofu.sh"
4148

42-
# Download the installer script:
43-
curl "https://get.opentofu.org/${INSTALLER}" --proto '=https' --tlsv1.2 -fsSLO --compressed --retry 5 ||
44-
(echo "error: failed to download: ${TAG}" && exit 1)
49+
# Download the installer script
50+
curl "https://get.opentofu.org/${INSTALLER}" \
51+
--proto '=https' \
52+
--tlsv1.2 \
53+
-fsSLO \
54+
--compressed \
55+
--retry 5 || {
56+
echo "error: failed to download: ${TAG}"
57+
exit 1
58+
}
4559

46-
# Give it execution permissions:
47-
chmod +x $INSTALLER
60+
# Set installer permissions
61+
chmod +x "${INSTALLER}"
4862

49-
su ${_REMOTE_USER} -c "./${INSTALLER} --install-method deb --opentofu-version ${VERSION}" ||
50-
(echo "error: failed to install tofu." && exit 1)
63+
# Run installer as non-root user
64+
su "${_REMOTE_USER}" -c "./${INSTALLER} --install-method deb --opentofu-version ${VERSION}" || {
65+
echo "error: failed to install tofu."
66+
exit 1
67+
}
5168

52-
# Clean up
53-
rm -rf $INSTALLER
69+
# Clean up installer
70+
rm -rf "${INSTALLER}"
5471

5572
echo "Done!"

0 commit comments

Comments
 (0)