aboutsummaryrefslogtreecommitdiff
path: root/old/pack
blob: c8ebd6c76ce9552f3e191c67e7497e3a40e67f4b (plain)
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
#!/bin/bash

# DETERMINE LOCATION OF FRAMEWORK
while read flocation; do if test -x ${flocation} && test "$( ${flocation} --fcheck )" -ge 20170111; then frameworkscript="${flocation}"; break; fi; done <<EOFLOCATIONS
/usr/share/bgscripts/framework.sh
EOFLOCATIONS
test -z "${frameworkscript}" && echo "$0: framework not found. Aborted." 1>&2 && exit 4

. ${frameworkscript} || echo "$0: framework did not run properly. Continuing..." 1>&2

type="";

case "${thisflavor}" in
   redhat|rhel|centos|fedora|korora) type=rpm;;
   debian|ubuntu) type=dpkg;;
   *) type=targz;;
esac

echo " $@ " | grep -qiE -- "help|usage|\s-h\s|\s-\?" 1>/dev/null 2>&1 && {
   # display help and exit
   less -F <<EOF
pack utility version 2017-05-29a-ddtools
usage: pack [ rpm | deb | tar | scrub ] [ --debug | -d {0-10} ]
Provides a single command for building a package. This script is customized to each package.
optional arguments:
 [ rpm | deb | tar | scrub ]    Build that type of package. Scrub calls the scrub.py script.
                                The default depends on the local os flavor. This system is "${thisflavor}"
 [ --debug {0-10} | -d {0-10} ] Display package type to build and exit. Debuglev not implemented here.
EOF
exit 1
}

# Derive package name and version number, for my simple package versions only.
fullname="$( pwd | sed -e 's/.*\(SOURCES\|deb\)\///;s/\/.*//;' )"
version="$( echo "${fullname}" | grep -oiE -- "-[0-9]{0,3}\.[0-9a-zA-Z]{0,5}-[0-9]{0,4}" | sed -e 's/^-//;' )"
shortversion="$( echo "${version}" | sed -e 's/-.*//;' )"
package="$( echo "${fullname}" | sed -e "s/-${version}//;" )"

echo " $@ " | grep -qiE -- "rpm|rhel|redhat|centos|fedora|korora" 1>/dev/null 2>&1 && type=rpm
echo " $@ " | grep -qiE -- "debian|ubuntu|deb\s|dpkg" 1>/dev/null 2>&1 && type=dpkg
echo " $@ " | grep -qiE -- "tar|tgz|gz" 1>/dev/null 2>&1 && type=targz
echo " $@ " | grep -qiE -- "scrub" 1>/dev/null 2>&1 && type=scrub

# Display information
echo "packaging ${package}-${version} as ${type}"
echo " $@ " | grep -qiE -- "debug|\s-d[ 0-9]{0,3}\s" 1>/dev/null 2>&1 && exit 0

case "${type}" in
   rpm)

########## PACKAGING for rhel/centos
# if you copy-paste this, be sure to define package, version, shortversion
rpmbuilddir=~/rpmbuild/
packagespecfile="${package}-${version}/usr/share/${package}/build/${package}.spec"
sed -n -e '1,/^\%files$/p;' "${rpmbuilddir}/SOURCES/${packagespecfile}" > "${rpmbuilddir}/SOURCES/${packagespecfile}.$$.swp" # removes files and changelog
cd ${rpmbuilddir}/SOURCES/"${package}-${version}"
"${rpmbuilddir}/SOURCES/${package}-${version}/usr/share/${package}/build/get-files" rpm >> "${rpmbuilddir}/SOURCES/${packagespecfile}.$$.swp"
{ printf '\n'; sed -n -e '/^\%changelog/,$p' "${rpmbuilddir}/SOURCES/${packagespecfile}"; } >> "${rpmbuilddir}/SOURCES/${packagespecfile}.$$.swp"
mv -f "${rpmbuilddir}/SOURCES/${packagespecfile}.$$.swp" "${rpmbuilddir}/SOURCES/${packagespecfile}"
rm -rf "${rpmbuilddir}/SOURCES/${package}-${shortversion}"; cp -prf "${rpmbuilddir}/SOURCES/${package}-${version}" "${rpmbuilddir}/SOURCES/${package}-${shortversion}"
rm -rf "${rpmbuilddir}/SOURCES/${package}-${shortversion}/DEBIAN"
cd "${rpmbuilddir}/SOURCES"
rm -rf "${package}.tgz"; tar -zc --exclude='.git*' --exclude='README.md' -f "${package}.tgz" "${package}-${shortversion}"
cp -p "${rpmbuilddir}/SOURCES/${packagespecfile}" "${rpmbuilddir}/SPECS"
mkdir -p "${rpmbuilddir}/RPMS/noarch"; cd "${rpmbuilddir}/RPMS/noarch"
rpmbuild -bb "${rpmbuilddir}/SPECS/${package}.spec"
rm -rf "${rpmbuilddir}/SOURCES/${package}-${shortversion}/" "${rpmbuilddir}/SOURCES/${package}.tgz"

      ;;
   dpkg)

########## PACKAGING for ubuntu
# You need package dpkg-dev to build packages.
# if you copy-paste this, be sure to define package, version
debdir=~/deb
debiandirmain="${package}-${version}/usr/share/${package}/build/debian-${package}"
cd "${debdir}/${package}-${version}"
"${debdir}/${package}-${version}/usr/share/${package}/build/get-files" deb | xargs md5sum > "${debdir}/${debiandirmain}/md5sums"
cd "${debdir}"

# main
rm -rf "${debdir}/${package}-${version}/DEBIAN/" 2>/dev/null; mkdir -p "${debdir}/${package}-${version}/DEBIAN/"
cp -pf "${debdir}/${debiandirmain}"/* "${debdir}/${package}-${version}/DEBIAN/"
mkdir "${debdir}/${package}" 2>/dev/null; rm -rf "${debdir}/${package}-${version}-work.tgz"
tar -zc --exclude='.git*' --exclude='README.md' -f "${debdir}/${package}-${version}-work.tgz" -C "${debdir}/${package}-${version}" $( awk '{print $2}' "${debdir}/${package}-${version}/DEBIAN/md5sums" ) DEBIAN
tar -zx -C "${debdir}/${package}" -f "${debdir}/${package}-${version}-work.tgz"
fakeroot dpkg-deb -b "${debdir}/${package}"
mv -f "${debdir}/${package}.deb" "${debdir}/${package}-${version}.deb"
rm -rf "${debdir}/${package}-${version}-work.tgz" "${debdir}/${package}"

#mv "${debdir}/$$/.git" "${debdir}/$$/"* "${debdir}/${package}-${version}/"; rmdir "${debdir}/$$"

      ;;
   targz)

########## PACKAGING in a master.tgz
# if you copy-paste this, be sure to define package, version
cd ~/deb 2>/dev/null || cd ~/rpmbuild/SOURCES
rm -rf ./"${package}-${version}".master.tgz
tar -zcf "${package}-${version}".master.tgz "${package}-${version}"/

      ;;
   scrub)

########## SCRUB for publication
# if you copy-paste this, be sure to define package, version
cd ~/deb 2>/dev/null || cd ~/rpmbuild/SOURCES
cd "$( find . -name "*scrub.txt" | grep -iE "${package}-${version}\/" | xargs dirname )"
/usr/share/bgscripts/scrub.py

      ;;
   unknown)
      echo "error: check $0 for errors on type ${type}." 1>&2
      ;;
esac
bgstack15