bin, make, scripts: Re-add files necessary for packaging jw-build

Re-add all files necessary to package jw-build itself, i.e.
sucessfully run make pkg-rebuild-reinstall. This adds 1892 lines of
code.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2025-11-14 11:22:50 +01:00
commit 82eb80979d
11 changed files with 1881 additions and 0 deletions

168
scripts/create-mkspec.sh Normal file
View file

@ -0,0 +1,168 @@
#!/bin/bash
_cat()
{
sed 's/^ *|//'
}
cfg_section()
{
ini_section "$inifile" $@
}
cfg_value()
{
ini_value "$inifile" $@
}
cfg_escape()
{
sed 's/\\/\\\\/g; s/\$/\\$/g; s/`/\\`/g'
}
# unneeded but kept, because it might come in handy in the future
have_pkg()
{
echo "$subpackages" | grep -q "\(^[ ]*\|[ ]\+\)$1\([ ]\+\|$\)"
return $?
}
subpackage_description()
{
case $1 in
run)
echo "Runtime files"
;;
devel)
echo "Development files"
;;
esac
}
os_cascade()
{
# might want to run python3 path/to/projects.py --os=suse-tumbleweed os-cascade
# or turn this into a python script and use projects.py as a module.
if [ "$DISTRIBUTION" ]; then
echo os linux $DISTRIBUTION | sed 's/\([^-]\+\)-\([^-]\+\)/\1 \1-\2/g'
else
echo os linux
fi
}
# -- here we go
echo "== running $0" "$@" >&2
export LANG=POSIX
dir=`dirname $0`
inifile="$1"
. $dir/ini-tools.sh
subpackages=`cfg_value global.subpackages`
license=`cfg_value global.license`
[ "$license" ] || license="janware GmbH proprietary license"
vendor=`cfg_value global.vendor`
[ "$vendor" ] || vendor="janware GmbH"
url=`cfg_value global.url`
[ "$url" ] || url="https://janware.com"
_cat <<- EOT
|echo "%define debug_package %{nil}"
|# ---------------------------------------
|echo "Name: \$NAME"
|echo "Summary: `cfg_value summary`"
|echo "Version: \$VERSION"
|echo "Release: \$RELEASE"
|echo "License: $license"
|echo "Group: System/Libraries"
|[ -n "\$SOURCE" ] && echo "Source: \$SOURCE"
|echo "Vendor: $vendor"
|echo "URL: $url"
|echo "BuildRoot: /var/tmp/%{name}-buildroot"
|echo "Distribution: jw / openSUSE Tumbleweed"
|echo ""
|echo "%description"
|echo "`cfg_value description`"
|echo ""
|# ---------------------------------------
|echo "%prep"
|echo "%setup -q -n \$NAME-\$V"
|echo ""
|echo "%build"
|echo 'pwd'
|echo 'make config'
|echo 'make'
|echo ""
|echo "%install"
|echo 'rm -rf \$RPM_BUILD_ROOT'
|echo "export ENV_PREFIX=\\\$RPM_BUILD_ROOT"
|echo "export INSTALL_LOG=\$INSTALL_LOG"
|echo "mkdir -p \`dirname \$INSTALL_LOG\`"
|echo "> \$INSTALL_LOG"
|echo "make install"
|echo "export PATH=$JWB_SCRIPT_DIR:\\\$PATH"
|echo "/bin/bash pkg.sh milk-install-log -p \\\$ENV_PREFIX -n \$NAME -t rpm -s \\"$subpackages\\" \$INSTALL_LOG \`dirname \$INSTALL_LOG\`"
|echo "exit 0" # <- Cut short CentOS magic appended to install scriptlet, which would generate .pyo files and other cruft.
EOT
for p in $subpackages; do
P=${p^^}
_cat <<- EOT
|echo ""
|echo "# --------------------------------------- subpackage $p"
|echo ""
|echo "%package -n \$NAME-$p"
|echo "Summary: `cfg_value summary`"
|echo "Group: `cfg_value global.group`"
|[ "\$REQUIRES_$P" ] && echo "Requires: \$REQUIRES_$P"
|[ "\$CONFLICTS_$P" ] && echo "Conflicts: \$CONFLICTS_$P"
|[ "\$PROVIDES_$P" ] && echo "Provides: \$PROVIDES_$P"
|echo ""
EOT
descr=`subpackage_description $p`
if [ "$descr" ]; then
_cat <<- EOT
|echo ""
|echo "%description -n \$NAME-$p"
|echo "$descr"
EOT
fi
for stage in pre preun post postun; do
echo "== processing stage $stage: cfg_section pkg.$p.$stage" >&2
out=""
#for os in '' `os_cascade | sed 's/\(^\| \)/ ./g'`; do
for os in '' `os_cascade`; do
sec=pkg.$p.$stage
if [ "$os" ]; then
sec="$sec.$os"
head="\n# --- $os\n"
else
head=""
fi
cfg_section $sec | grep -q . || continue
out="$out$head`cfg_section $sec`"
done
if [ "$out" ]; then
echo -e "$out" >&2
_cat <<- EOT
|echo ""
|echo "%$stage -n \$NAME-$p"
EOT
echo "cat << EOT"
echo -e "$out" | cfg_escape
echo "EOT"
fi
done
_cat <<- EOT
|echo ""
|echo "%files -n \$NAME-$p -f \$INSTALL_LOG.\$NAME-$p"
|echo '%defattr (-, root, root)'
EOT
done

56
scripts/ini-tools.sh Normal file
View file

@ -0,0 +1,56 @@
ini_section()
{
local inifile="$1"
local sec="$2"
cat "$inifile" |
cut -d\# -f1 |
tr -s '\n' '\n' |
sed -n "/^ *\[$sec\]/,/^ *\[/ p" |
grep -v '^ *\[' |
sed '/^ *$/ d'
}
ini_value()
{
local inifile="$1"
local path="$2"
local sec=`echo "$path" | sed 's/\.[^.]\+$//'`
local key=`echo "$path" | sed 's/.*\.//'`
# echo "path=>$path<"
# echo "sec=>$sec<"
# echo "key=>$key<"
if [ "$key" = "$path" ]; then
ini_section "$inifile" "$path"
return 0
fi
ini_section "$inifile" "$sec" | sed "
/^ *$key *=/ !d
s/^ *$key *= *//
s/ *$//
/^ *$/ d
"
}
ini_has_section()
{
local inifile="$1"
local sec="$2"
grep -q "^ *\[$sec\]" $inifile || return 1
}
ini_has_value()
{
ini_value $@ | grep -q .
}
ini_escape()
{
cat | sed '
s/\$/\\$/g
s/`/\\\`/g
'
}

130
scripts/mkspec-wrapper.sh Normal file
View file

@ -0,0 +1,130 @@
#!/bin/bash
usage()
{
echo usage: $MYNAME /path/to/mkspec.sh -h [-N name] [-T topdir] [-V version] [-S source] [-R requires] [-P project] >&2
[ "$1" ] && exit $1
}
append()
{
local var=$1
shift
local tmp=`eval echo \"\\$$var $@\" | sed 's/^[[:space:]]*//; s/[[:space:]]*$//'`
eval $var=\"$tmp\"
}
# -- here we go
#set -x
MYNAME=`basename $0`
ID=`whoami`
[ ! "$INSTALL_LOG" ] && INSTALL_LOG=/tmp/rpmbuild-$ID/install.log
eval set -- `getopt -l "provides-run:" -l "provides-devel:" -o "P:T:V:S:N:hR:D:X:Y:d:" -- "$@"`
while [ "$1" != -- ]; do
echo checking "$1=$2" >&2
case $1 in
-h)
usage 0;;
-T)
TOPDIR="$2"
shift;;
-V)
V="$2"
shift;;
-S)
SOURCE="$2"
shift;;
-N)
NAME="$2"
shift;;
-R)
append REQUIRES_RUN "$2"
shift
;;
-X)
append CONFLICTS_RUN "$2"
shift
;;
-D)
append REQUIRES_DEVEL "$2"
shift
;;
-Y)
append CONFLICTS_DEVEL "$2"
shift
;;
--provides-run)
append PROVIDES_RUN "$2"
shift
;;
--provides-devel)
append PROVIDES_DEVEL "$2"
shift
;;
-P)
PROJECT="$2"
shift;;
-d)
DISTRIBUTION="$2"
shift;;
*)
usage 1;;
esac
shift
done
shift
MKSPEC_SH="$1"
shift
[ -z "$TOPDIR" ] && TOPDIR=.
if [ -z "$V" ]; then
if [ -f $TOPDIR/VERSION ]; then
VERSION="`cat $TOPDIR/VERSION | cut -d- -f1`"
RELEASE="`cat $TOPDIR/VERSION | cut -d- -f2- | sed 's/[-_].*//'`"
else
VERSION=noversion
RELEASE=norelease
fi
else
VERSION="`echo $V | cut -d- -f1`"
RELEASE="`cat $TOPDIR/VERSION | cut -d- -f2- | sed 's/[-_].*//'`"
fi
if [ -z "$NAME" ]; then
NAME=`pwd | xargs basename`
fi
REQUIRES="$REQUIRES_RUN $REQUIRES_DEVEL"
CONFLICTS="$CONFLICTS_RUN $CONFLICTS_DEVEL"
#if [ -n "$REQUIRES" ]; then
# REQUIRES_RUN=`echo $REQUIRES |
# sed -e '
# s/\([a-zA-Z-]\+\) *\([<>=]*\) *\([a-zA-Z0-9\.-]*\)/\1-run \2 \3,/g
# s/,$//
# s/-run-run/-run/
# '`
# REQUIRES_DEVEL="$REQUIRES_RUN, $NAME-run = $VERSION-$RELEASE, `echo $REQUIRES_RUN | sed -e 's/-run/-devel/g'`"
#fi
#echo "REQUIRES_RUN=\"$REQUIRES_RUN\""
#exit
export \
REQUIRES REQUIRES_RUN REQUIRES_DEVEL \
CONFLICTS CONFLICTS_RUN CONFLICTS_DEVEL \
PROVIDES PROVIDES_RUN PROVIDES_DEVEL \
TOPDIR \
PROJECT NAME \
SOURCE \
VERSION RELEASE V \
INSTALL_LOG \
DISTRIBUTION
bash $MKSPEC_SH

1237
scripts/pkg.sh Normal file

File diff suppressed because it is too large Load diff

174
scripts/scm.sh Normal file
View file

@ -0,0 +1,174 @@
#!/bin/bash
cmd_mv()
{
local from="$1"
local to="$2"
case $scm in
cvs)
cp "$from" "$to"
cvs add "$to"
cvs remove -f "$from"
;;
git)
git mv "$from" "$to"
;;
esac
}
cmd_commit()
{
C=''
for i in "$@"; do
C="$C \"${i//\"/\\\"}\""
done
eval $scm commit "$C"
}
cmd_add()
{
$scm add "$@"
}
cmd_rm()
{
case $scm in
cvs)
cvs remove "$@"
;;
git)
git rm "$@"
;;
esac
}
cmd_clean()
{
case $scm in
cvs)
while [ "${1:0:1}" = - ]; do
shift
done
set +e
local file
for file in $@; do
if ! grep -q "/$file/" CVS/Entries; then
rm -f $file
fi
done
;;
git)
git clean -x "$@"
;;
esac
}
cmd_ls_files()
{
filter_deleted()
{
local rc_file="$1"
shift
local cand
for cand in "$@"; do
grep -q "^R ./$cand/" $rc_file && continue
echo $cand
done
}
output()
{
if [ "$zero_terminate" = 1 ]; then
echo -en "$*\x00"
else
echo "$*"
fi
}
list_dirents_cvs()
{
local dirs=`sed '/^D\// !d; s%^D/%%; s%/.*%%' $1/CVS/Entries`
dirs="`filter_deleted $1/CVS/Entries $dirs`"
local cands
if [ -f $1/CVS/Entries.Log ]; then
cands="`sed '/^A D\// !d; s%^A D/%%; s%/.*%%' $1/CVS/Entries.Log`"
dirs="$dirs `filter_deleted $1/CVS/Entries.Log $cands`"
fi
local files=`sed '/^\// !d; s%/%%; s%/.*%%; s%^%%' $1/CVS/Entries`
files="`filter_deleted $1/CVS/Entries $files`"
local d f
for f in $files; do
output "$1/$f"
done
for d in $dirs; do
[ "$opt_only_regular_files" = 1 ] || output $1/$d
list_dirents_cvs $1/$d
done
}
list_dirents_git()
{
local opts="$git_ls_files_opts"
git --version | grep -q "version *1" && opt_no_submodules=1
[ "$opt_no_submodules" = 1 ] || opts="$opts --recurse-submodules"
git ls-files --recurse-submodules $opts $1
}
list_dirents()
{
if [ -d $1/CVS ]; then
list_dirents_cvs $1
return
fi
git status >/dev/null 2>&1 || {
echo "failed to list versioned files in $1: no VCS" >&2
exit 1
}
list_dirents_git $1
}
set -- `getopt fnzt "$@"`
while [ "$1" != -- ]; do
case $1 in
-f)
opt_only_regular_files=1
;;
-n)
opt_no_submodules=1
;;
-z)
zero_terminate=1
git_ls_files_opts="$git_ls_files_opts -z"
opt_sort="$opt_sort -z"
;;
-t)
text_files=1
;;
esac
shift
done
shift
proj_dir="$1"
[ "$proj_dir" ] && cd $proj_dir
if [ "$text_files" ]; then
list_dirents . | sort $opt_sort | xargs file -N | grep ":.*text" | cut -d: -f1
else
list_dirents . | sort $opt_sort
fi
}
# ------- here we go
export LANG=POSIX
myname=`basename $0`
cmd=cmd_${1//-/_}
shift
if [ -d "CVS" ]; then
scm=cvs
else
scm=git
fi
$cmd "$@"