-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwith-deps
More file actions
executable file
·270 lines (240 loc) · 8.17 KB
/
with-deps
File metadata and controls
executable file
·270 lines (240 loc) · 8.17 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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#!/bin/bash
# with-deps: A wrapper script that provides shared dependencies to individual dotfiles scripts
# Usage: ./with-deps script1.sh [script2.sh ...]
#
# This script automatically runs dependency scripts first to ensure the environment is properly set up,
# then executes the target scripts sequentially with all necessary shared functions available.
set -e
# Parse flags (keeping help functionality)
SCRIPT_PATHS=()
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
echo "Usage: $0 <script-path> [script-path2] [script-path3] ..."
echo ""
echo "Options:"
echo " -h, --help Show this help message"
echo ""
echo "Examples:"
echo " $0 programs/ubuntu/packages.sh"
echo " $0 programs/ubuntu/lazygit.sh programs/ubuntu/kubectl.sh"
echo " $0 dependencies/create-dirs.sh programs/ubuntu/packages.sh"
echo ""
echo "This wrapper automatically runs dependency scripts first, then provides"
echo "shared functions like safer-apt, fix-apt, etc. to the target scripts."
echo "Multiple scripts are run sequentially after dependencies are set up once."
exit 0
;;
-*)
echo "Unknown option: $1"
echo "Use -h or --help for usage information."
exit 1
;;
*)
SCRIPT_PATHS+=("$1")
shift
;;
esac
done
# Check if script arguments are provided
if [[ ${#SCRIPT_PATHS[@]} -eq 0 ]]; then
echo "Usage: $0 <script-path> [script-path2] [script-path3] ..."
echo ""
echo "Examples:"
echo " $0 programs/ubuntu/packages.sh"
echo " $0 programs/ubuntu/lazygit.sh programs/ubuntu/kubectl.sh"
echo " $0 dependencies/create-dirs.sh programs/ubuntu/packages.sh"
echo ""
echo "This wrapper automatically runs dependency scripts first, then provides"
echo "shared functions like safer-apt, fix-apt, etc. to the target scripts."
echo "Multiple scripts are run sequentially after dependencies are set up once."
echo ""
echo "Use -h or --help for more information."
exit 1
fi
# Resolve paths relative to the dotfiles directory
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
# Validate and resolve all script paths
RESOLVED_SCRIPTS=()
for script_path in "${SCRIPT_PATHS[@]}"; do
if [[ ! -f "$script_path" ]]; then
# Try relative to dotfiles directory
if [[ -f "$SCRIPT_DIR/$script_path" ]]; then
RESOLVED_SCRIPTS+=("$SCRIPT_DIR/$script_path")
else
echo "Error: Script not found: $script_path"
exit 1
fi
else
RESOLVED_SCRIPTS+=("$script_path")
fi
# Make script executable if it isn't
if [[ ! -x "${RESOLVED_SCRIPTS[-1]}" ]]; then
chmod +x "${RESOLVED_SCRIPTS[-1]}" 2>/dev/null || true
fi
done
# Source the shared dependencies
DEPS_FILE="$SCRIPT_DIR/dependencies/shared-functions.sh"
if [[ -f "$DEPS_FILE" ]]; then
source "$DEPS_FILE"
else
echo "Warning: Dependencies file not found at $DEPS_FILE"
echo "Some functions may not be available to the scripts."
fi
# Set up basic environment variables for better compatibility
export DOTFILES_FOLDER="$SCRIPT_DIR"
# Set up tracking for script execution
SCRIPT_FAILURE_LOG="$SCRIPT_DIR/tmp/with-deps-failed-scripts.log"
SCRIPT_SUCCESS_LOG="$SCRIPT_DIR/tmp/with-deps-success-scripts.log"
# Function to run dependency scripts
run_dependencies() {
echo "🔧 Running dependency scripts..."
echo ""
# Detect OS for OS-specific dependencies
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
OS_PATH="ubuntu"
OS_NAME="Ubuntu"
elif [[ "$OSTYPE" == "darwin"* ]]; then
OS_PATH="mac"
OS_NAME="Mac"
else
echo "Warning: Unsupported OS for dependencies"
return 0
fi
# Set up temp directory and failure log like install.sh does
mkdir -p "$SCRIPT_DIR/tmp" &>/dev/null || true
FAILURE_LOG="$SCRIPT_DIR/tmp/failed_scripts.log"
export FAILURE_LOG
touch "$FAILURE_LOG"
# Initialize script tracking logs
touch "$SCRIPT_FAILURE_LOG"
touch "$SCRIPT_SUCCESS_LOG"
# Run general dependencies first
if [[ -d "$SCRIPT_DIR/dependencies" ]]; then
echo "📦 Running general dependencies..."
for dep_script in "$SCRIPT_DIR/dependencies"/*.sh; do
if [[ -f "$dep_script" ]]; then
script_name=$(basename "$dep_script")
echo " ▶ Running $script_name"
if bash "$dep_script"; then
echo " ✓ $script_name completed"
else
echo " ✗ $script_name failed"
echo "$dep_script" >> "$FAILURE_LOG"
fi
fi
done
echo ""
fi
# Run OS-specific dependencies
if [[ -d "$SCRIPT_DIR/dependencies/$OS_PATH" ]]; then
echo "📦 Running $OS_NAME dependencies..."
for dep_script in "$SCRIPT_DIR/dependencies/$OS_PATH"/*.sh; do
if [[ -f "$dep_script" ]]; then
script_name=$(basename "$dep_script")
echo " ▶ Running $script_name"
if bash "$dep_script"; then
echo " ✓ $script_name completed"
else
echo " ✗ $script_name failed"
echo "$dep_script" >> "$FAILURE_LOG"
fi
fi
done
echo ""
fi
# Check for failures
if [[ -s "$FAILURE_LOG" ]]; then
echo "⚠️ Some dependency scripts failed:"
while IFS= read -r failed_script; do
echo " ✗ $(basename "$failed_script")"
done < "$FAILURE_LOG"
echo ""
echo "Proceeding with main scripts, but some functionality may be missing..."
echo ""
else
echo "✅ All dependencies completed successfully!"
echo ""
fi
}
# Function to run a single script and track result
run_script() {
local script_path="$1"
local script_name=$(basename "$script_path")
echo "🚀 Running: $script_name"
echo ""
if bash "$script_path"; then
echo ""
echo "✅ $script_name completed successfully!"
echo "$script_path" >> "$SCRIPT_SUCCESS_LOG"
return 0
else
echo ""
echo "❌ $script_name failed!"
echo "$script_path" >> "$SCRIPT_FAILURE_LOG"
return 1
fi
}
# Function to clean up temporary files
cleanup() {
if [[ -f "$FAILURE_LOG" ]]; then
rm -f "$FAILURE_LOG" 2>/dev/null || true
fi
if [[ -f "$SCRIPT_FAILURE_LOG" ]]; then
rm -f "$SCRIPT_FAILURE_LOG" 2>/dev/null || true
fi
if [[ -f "$SCRIPT_SUCCESS_LOG" ]]; then
rm -f "$SCRIPT_SUCCESS_LOG" 2>/dev/null || true
fi
}
# Set up cleanup trap
trap cleanup EXIT
# Always run dependencies first
run_dependencies
# Show what we're about to run
if [[ ${#RESOLVED_SCRIPTS[@]} -eq 1 ]]; then
echo "📋 Running 1 script..."
else
echo "📋 Running ${#RESOLVED_SCRIPTS[@]} scripts..."
fi
echo ""
# Run all scripts sequentially
TOTAL_SUCCESS=0
TOTAL_FAILED=0
for script_path in "${RESOLVED_SCRIPTS[@]}"; do
if run_script "$script_path"; then
TOTAL_SUCCESS=$((TOTAL_SUCCESS + 1))
else
TOTAL_FAILED=$((TOTAL_FAILED + 1))
fi
echo ""
done
# Show final summary
echo "📊 Execution Summary:"
echo ""
if [[ $TOTAL_SUCCESS -gt 0 ]]; then
echo "✅ Successfully completed scripts: $TOTAL_SUCCESS"
if [[ -s "$SCRIPT_SUCCESS_LOG" ]]; then
while IFS= read -r success_script; do
echo " ✓ $(basename "$success_script")"
done < "$SCRIPT_SUCCESS_LOG"
fi
echo ""
fi
if [[ $TOTAL_FAILED -gt 0 ]]; then
echo "❌ Failed scripts: $TOTAL_FAILED"
if [[ -s "$SCRIPT_FAILURE_LOG" ]]; then
while IFS= read -r failed_script; do
echo " ✗ $(basename "$failed_script")"
done < "$SCRIPT_FAILURE_LOG"
fi
echo ""
fi
# Overall result
if [[ $TOTAL_FAILED -eq 0 ]]; then
echo "🎉 All scripts completed successfully!"
exit 0
else
echo "⚠️ Some scripts failed. Check the output above for details."
exit 1
fi