-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·115 lines (101 loc) · 3.46 KB
/
setup.sh
File metadata and controls
executable file
·115 lines (101 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# Description: Automated setup script for OpenTofu, Docker, and Yarn on Linux and macOS
# If it fails, please help us improve it by creating an issue or a PR. Otherwise, you can install them manually.
#!/usr/bin/env bash
set -e
DIR=$(dirname "$0")
cd "$DIR" || exit 1
# ----------------------------
# Helper functions
# ----------------------------
command_exists() {
command -v "$1" >/dev/null 2>&1
}
info() {
echo -e "\033[1;34m[INFO]\033[0m $1"
}
error() {
echo -e "\033[1;31m[ERROR]\033[0m $1"
}
# ----------------------------
# Detect OS
# ----------------------------
OS="$(uname -s)"
info "Detected OS: $OS"
# ----------------------------
# Install OpenTofu
# ----------------------------
install_opentofu_linux() {
info "Installing OpenTofu for Linux..."
# LATEST=$(curl -s https://api.github.com/repos/opentofu/opentofu/releases/latest | grep browser_download_url | grep linux_amd64.zip | cut -d '"' -f 4)
LATEST=https://github.com/opentofu/opentofu/releases/download/v1.10.5/tofu_1.10.5_linux_amd64.zip
cd /tmp || exit 1
curl -LO "$LATEST"
unzip -o tofu_*_linux_amd64.zip
sudo mv tofu /usr/local/bin/
rm tofu_*_linux_amd64.zip
info "OpenTofu version: $(tofu version)"
cd $DIR || exit 1
}
install_opentofu_mac() {
info "Installing OpenTofu via Homebrew..."
if ! command_exists brew; then
error "Homebrew not found. Install it first: https://brew.sh/"
exit 1
fi
brew tap opentofu/opentofu
brew install opentofu
info "OpenTofu version: $(opentofu version)"
}
# ----------------------------
# Install Docker
# ----------------------------
install_docker_linux() {
info "Installing Docker for Linux..."
sudo apt update
sudo apt install -y ca-certificates curl gnupg lsb-release unzip
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
sudo systemctl enable docker
info "Docker version: $(docker --version)"
}
install_docker_mac() {
info "Please install Docker Desktop from https://www.docker.com/products/docker-desktop/"
}
# ----------------------------
# Install Yarn
# ----------------------------
install_yarn_linux() {
info "Installing Node.js LTS..."
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt install -y nodejs
info "Installing Yarn..."
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update
sudo apt install -y yarn
info "Yarn version: $(yarn --version)"
}
install_yarn_mac() {
info "Installing Yarn via Homebrew..."
brew install yarn
info "Yarn version: $(yarn --version)"
}
# ----------------------------
# Main installation flow
# ----------------------------
if [[ "$OS" == "Linux" ]]; then
install_opentofu_linux
install_docker_linux
install_yarn_linux
elif [[ "$OS" == "Darwin" ]]; then
install_opentofu_mac
install_docker_mac
install_yarn_mac
else
error "Unsupported OS: $OS"
exit 1
fi
info "Installation completed successfully!"