-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall
More file actions
225 lines (201 loc) · 6.85 KB
/
Copy pathinstall
File metadata and controls
225 lines (201 loc) · 6.85 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#!/usr/bin/env bash
set -e
# ===============================
# Configuration
# ===============================
ENV_NAME="opss25"
PACKAGES_DIR="$HOME/$ENV_NAME/packages"
PLANVIZ_REPO="https://github.com/ShortestPathLab/opss25-startkit"
SCRIPTS_REPO="https://github.com/ShortestPathLab/opss25-contest-setup" # replace with actual URL
PYTHON_VERSION="3.11"
# ===============================
# Helper functions
# ===============================
install_if_missing() {
local cmd="$1"
local install_cmd="$2"
if ! command -v "$cmd" &>/dev/null; then
echo "❌ $cmd not found. Installing..."
eval "$install_cmd"
hash -r
else
echo "✅ $cmd already installed."
fi
}
ensure_conda_env() {
if ! conda env list | grep -q "^$ENV_NAME "; then
echo "❌ Conda environment '$ENV_NAME' not found. Creating..."
conda create -y -n "$ENV_NAME" python="$PYTHON_VERSION"
else
echo "✅ Conda environment '$ENV_NAME' already exists."
fi
}
clone_if_missing() {
local repo_url="$1"
local target_dir="$2"
local setup_cmd="$3"
if [ ! -d "$target_dir" ]; then
echo "❌ $target_dir not found. Cloning from $repo_url..."
git clone "$repo_url" "$target_dir"
else
echo "✅ $target_dir already exists, skipping clone."
fi
echo "🔄 Running setup commands for $target_dir..."
cd "$target_dir"
eval "$setup_cmd"
cd - >/dev/null
echo "✅ Finished setup for $target_dir."
}
# ===============================
# 0. Check if installed
# ===============================
if command -v opss25-uninstall &>/dev/null; then
echo "✅ opss25 environment already set up. If you want to reinstall, first run: opss25-uninstall. Exiting."
exit 0
fi
# ===============================
# 0.5. Check if MacOS and ensure brew is installed
# ===============================
if [[ "$OSTYPE" == "darwin"* ]]; then
install_if_missing "brew" "
echo '⚠️ Installation will require administrator permissions. You may be prompted for your password.'
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh | bash
"
fi
# ===============================
# 1. Check/install git
# ===============================
install_if_missing "git" "
echo '⚠️ Installation will require administrator permissions. You may be prompted for your password.'
if command -v apt-get &>/dev/null; then
sudo apt-get install -y git
elif command -v dnf &>/dev/null; then
sudo dnf install -y git
elif command -v yum &>/dev/null; then
sudo yum install -y git
elif command -v pacman &>/dev/null; then
sudo pacman -S --noconfirm git
elif command -v brew &>/dev/null; then
brew install git
else
echo '⚠️ Please install Git manually.'
exit 1
fi
"
setup_rootless_docker() {
# Only for Linux systems
if command -v dockerd-rootless-setuptool.sh &>/dev/null; then
if command -v apt-get >/dev/null 2>&1; then
sudo apt-get update -y
sudo apt-get install -y uidmap
elif command -v dnf >/dev/null 2>&1; then
sudo dnf install -y shadow-utils
elif command -v yum >/dev/null 2>&1; then
sudo yum install -y shadow-utils
elif command -v pacman >/dev/null 2>&1; then
sudo pacman -Sy --noconfirm shadow
fi
dockerd-rootless-setuptool.sh install
else
echo "⚠️ Rootless Docker setup tool not found. Please you may need to set up rootless Docker manually, or run commands with sudo."
exit 1
fi
}
# ===============================
# 2. Check/install docker
# ===============================
install_if_missing "docker" "
echo '⚠️ Installation will require administrator permissions. You may be prompted for your password.'
if [[ "$OSTYPE" == "darwin"* ]]; then
brew install --cask docker
elif command -v curl &>/dev/null; then
curl -fsSL https://get.docker.com | sudo bash
setup_rootless_docker
elif command -v wget &>/dev/null; then
wget -qO- https://get.docker.com | sudo bash
setup_rootless_docker
else
echo '⚠️ We could automatically install Docker for your system. Please install Docker manually.'
exit 1
fi
"
# ===============================
# 3. Check/install conda
# ===============================
if ! command -v conda &>/dev/null; then
echo "❌ Conda not found. Installing Miniconda..."
cd /tmp
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh
elif [[ "$OSTYPE" == "darwin"* ]]; then
if [[ `uname -m` == arm64 ]]; then
curl -L https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-arm64.sh -o miniconda.sh
else
curl -L https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh -o miniconda.sh
fi
else
echo "⚠️ Please install Miniconda manually."
exit 1
fi
bash miniconda.sh -b -p "$HOME/miniconda"
eval "$("$HOME/miniconda/bin/conda" shell.bash hook)"
conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/main
conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/r
conda init
echo "✅ Miniconda installed."
else
echo "✅ Conda already installed."
eval "$(conda shell.bash hook)"
fi
# ===============================
# 4. Ensure opss25 environment
# ===============================
ensure_conda_env
# ===============================
# 5. Activate opss25 environment
# ===============================
echo "🔄 Activating conda environment '$ENV_NAME'..."
conda activate "$ENV_NAME"
if [[ "$CONDA_DEFAULT_ENV" != "$ENV_NAME" ]]; then
echo "❌ Could not switch to $ENV_NAME conda environment. You may manually switch to $ENV_NAME by running 'conda activate $ENV_NAME' and then re-run this script to continue. Aborting."
exit 1
fi
# ===============================
# 7. PlanViz setup
# ===============================
PLANVIZ_DIR="$PACKAGES_DIR/PlanViz"
if ! command -v opss25-planviz &>/dev/null; then
clone_if_missing "$PLANVIZ_REPO" "$PLANVIZ_DIR" "
echo 'Installing PlanViz...'
cd $PLANVIZ_DIR/external/PlanViz && python -m pip install -r requirements.txt
cd $PLANVIZ_DIR/python/piglet && python -m pip install -r requirements.txt
"
else
echo "✅ opss25-planviz already in PATH."
fi
# ===============================
# 8. Lifelong scripts setup
# ===============================
SCRIPTS_DIR="$PACKAGES_DIR/setup"
SCRIPTS_SUBDIR="$SCRIPTS_DIR/scripts"
if ! command -v opss25-uninstall &>/dev/null; then
clone_if_missing "$SCRIPTS_REPO" "$SCRIPTS_DIR" "
echo 'Adding scripts to PATH...'
chmod +x $SCRIPTS_SUBDIR/*
echo 'export PATH=\"$SCRIPTS_SUBDIR:\$PATH\"' >> ~/.bashrc
hash -r
"
else
echo "✅ scripts already in PATH."
fi
hash -r
# ===============================
# Done
# ===============================
echo ""
echo "🎉 Setup complete!"
echo "👉 You should now switch to the bash shell: bash"
echo "👉 And activate your environment: conda activate $ENV_NAME"
echo ""
source ~/.bashrc
opss25-help