-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun
More file actions
executable file
·258 lines (218 loc) · 6.8 KB
/
run
File metadata and controls
executable file
·258 lines (218 loc) · 6.8 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
#!/usr/bin/env bash
#
# usage: ./run command [argument ...]
#
# Commands for managing the halos workspace.
#
# See https://death.andgravity.com/run-sh
# for an explanation of how it works and why it's useful.
# First, set up the environment.
# (Check the notes at the end when changing this.)
set -o nounset
set -o pipefail
set -o errexit
# Enable this to echo commands as they are executed.
#set -o xtrace
# Change the current directory to the project root.
PROJECT_ROOT=${0%/*}
if [[ $0 != $PROJECT_ROOT && $PROJECT_ROOT != "" ]]; then
cd "$PROJECT_ROOT"
fi
readonly PROJECT_ROOT=$(pwd)
# Store the absolute path to this script (useful for recursion).
readonly SCRIPT="$PROJECT_ROOT/$(basename "$0")"
################################################################################
# Repository Definitions
declare -A REPOS=(
["halos-pi-gen"]="git@github.com:halos-org/halos-pi-gen.git main"
["apt.hatlabs.fi"]="git@github.com:hatlabs/apt.hatlabs.fi.git main"
["runtipi-marine-app-store"]="git@github.com:hatlabs/runtipi-marine-app-store.git main"
["runtipi-docker-service"]="git@github.com:hatlabs/runtipi-docker-service.git main"
["avnav-docker"]="git@github.com:hatlabs/avnav-docker.git main"
["opencpn-docker"]="git@github.com:halos-org/opencpn-docker.git main"
["cockpit-apt"]="git@github.com:halos-org/cockpit-apt.git main"
["halos-cockpit-config"]="git@github.com:halos-org/halos-cockpit-config.git main"
["cockpit-networkmanager-halos"]="git@github.com:halos-org/cockpit-networkmanager-halos.git main"
["halos-metapackages"]="git@github.com:halos-org/halos-metapackages.git main"
["halos-core-containers"]="git@github.com:halos-org/halos-core-containers.git main"
)
################################################################################
# Repository Management Commands
function clone-repos {
#@ Clone any missing repositories
#@ Category: Repository Management
echo "🔄 Checking repositories..."
local cloned=0
local skipped=0
for repo in "${!REPOS[@]}"; do
if [ -d "$repo" ]; then
echo "⏭️ $repo (already exists)"
((skipped++))
else
read -r url branch <<< "${REPOS[$repo]}"
echo "📥 Cloning $repo (branch: $branch)..."
if git clone -b "$branch" "$url" "$repo"; then
echo "✅ $repo cloned successfully"
((cloned++))
else
echo "❌ Failed to clone $repo"
return 1
fi
fi
done
echo ""
echo "📊 Summary: $cloned cloned, $skipped skipped"
}
function pull-all-main {
#@ Pull latest changes from main branches for all repos
#@ Category: Repository Management
echo "🔄 Updating all repositories..."
local updated=0
local failed=0
local missing=0
for repo in "${!REPOS[@]}"; do
if [ ! -d "$repo" ]; then
echo "⚠️ $repo (missing - run 'clone-repos' first)"
((missing++))
continue
fi
read -r url branch <<< "${REPOS[$repo]}"
echo "📥 Updating $repo (branch: $branch)..."
if (cd "$repo" && git pull origin "$branch"); then
echo "✅ $repo updated successfully"
((updated++))
else
echo "❌ Failed to update $repo"
((failed++))
fi
done
echo ""
echo "📊 Summary: $updated updated, $failed failed, $missing missing"
if [ $failed -gt 0 ]; then
return 1
fi
}
function show-status {
#@ Show git status for all repositories
#@ Category: Repository Management
echo "📊 Repository status:"
echo ""
for repo in "${!REPOS[@]}"; do
if [ ! -d "$repo" ]; then
echo "❌ $repo: NOT CLONED"
continue
fi
echo "📁 $repo:"
(cd "$repo" && git status -sb)
echo ""
done
}
################################################################################
# Setup Commands
function install-dev-deps {
#@ Install workspace-level development dependencies (jq, lefthook, gh)
#@ Category: Setup
local -a deps=(jq lefthook gh)
local -a missing=()
for dep in "${deps[@]}"; do
if ! command -v "$dep" &>/dev/null; then
missing+=("$dep")
fi
done
if [ ${#missing[@]} -eq 0 ]; then
echo "✅ All dev dependencies already installed: ${deps[*]}"
return 0
fi
echo "📦 Missing: ${missing[*]}"
if command -v brew &>/dev/null; then
echo "🍺 Installing via Homebrew..."
brew install "${missing[@]}"
elif command -v apt-get &>/dev/null; then
echo "📦 Installing via apt..."
sudo apt-get update
sudo apt-get install -y "${missing[@]}"
else
echo "❌ No supported package manager found (brew or apt-get)."
echo " Install manually: ${missing[*]}"
return 1
fi
echo "✅ Dev dependencies installed"
}
function install-hooks {
#@ Install pre-commit hooks using lefthook
#@ Category: Setup
if ! command -v lefthook &> /dev/null; then
echo "❌ lefthook not found. Install it first:"
echo " brew install lefthook"
return 1
fi
echo "🔧 Installing pre-commit hooks..."
lefthook install
echo "✅ Hooks installed successfully"
}
function run-hooks {
#@ Run pre-commit hooks manually
#@ Category: Setup
if ! command -v lefthook &> /dev/null; then
echo "❌ lefthook not found. Install it first:"
echo " brew install lefthook"
return 1
fi
echo "🔍 Running pre-commit hooks..."
lefthook run pre-commit
}
################################################################################
# Help System
function help {
#@ Show this help message
#@ Category: Core
echo "Available commands:"
echo ""
# Extract function definitions and their help comments
awk '/^function / {
fname = $2
sub(/[({].*/, "", fname)
getline
if ($0 ~ /#@/) {
desc = $0
sub(/.*#@ /, "", desc)
sub(/ *$/, "", desc)
getline
if ($0 ~ /#@ Category:/) {
cat = $0
sub(/.*Category: /, "", cat)
sub(/ *$/, "", cat)
if (!seen[cat]++) categories[++cat_count] = cat
commands[cat, ++cmd_count[cat]] = fname
descriptions[cat, cmd_count[cat]] = desc
}
}
}
END {
for (i = 1; i <= cat_count; i++) {
cat = categories[i]
print "\n" cat ":"
for (j = 1; j <= cmd_count[cat]; j++) {
printf " %-30s %s\n", commands[cat, j], descriptions[cat, j]
}
}
}' "$0"
echo ""
echo "Usage: ./run <command> [arguments...]"
}
################################################################################
# Commands end.
# Dispatch to command. A simpler version would be just "$@" (with the quotes!).
TIMEFORMAT=$'\nTask completed in %3lR'
time "${@:-help}"
# Some dev notes for this script.
#
# The commands *require*:
#
# * The current working directory is the project root.
# * The shell options and globals are set as they are.
#
# Inspired by the following:
# - https://death.andgravity.com/run-sh
# - http://www.oilshell.org/blog/2020/02/good-parts-sketch.html
# - https://www.youtube.com/watch?v=SdmYd5hJISM&t=7s