Repository navigation
Expand file tree
/
Copy pathINSTALL
More file actions
executable file
·193 lines (167 loc) · 6.03 KB
/
Copy pathINSTALL
File metadata and controls
executable file
·193 lines (167 loc) · 6.03 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
#!/usr/bin/env bash
# Script to install Rocoto Workflow Manager using Bundler
set -euo pipefail # Exit on error, undefined vars, pipe failures
# Set location of Rocoto installation
ROCOTO_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
# Print usage information
usage() {
cat << EOF
Usage: ${0##*/} [OPTIONS]
Install the Rocoto Workflow Manager and its dependencies.
Options:
--with-ruby=PATH Path to Ruby installation directory
--local Use cached gems from vendor/cache/ (air-gapped mode)
-h, --help Show this help message
Examples:
./INSTALL
./INSTALL --with-ruby=/opt/ruby/3.3.0
./INSTALL --local # Air-gapped installation using vendor/cache/
EOF
exit 0
}
# Parse command line arguments
RUBY=""
LOCAL_INSTALL=false
for arg in "$@"; do
case "$arg" in
--with-ruby=*)
RUBY="${arg#*=}/bin/ruby"
;;
--local)
LOCAL_INSTALL=true
;;
-h|--help)
usage
;;
*)
echo "Error: Unknown option '$arg'" >&2
echo "Use --help to see available options" >&2
exit 1
;;
esac
done
# Find Ruby executable
if [[ -z "$RUBY" ]]; then
if ! RUBY=$(command -v ruby); then
echo "Error: Cannot find ruby in PATH." >&2
echo "Use --with-ruby to specify the Ruby installation directory." >&2
exit 1
fi
fi
# Verify Ruby executable exists and is executable
if [[ ! -x "$RUBY" ]]; then
echo "Error: Ruby executable not found or not executable: $RUBY" >&2
echo "Use --with-ruby to specify the correct Ruby installation directory." >&2
exit 1
fi
echo "==> Using Ruby: $RUBY"
# Check Ruby version
RUBY_VERSION=$("$RUBY" -e "puts RUBY_VERSION")
echo "==> Ruby version: $RUBY_VERSION"
if ! "$RUBY" -e "exit(RUBY_VERSION >= '3.3.0' ? 0 : 1)"; then
echo "Error: Ruby 3.3.0 or higher is required (found $RUBY_VERSION)" >&2
echo "Note: Ruby 3.2 and earlier are no longer supported and do not receive security updates." >&2
exit 1
fi
# Check if bundler is installed
echo "==> Checking for Bundler..."
if ! "$RUBY" -e "require 'bundler'" 2>/dev/null; then
echo "==> Bundler not found, installing..."
# Get the gem command associated with this Ruby
GEM_CMD="${RUBY%/ruby}/gem"
if [[ ! -x "$GEM_CMD" ]]; then
GEM_CMD=$(command -v gem) || {
echo "Error: Cannot find gem command for $RUBY" >&2
exit 1
}
fi
"$GEM_CMD" install bundler --user-install --no-document
# Add user gem bin directory to PATH if not already there
USER_GEM_BIN=$("$RUBY" -e "puts Gem.user_dir")/bin
if [[ ":$PATH:" != *":$USER_GEM_BIN:"* ]]; then
export PATH="${USER_GEM_BIN}:${PATH}"
echo "==> Added ${USER_GEM_BIN} to PATH for this session"
echo ""
echo "Note: You may want to add this to your ~/.bashrc or ~/.bash_profile:"
echo " export PATH=\"${USER_GEM_BIN}:\${PATH}\""
echo ""
fi
else
echo "==> Bundler already installed"
fi
# Get the bundle command path
BUNDLE_CMD=$("$RUBY" -e "require 'rubygems'; puts Gem.bin_path('bundler', 'bundle')")
if [[ ! -f "$BUNDLE_CMD" ]]; then
echo "Error: Cannot find bundle executable" >&2
exit 1
fi
echo "==> Using Bundler: $BUNDLE_CMD"
# Update Ruby shebangs in scripts
echo "==> Updating Ruby shebangs in scripts..."
shebang_count=0
for file in sbin/*; do
# Skip if not a file, or is a shell script, or is a symlink
[[ -f "$file" ]] || continue
[[ "$file" == *.sh ]] && continue
[[ -L "$file" ]] && continue
# Update shebang line
if sed -i.bak "1s|^#!.*|#!${RUBY}|" "$file"; then
rm -f "${file}.bak"
shebang_count=$((shebang_count + 1))
fi
done
echo "==> Updated shebangs in $shebang_count script(s)"
# Configure bundler to use local installation directory
echo "==> Configuring bundler for local gem installation..."
"$BUNDLE_CMD" config set --local path 'bundle'
"$BUNDLE_CMD" config set --local disable_shared_gems 'true'
# Install gem dependencies using Bundler in standalone mode
echo "==> Installing gem dependencies with Bundler (standalone mode)..."
echo "==> Standalone mode removes runtime dependency on Bundler gem"
if [[ "$LOCAL_INSTALL" == "true" ]]; then
echo "==> Using local (air-gapped) installation from vendor/cache/"
if [[ ! -d "vendor/cache" ]] || [[ -z "$(ls -A vendor/cache 2>/dev/null)" ]]; then
echo ""
echo "Error: --local option specified but vendor/cache/ is missing or empty." >&2
echo ""
echo "To create the gem cache, run these commands on a system with internet access:" >&2
echo " bundle config set cache_all true" >&2
echo " bundle cache" >&2
echo " git add vendor/cache/" >&2
exit 1
fi
if ! "$BUNDLE_CMD" install --local --standalone; then
echo ""
echo "Error: Local installation failed." >&2
echo "The cached gems may be incompatible with this system." >&2
exit 1
fi
else
if ! "$BUNDLE_CMD" install --standalone; then
echo ""
echo "Error: Bundler installation failed." >&2
echo "This is often due to missing system dependencies or network issues." >&2
echo ""
echo "For air-gapped systems, use the --local option to install from cached gems." >&2
echo "See README.md for details on creating the gem cache." >&2
exit 1
fi
fi
echo ""
echo "=============================================="
echo " Rocoto Installation Complete!"
echo "=============================================="
echo ""
echo "Installation directory: ${ROCOTO_DIR}"
echo "Gems installed in: ${ROCOTO_DIR}/bundle"
echo "Ruby version: ${RUBY_VERSION}"
echo ""
echo "Note: This installation uses standalone mode."
echo "The Bundler gem is NOT required at runtime."
echo ""
echo "To use Rocoto, add the bin/ directory to your PATH:"
echo " export PATH=\"${ROCOTO_DIR}/bin:\${PATH}\""
echo ""
echo "To make this permanent, add the above line to your"
echo "~/.bashrc or ~/.bash_profile"
echo ""