aboutsummaryrefslogtreecommitdiff
path: root/tools/cpm/package.sh
blob: 8246222d50ddd47542d2bb86a4eb64f356c0946f (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
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
#!/bin/sh -e

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

RETURN=0

usage() {
	cat <<EOF
Usage: cpmutil.sh package [command]

Operate on a package or packages.

Commands:
    hash            	Verify the hash of a package, and update it if needed
    update          	Check for updates for a package
    fetch           	Fetch a package and place it in the cache
    add             	Add a new package
    rm              	Remove a package
    version         	Change the version of a package
    which           	Check if a package is defined
    url             	Get the download URL for a package
    dir             	Get the local directory for a package
    reset           	Reset a fetched package to its original state
    patch           	Add a patch to a package in the cpmfile

EOF

	exit $RETURN
}

SCRIPTS=$(CDPATH='' cd -- "$(dirname -- "$0")/package" && pwd)
CMAKE="$CMAKE/package"

export SCRIPTS CMAKE

filter_args() {
	print_usage=false
	all_flag=false
	commit_flag=false
	filtered=""

	for arg in "$@"; do
		case "$arg" in
		-h | --help) print_usage=true ;;
		-a | --all) all_flag=true ;;
		-c | --commit) commit_flag=true ;;
		-ac | -ca)
			commit_flag=true
			all_flag=true
			;;
		*) filtered="$filtered $arg" ;;
		esac
	done
}

while :; do
	case "$1" in
	dir | fetch | hash | reset | rm | url | version | which | update)
		cmd="$1"
		shift

		filter_args "$@"
		cmake_defines=""

		if $print_usage; then cmake_defines="$cmake_defines -DPRINT_USAGE=TRUE"; fi
		if $all_flag; then cmake_defines="$cmake_defines -DALL_PACKAGES=TRUE"; fi
		if $commit_flag; then cmake_defines="$cmake_defines -DMAKE_COMMIT=TRUE"; fi

		# shellcheck disable=SC2086
		cmake $cmake_defines -P "$CMAKE/$cmd.cmake" -- $filtered
		break
		;;
	add | patch)
		cmd="$1"
		shift
		"$SCRIPTS/$cmd".sh "$@"
		break
		;;
	*) usage ;;
	esac

	shift
done