-
Notifications
You must be signed in to change notification settings - Fork 0
/
build
executable file
·80 lines (66 loc) · 2.02 KB
/
build
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
#!/bin/bash
# this script will take a dir as the only arg
# use createrepo_c and modulemd tools to createrepo on that dir
# Usage: build <repo-path> # create yum repo
# Usage: build <repo-path> sign # and sign the rpm packages
SIGN_RPM=false
PROG_NAME="$(basename $0)"
PROG_DIR="$(cd $(dirname $0) && pwd)"
# Function to create a repository in the given directory
create_repo(){
local repo_dir=$1
local create_module=true
# Check if the directory exists
if [ ! -d "${repo_dir}" ]; then
echo "Error: repo dir ${repo_dir} does not exist" >&2
return 1
fi
if ls ${repo_dir} | grep -q 'el7'; then
create_module=false
fi
cd "${repo_dir}" || return 1
if [ "$SIGN_RPM" = true ]; then
echo "Sign RPM packages in ${repo_dir}"
find . -type f -name '*.rpm' -exec rpm --addsign {} \;
else
echo "Skip rpm signing in ${repo_dir}"
fi
if ! createrepo_c .; then
echo "Error: failed to run createrepo_c in ${repo_dir}" >&2
return 1
fi
if [ "$create_module" = true ]; then
repo2module -s stable . modules.yaml
modifyrepo_c --mdtype=modules modules.yaml repodata/
return 0
fi
}
# Function to recursively find all directories and create repos
process_directories(){
local base_dir=$1
find "$base_dir" -type d | while read -r dir; do
# skip dir named with repodata or start with .
if [[ "$dir" == *repodata ]] || [[ "$dir" == "." ]]; then
echo "skip directory: ${dir}"
continue
fi
echo "Creating repo in directory: ${dir}"
create_repo "$dir"
done
wait
}
# check if it is EL Linux by /etc/os-release
if [ -f /etc/os-release ]; then
if ! rpm --eval '%{?rhel}' >/dev/null 2>&1; then
echo "Error: Run this on RHEL" >&2
exit 1
fi
else
echo "Error: run this on enterprise linux (rhel) environment" >&2
exit 1
fi
# check if the 2nd arg is 'sign'
if [ "$#" -eq 2 ] && [ "$2" == "sign" ]; then
SIGN_RPM=true
fi
create_repo "$1"