1#!/usr/bin/env bash
2
3set -euo pipefail
4
5AGPL_CRATES=("collab")
6RELEASE_CRATES=("cli" "remote_server" "zed")
7
8check_license () {
9 local dir="$1"
10 local allowed_licenses=()
11
12 local is_agpl=false
13 for agpl_crate in "${AGPL_CRATES[@]}"; do
14 if [[ "$dir" == "crates/$agpl_crate" ]]; then
15 is_agpl=true
16 break
17 fi
18 done
19
20 if [[ "$is_agpl" == true ]]; then
21 allowed_licenses=("LICENSE-AGPL")
22 else
23 allowed_licenses=("LICENSE-GPL" "LICENSE-APACHE")
24 fi
25
26 for license in "${allowed_licenses[@]}"; do
27 if [[ -L "$dir/$license" ]]; then
28 return 0
29 elif [[ -e "$dir/$license" ]]; then
30 echo "Error: $dir/$license exists but is not a symlink."
31 exit 1
32 fi
33 done
34
35 if [[ "$is_agpl" == true ]]; then
36 echo "Error: $dir does not contain a LICENSE-AGPL symlink"
37 else
38 echo "Error: $dir does not contain a LICENSE-GPL or LICENSE-APACHE symlink"
39 fi
40 exit 1
41}
42
43git ls-files "**/*/Cargo.toml" | while read -r cargo_toml; do
44 check_license "$(dirname "$cargo_toml")"
45done
46
47
48# Make sure the AGPL server crates are included in the release tarball.
49for release_crate in "${RELEASE_CRATES[@]}"; do
50 tree_output=$(cargo tree --package "$release_crate")
51 for agpl_crate in "${AGPL_CRATES[@]}"; do
52 # Look for lines that contain the crate name followed by " v" (version)
53 # This matches patterns like "├── collab v0.44.0"
54 if echo "$tree_output" | grep -E "(^|[^a-zA-Z_])${agpl_crate} v" > /dev/null; then
55 echo "Error: crate '${agpl_crate}' is AGPL and is a dependency of crate '${release_crate}'." >&2
56 echo "AGPL licensed code should not be used in the release distribution, only in servers." >&2
57 exit 1
58 fi
59 done
60done
61
62echo "check-licenses succeeded"