-
Notifications
You must be signed in to change notification settings - Fork 1
/
prep_perl_lib_for_build.sh
executable file
·123 lines (111 loc) · 2.92 KB
/
prep_perl_lib_for_build.sh
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
#!/bin/bash
#
# Prepare a unibuild folder for building a perl library from CPAN
#
# Changlog:
# - 2024-04-04 Otto J Wittner - Created
BUILDROOT=$(pwd)
SRCROOT=$(dirname $(pwd))
DISTRO="el9"
declare -A DISTROS
DISTROS[el9]="rpm"
usage () {
echo "Usage: `basename $0` [options] cpan-lib ..."
echo " -h Help message."
echo " -d distro Linux distro to build for. Default is $DISTRO. Supported are: ${!DISTROS[@]}"
echo " -q Be quiet."
exit 1;
}
msg () {
# Output message to stdout if appropriate
if [ -z $QUIET ]; then
echo $*
fi
}
# Parse arguments
while getopts ":hqd:" opt; do
case $opt in
d)
if [ "`echo "$DISTROS" | grep -w $OPTARG`" ]; then
DISTRO=$OPTARG
else
echo "Unsupported distro $OPTARG."
exit 1
fi
;;
q)
QUIET="yes"
;;
h)
usage
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
shift $(($OPTIND - 1)) # (Shift away parsed arguments)
if [ $# -lt 1 ]; then
usage
fi
#Prepare environment
cp .rpmmacros ~/
dnf install -qy cpanspec
for PERLLIB in $*
do
msg "Perparing unibuild evironment for $PERLLIB ..."
DIR=$(echo $PERLLIB | awk '{print tolower($0)}' | sed 's/::/_/g')
DIR="perl_${DIR}"
# Prepare unibuild folders
mkdir -p $DIR/unibuild-packaging/${DISTROS[$DISTRO]}
cd $DIR
# Fetch source and create spec (with perl module syntax spec as "Provides:")
TARFILE=$(ls *.tar.gz 2>/dev/null | head -n 1)
if [ "$TARFILE" ]; then
# Make spec of available tar
cpanspec -o -m -v $TARFILE
else
# Download tar from CPAN and make spec
cpanspec -o -m -v $PERLLIB
fi
if [ $? -eq 0 ]; then
# cpanspec succeeded.
# Fix source in spec
sed -i -E 's|^(Source0:.*)http.*/(.*)|\1\2 |g' *.spec
# Add modules provided by lib
#MODULES=$( tar -tvf *.tar.gz | grep "/lib/.*\.pm" | sed -E 's|.*/lib/(.*)\.pm|\1|g' | sed 's|/|::|g')
MODULES=$( tar -tvf *.tar.gz | awk '{print $6}' | grep "^[^/]*/lib/.*\.pm" | sed -E 's|.*/lib/(.*)\.pm|\1|g' | sed 's|/|::|g')
for l in $MODULES; do
# Add perl module syntax to spec for module
sed -i -E "s|^(%description)|Provides: perl($l)\n\1|g" *.spec
done
if [ "$MODULES" ]; then
# Make it pretty. Add an extra line feed
sed -i -E "s|^(%description)|\n\1|g" *.spec
else
msg "Waring: No modules (*.pm) found in /lib in library."
# Add perl module syntax to spec for core module
sed -i -E "s|^(%description)|Provides: perl($PERLLIB)\n\n\1|g" *.spec
fi
mv *.spec unibuild-packaging/${DISTROS[$DISTRO]}
cat <<EOF > Makefile
#
# Makefile for Any Package
#
include unibuild/unibuild.make
EOF
cd ..
grep -q "^${DIR}$" unibuild-order
if [ $? -gt 0 ]; then
# Add new module to order list
sed -i "s|# Order-list|# Order-list\n${DIR}|g" unibuild-order
echo "${DIR} added to unibuild-order"
fi
fi
echo
done