#!/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/jw-projects.py --os=suse-tumbleweed os-cascade # or turn this into a python script and use jw-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