aboutsummaryrefslogtreecommitdiff
path: root/tools/cpm/migrate.sh
blob: 8be2b1786c77c3bedfea10f3268a63f07d3d6d03 (plain) (blame)
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
#!/bin/sh -e

# SPDX-FileCopyrightText: Copyright 2026 crueter
# SPDX-License-Identifier: LGPL-3.0-or-later

SUBMODULES="$(git submodule status --recursive | cut -c2-)"
: "${SUBMODULES:?No submodules defined!}"

tmp=$(mktemp)
printf '{}' >"$tmp"

IFS="
"
for i in $SUBMODULES; do
	sha=$(echo "$i" | cut -d" " -f1 | cut -c1-10)
	ver=$(echo "$i" | cut -d" " -f3 | tr -d '()')

	path=$(echo "$i" | cut -d" " -f2)
	name=$(echo "$path" | awk -F/ '{print $NF}')

	remote=$(git -C "$path" remote get-url origin)

	host=$(echo "$remote" | cut -d"/" -f3)
	[ "$host" != github.com ] || host=

	repo=$(echo "$remote" | cut -d"/" -f4-5 | cut -d'.' -f1)

	entry=$(jq -n --arg name "$name" \
		--arg sha "$sha" \
		--arg ver "$ver" \
		--arg repo "$repo" \
		--arg host "$host" \
		'{
        ($name): {
            sha: $sha,
            version: $ver,
            repo: $repo
        } + (if $host != "" then {git_host: $host} else {} end)
        }')

	jq --argjson new "$entry" '. + $new' "$tmp" >"${tmp}.new"
	mv "$tmp.new" "$tmp"
done

jq '.' "$tmp" >cpmfile.json
rm -f "$tmp"