From: Michael Wagner Date: Wed, 6 Feb 2019 20:31:18 +0000 (+0100) Subject: Merge branch 'master' of http://wagnertech.de/git/projects X-Git-Tag: sysd2sysv_0.2-2 X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/projects.git/commitdiff_plain/79db08267b1bb93ea92e2538a66bbaac21c240b6?hp=675071341d474d6689bef4d8f368eea082ab68c1 Merge branch 'master' of http://wagnertech.de/git/projects --- diff --git a/debian/control b/debian/control deleted file mode 100644 index 4034bfd..0000000 --- a/debian/control +++ /dev/null @@ -1,14 +0,0 @@ -Source: projects -Section: main -Priority: optional -Maintainer: Michael Wagner -Build-Depends: git - -Package: mbuild -Architecture: all -Depends: dpkg-dev -Description: WagnerTech build environment - Simple build environment for Debian packages - . - This package contains scripts and makefiles for - script and C/C++ packages. diff --git a/debian/mbuild.changelog b/debian/mbuild.changelog index 5346c34..8d1ba1a 100644 --- a/debian/mbuild.changelog +++ b/debian/mbuild.changelog @@ -1,12 +1,16 @@ -projects (0.2-%BUILD%) unstable; urgency=medium +projects (0.3-%BUILD%) unstable; urgency=medium + * new number due to version numbering problems + -- Michael Wagner Wed, 09 Jan 2019 22:54:48 +0100 +projects (0.2) unstable; urgency=medium * Build in svn-Umgebung + * including build script + * new options + * including pre/post installation scripts + * packing for tgz and versioning + -- Michael Wagner Fri, 10 Aug 2018 22:54:48 +0100 - -- Michael Wagner Mon, 18 Apr 2018 09:45:25 +0100 - -projects (0.1-%BUILD%) unstable; urgency=medium - +projects (0.1) unstable; urgency=medium * Build in neuer git-Umgebung - -- Michael Wagner Mon, 12 Feb 2018 09:45:25 +0100 diff --git a/debian/mbuild.control b/debian/mbuild.control new file mode 100644 index 0000000..4034bfd --- /dev/null +++ b/debian/mbuild.control @@ -0,0 +1,14 @@ +Source: projects +Section: main +Priority: optional +Maintainer: Michael Wagner +Build-Depends: git + +Package: mbuild +Architecture: all +Depends: dpkg-dev +Description: WagnerTech build environment + Simple build environment for Debian packages + . + This package contains scripts and makefiles for + script and C/C++ packages. diff --git a/debian/mbuild.cp b/debian/mbuild.cp index 0a78def..e38be77 100755 --- a/debian/mbuild.cp +++ b/debian/mbuild.cp @@ -9,4 +9,10 @@ cp tools/make/treecopy $base/usr/bin/ mkdir -p $base/usr/share/mbuild/ cp tools/make/rules $base/usr/share/mbuild/ +cp tools/make/insert_build.sh $base/usr/share/mbuild/ +cp tools/make/mMakefile $base/usr/share/mbuild/makefile + +mkdir -p $base/usr/share/man/man8 +gzip -c doc/mbuild.8 >$base/usr/share/man/man8/mbuild.8.gz +gzip -c doc/mconfigure.1 >$base/usr/share/man/man8/mconfigure.1.gz diff --git a/debian/sysd2sysv.changelog b/debian/sysd2sysv.changelog index b3a95d9..7c5564b 100644 --- a/debian/sysd2sysv.changelog +++ b/debian/sysd2sysv.changelog @@ -1,3 +1,8 @@ -projects (0.1-%BUILD%) unstable; urgency=medium +projects (0.2-%BUILD%) unstable; urgency=medium + * with template for init-script + -- Michael Wagner Sun, 11 Feb 2018 20:03:04 +0100 + +projects (0.1) unstable; urgency=medium * initial version -- Michael Wagner Sun, 11 Feb 2018 20:03:04 +0100 + diff --git a/debian/sysd2sysv.control b/debian/sysd2sysv.control new file mode 100644 index 0000000..c50d469 --- /dev/null +++ b/debian/sysd2sysv.control @@ -0,0 +1,12 @@ +Source: projects +Section: main +Priority: optional +Maintainer: Michael Wagner +Build-Depends: git + +Package: sysd2sysv +Architecture: all +Description: System V init compatibility wrapper + . + System V init compatibility wrapper + diff --git a/debian/sysd2sysv.cp b/debian/sysd2sysv.cp index 314375c..4632c02 100755 --- a/debian/sysd2sysv.cp +++ b/debian/sysd2sysv.cp @@ -4,6 +4,9 @@ set -e mkdir -p $1/usr/bin/ cp sh/sysd2sysv $1/usr/bin/ +mkdir -p $1/var/sysd2sysv +cp etc/sysd2sysv.tpl $1/var/sysd2sysv/ + # copy man page mkdir -p $1/usr/share/man/man8 gzip -c doc/sysd2sysv.8 >$1/usr/share/man/man8/sysd2sysv.8.gz diff --git a/debian/sysd2sysv.postinst b/debian/sysd2sysv.postinst new file mode 100755 index 0000000..442c70f --- /dev/null +++ b/debian/sysd2sysv.postinst @@ -0,0 +1,18 @@ +#!/bin/bash +set -e + +# delete init files created from template +pushd /etc/init.d >/dev/null +for file in $(ls) +do + if grep "# sysd2sysv-template #" $file + then + rm $file + fi + # for downward compatibility + if [ -f mlistd ] + then + rm mlistd + fi +done + diff --git a/doc/mbuild.8 b/doc/mbuild.8 index 0f7b4f1..3209b7b 100644 --- a/doc/mbuild.8 +++ b/doc/mbuild.8 @@ -1,6 +1,6 @@ .\" Manpage for mbuild. .\" Contact mail@wagnertech.de to correct errors or typos. -.TH man 8 "12 Jul 2018" "0.1" "mbuild man page" +.TH mbuild 8 "Jul 2018" GNU "WagnerTech Utilities" .SH NAME mbuild \- build system of WagnerTech UG .SH SYNOPSIS @@ -13,25 +13,59 @@ consists of 3 phases: configuration - compile - pack configuration is done by the .B mconfigure -script. It determins the verion number from the git/subversion status. Per +script. It determins the verion number from the git/subversion status. A +.B PAKET.changelog +file is needed. Per default this script also performs compile and pack step. + +If a +.B PAKET.build +file is present in the debian directory, it is called with a -prepare parameter. .TP compile To perform the compile step a .B PAKET.build -script is needed in the debian directory. +script is needed in the +.B debian +directory. .TP pack To perform the pack step a .B PAKET.cp -script is needed in the debian directory. - +script and a +.B PAKET.control +file are needed in the debian directory. If pre/post installation scripts +are needed, these files must be also placed in the +.B debian +directory. .SH FILES +.TP +PAKET.changelog +Example: +.br +projects (0.2-%BUILD%) unstable; urgency=medium + * Build in svn-Umgebung + -- Michael Wagner Fr 10. Aug 22:54:48 CEST 2018 +.TP PAKET.build - +Any executable script file executing the build in the ../build directory +.TP PAKET.cp +An executable script file copying the artefacts to target paths preposed by $1: +.br +cp ../build/my_artefact $1/usr/bin/ +.TP +PAKET.preinst PAKET.postint PAKET.prerm PAKET.postrm +Optional pre/post installation scripts +.TP +PAKET.control +Debian control file +.PP +These files are expected in a +.B debian +directory, placed below the projects main directory. .SH SEE ALSO -make(1), mconfigure(8) +make(1), mconfigure(1) .SH BUGS No known bugs. .SH AUTHOR diff --git a/doc/mconfigure.1 b/doc/mconfigure.1 new file mode 100644 index 0000000..c5b2eb6 --- /dev/null +++ b/doc/mconfigure.1 @@ -0,0 +1,35 @@ +.\" Manpage for mconfigure. +.\" Contact mail@wagnertech.de to correct errors or typos. +.TH mconfigure 1 "Aug 2018" "GNU" "WagnerTech Utilities" +.SH NAME +mconfigure \- interface to build system of WagnerTech UG +.SH SYNOPSIS +.B mconfigure +.I paket +.B [-cdp] +.SH DESCRIPTION +mconfigure builds the package +.I paket. +mconfigure has to be called in the projects base directory containing a directoty named +.B debian, +that contains the files described in +.B mbuild(8). +.SH OPTIONS +.TP +-c +select configuration step +.TP +-d +select compile step +.TP +-p +select pack step +.PP +If no steps are selected all steps are performed. +.SH SEE ALSO +mbuild(8): Overview description +.SH BUGS +No known bugs. +.SH AUTHOR +Michael Wagner (michael@wagnertech.de) + diff --git a/doc/sysd2sysv.8 b/doc/sysd2sysv.8 index ab1a271..d7bb403 100644 --- a/doc/sysd2sysv.8 +++ b/doc/sysd2sysv.8 @@ -9,7 +9,7 @@ COMMAND SERVICE .SH DESCRIPTION .PP sysd2sysv checks, if the service is present in /etc/init.d. If not -it is expected to be in /etc/sysd2sysv and copied to /etc/init.d. +it builds one from /etc/init.d/sysd2sysv.tpl. .PP Do not install in a Systemd environment! .SH AUTHOR diff --git a/etc/.dummy b/etc/.dummy new file mode 100644 index 0000000..e69de29 diff --git a/etc/sysd2sysv.tpl b/etc/sysd2sysv.tpl new file mode 100644 index 0000000..8e61839 --- /dev/null +++ b/etc/sysd2sysv.tpl @@ -0,0 +1,123 @@ +#!/bin/bash +set -e # end if anything fails + +# tag: if the next line is changed/removed a reinstall of sysd2sysv will keep this file +# sysd2sysv-template # + +PROG=%PROG% +PROG_PATH=$(which $PROG) || { echo "$PROG missing"; exit 1; } + +syslog=/dev/null +syserr=/tmp/%PROG%.err + +RETVAL=0 + +. /lib/lsb/init-functions + +usage() { + echo "$0 [options] start|restart|stop" + echo " -l DEFAULT: $syslog" + echo " -e DEFAULT: $syserr" +} + +start () { + + # check, if process is already running + if [ `ps -ef | grep $PROG_PATH | grep -v grep | grep -v bash | wc -l` -gt 0 ] + then + log_end_msg 1 + exit 1 + fi + + log_daemon_msg $PROG || true + ($PROG &) 1>>$syslog 2>>$syserr + sleep 2 + if status_of_proc $PROG + then + log_end_msg 0 || true + else + log_end_msg 1 || true + fi +} + +status() { + if [ `ps -ef | grep $PROG_PATH | grep -v grep | grep -v bash | wc -l` -gt 0 ] + then + echo -n $PROG" is running..." + echo "" + else + echo -n $PROG" is stopped" + echo "" + fi +} + +stop () { + log_daemon_msg "Stopping $PROG" + kill $(ps aux |grep $PROG_PATH |grep -v grep | awk '{print $2}') || true + return 0 +} + +# evaluate parameters + +operation="NOP" + +while [ -n "$1" ] +do + case "$1" in + start) + operation=start + shift + ;; + restart) + operation=restart + shift + ;; + stop) + operation=stop + shift + ;; + -c) + configfile=$2 + shift 2 + ;; + -l) + syslog=$2 + if [ -f $syslog ]; then rm $syslog; fi + shift 2 + ;; + -e) + syserr=$2 + shift 2 + ;; + -h) + usage + exit 0 + ;; + *) + usage + exit 1 + ;; + esac +done + +if [ -f $syserr ]; then rm $syserr; fi + +case $operation in +start) + start + ;; +stop) + stop + ;; +restart) + stop + start + ;; +*) + usage + exit 1 + ;; +esac + +exit 0 + diff --git a/sh/sysd2sysv b/sh/sysd2sysv index dee45a7..d1dec0d 100755 --- a/sh/sysd2sysv +++ b/sh/sysd2sysv @@ -8,12 +8,14 @@ then fi if [ ! -f /etc/init.d/$2 ] - cp /etc/sysd2sysv/$2 /etc/init.d/ +then + sed "s/%PROG%/$2/" /var/sysd2sysv/sysd2sysv.tpl > /etc/init.d/$2 + chmod 755 /etc/init.d/$2 fi if [ $1 = "enable" ] then - update-rc.d $2 defaults 100 + update-rc.d $2 defaults 99 elif [ $1 = "disable" ] then update-rc.d -f $2 remove diff --git a/tools/make/mMakefile b/tools/make/mMakefile new file mode 100644 index 0000000..d6da7bb --- /dev/null +++ b/tools/make/mMakefile @@ -0,0 +1,39 @@ +# Generic makefile for mBuild build process + + +# default parameters +CC = g++ +INSERT_BUILD = /usr/share/mbuild/insert_build.sh + +include make.pre + +# All Target +all: $(DEPS) $(SOURCE:%.cpp=%.o) $(TARGET) + +# Other Targets +clean: + -rm *.o + -rm $(TARGET) + + +.PHONY: all make.post + +%.a: $(SOURCE:%.cpp=%.o) + ar r $(TARGET) *.o + +%.so: $(SOURCE:%.cpp=%.o) $(LDLIBS) + $(CXX) -shared -o $(TARGET) *.o $(LDLIBS) $(EXTLIB) + +make.pre: ~/build/debian/rules.pre + cp ~/build/debian/rules.pre make.pre + +-include make.post +# defile default operations + +#----------------------------------------------------------------- +# Build-Regeln +#----------------------------------------------------------------- +%.pdf : %.tex $(SOURCES) + pdflatex $< && pdflatex $< + cp $*.pdf ~/build + diff --git a/tools/make/makefile b/tools/make/makefile index 57dc39d..1bee6f4 100644 --- a/tools/make/makefile +++ b/tools/make/makefile @@ -87,3 +87,4 @@ clean: %.pdf : %.tex $(SOURCES) pdflatex $< && pdflatex $< + diff --git a/tools/make/mconfigure b/tools/make/mconfigure index f745eff..a6e919d 100755 --- a/tools/make/mconfigure +++ b/tools/make/mconfigure @@ -4,9 +4,9 @@ set -e function echo_usage { echo "usage: mconfigure [options]" echo " -a " - echo " -c : configure only, no compile, pack" - echo " -d : compile only" - echo " -p : pack only" + echo " -c : configure" + echo " -d : compile" + echo " -p : pack default: do all" } function set_build { @@ -22,6 +22,11 @@ function set_build { then tag="0.0-TOP" fi + tag_paket=${tag%_*} + if [ "$tag_paket" != "$paket" ] + then + tag="0.0-TOP" + fi changes=$(git status -s |grep "^ *M") || true if test -n "$changes" then @@ -30,10 +35,14 @@ function set_build { version=${tag%%-*} version=${version##*_} build=${tag#*-} + else + echo "No configuration system found. Cannot determine version." + exit 1 fi } function check_version { + vline=$(head -1 debian/$paket.changelog) vline=${vline%-*} clversion=${vline#*(} @@ -42,6 +51,13 @@ function check_version { version=$clversion return fi + + # do no check on a modified git repos + if [ "${build: -1}" == "M" ] + then + return + fi + if [ "$clversion" != $version ] then echo "version mismatch: git: $version, changelog: $clversion" @@ -66,21 +82,19 @@ fi paket=$1 -configure=1 -compile=1 -pack=1 -while getopts ":ap" opt; do +configure=0 +compile=0 +pack=0 +shift +while getopts ":acdp" opt; do case $opt in a) ARCH=$OPTARG ;; - c) compile=0 - pack=0 + c) configure=1 ;; - d) configure=0 - pack=0 + d) compile=1 ;; - p) configure=0 - compile=0 + p) pack=1 ;; \?) echo "Invalid option: -$OPTARG" echo_usage @@ -93,27 +107,39 @@ while getopts ":ap" opt; do esac done +# if nothing is selected, select all +if [ $configure -eq 0 -a $compile -eq 0 -a $pack -eq 0 ] +then + configure=1 + compile=1 + pack=1 +fi + if [ $configure -eq 1 ] then - echo "export paket=$1" > debian/setenv.sh - shift + # delete changelog and control + rm debian/changelog debian/control || true + + echo "paket=$paket" > debian/rules.pre +# shift ARCH="" cpp_build=0 set_build check_version - echo "export version=$version" >> debian/setenv.sh - echo "export build=$build" >> debian/setenv.sh + echo "version=$version" >> debian/rules.pre + echo "build=$build" >> debian/rules.pre # get repository name - tmp=$(pwd) - pwd=${tmp##*/} - pwd=${pwd,,*} - echo "export pwd=$pwd" >> debian/setenv.sh +# tmp=$(pwd) +# pwd=${tmp##*/} +# pwd=${pwd,,*} +# echo "pwd=$pwd" >> debian/rules.pre echo "building $paket with build $version-$build" pushd debian >/dev/null + # ./debian ------------------------------------- ln -sf /usr/share/mbuild/rules . @@ -121,8 +147,24 @@ then then rm -rf tmp fi - #rm *.stamp 2>/dev/null || true - #rm make.pre 2>/dev/null || true + + # check for pre/post installation scripts + if [ -f $paket.preinst ] + then + echo "add_inst_tgt += debian/tmp/DEBIAN/preinst" >> rules.pre + fi + if [ -f $paket.postinst ] + then + echo "add_inst_tgt += debian/tmp/DEBIAN/postinst" >> rules.pre + fi + if [ -f $paket.prerm ] + then + echo "add_inst_tgt += debian/tmp/DEBIAN/prerm" >> rules.pre + fi + if [ -f $paket.postrm ] + then + echo "add_inst_tgt += debian/tmp/DEBIAN/postrm" >> rules.pre + fi mkdir -p tmp/DEBIAN @@ -135,41 +177,63 @@ then fi popd >/dev/null + # ./. --------------------------------------------- # copy package control - if [ ! -f debian/control ] + if [ -f debian/$paket.control ] then - control=$(find etc -name $paket.control) + # proceed + echo + else + # try old fashoned way + control=$(find etc -name $paket.control) || true if [ -z "$control" ] then echo "warning: control file not found" echo " this file is necessary for any package production." else - echo "Source: $pwd + echo "Source: $paket Section: main Priority: optional Maintainer: WagnerTech UG - " > debian/control - grep -v "Version:" $control |grep -v "Maintainer:" >> debian/control + " > debian/$paket.control + grep -v "Version:" $control |grep -v "Maintainer:" >> debian/$paket.control + fi + fi + + # build prepare + if [ -e debian/$paket.build ] + then + if [ -e ../build ] + then + rm -rf ../build + mkdir ../build + fi + if grep -- "-prepare" debian/$paket.build >/dev/null + then + debian/rules sync + debian/$paket.build -prepare fi fi + + # pack prepare + if [ -f debian/$paket.cp -a -f debian/$paket.control ] + then + echo "PACK=binary" >> debian/rules.pre + elif [ -f debian/$paket.cp ] + then + echo "PACK=zip" >> debian/rules.pre + else + echo "PACK=version" >> debian/rules.pre + fi + cp debian/rules.pre debian/setenv.sh fi -# check for copy file -#if [ ! -f debian/$paket.cp ] -#then -# # search for copy file -# copy=$(find . -name $paket.cp) -# if [ -n "$copy" ] -# then -# echo "ln -sf ../$copy debian/" -# ln -sf ../$copy debian/ -# else -# echo "warning: file $paket.cp missing or not executable:" -# echo " this file is necessary for any package production." -# fi -#fi - +if [ $compile -eq 1 -a ! -e debian/$paket.build ] +then + echo "no debian/build.sh: skipping build step" + compile=0 +fi if [ $compile -eq 1 ] then # build artefacts @@ -181,6 +245,6 @@ if [ $pack -eq 1 ] then # build package . debian/setenv.sh - debian/rules binary + debian/rules pack fi diff --git a/tools/make/rules b/tools/make/rules index da98ee5..33e72e3 100755 --- a/tools/make/rules +++ b/tools/make/rules @@ -5,6 +5,9 @@ # defile default operations NOP = @echo "No operation for target $@" DEB = fakeroot dpkg-deb --build debian/tmp +INSERT_BUILD = /usr/share/mbuild/insert_build.sh + +include debian/rules.pre default: echo "no default rule available" @@ -14,7 +17,12 @@ clean: -rm -rf debian/tmp # Bauen der kompilierten Programme und formatierten Dokumente aus den Quellen im Bauverzeichnis -build: +build: debian/$(paket).build sync + debian/$(paket).build + # Build succeeded + +pack: $(PACK) + # packing succeeded # Bauen der kompilierten architekturabhängigen Programme aus den Quellen im Bauverzeichnis build-arch: @@ -34,23 +42,48 @@ binary-arch: # Erstellen Architektur-unabhängiger (Architecture: all) Binärpakete im übergeordneten Verzeichnis binary-indep: copy ../$(paket)_$(version)-$(build)$(_arch).deb +version: ~/build/$(TARGET) + $(INSERT_BUILD) ~/build/$(TARGET) $(build) + cp ~/build/*$(build)* ../ + +../build: + mkdir ../build + +sync: + bash -c 'for dirs in $$(ls); do rsync -av $$dirs ../build; done' + copy: debian/$(paket).cp debian/$(paket).cp debian/tmp -../$(paket)_$(version)-$(build)$(_arch).deb:debian/tmp/DEBIAN/control +../$(paket)_$(version)-$(build)$(_arch).deb:debian/tmp/DEBIAN/control $(add_inst_tgt) $(DEB) mv debian/tmp.deb ../$(paket)_$(version)-$(build)$(_arch).deb debian/tmp/DEBIAN/control: debian/control debian/changelog dpkg-gencontrol -debian/changelog: debian/$(paket).changelog debian/setenv.sh +debian/control: debian/$(paket).control + cp debian/$(paket).control debian/control + +debian/changelog: debian/$(paket).changelog debian/rules.pre sed "s/%BUILD%/$(build)/" debian/$(paket).changelog > debian/changelog # echo "${pwd} (${build}) unstable; urgency=medium" > debian/changelog # echo " * generated by mbuild" >> debian/changelog # echo " -- Michael Wagner Sun, 11 Feb 2018 20:03:04 +0100" >> debian/changelog # mb_create_changelog +debian/tmp/DEBIAN/preinst: debian/$(paket).preinst + cp debian/$(paket).preinst debian/tmp/DEBIAN/preinst + +debian/tmp/DEBIAN/postinst: debian/$(paket).postinst + cp debian/$(paket).postinst debian/tmp/DEBIAN/postinst + +debian/tmp/DEBIAN/prerm: debian/$(paket).prerm + cp debian/$(paket).prerm debian/tmp/DEBIAN/prerm + +debian/tmp/DEBIAN/postrm: debian/$(paket).postrm + cp debian/$(paket).postrm debian/tmp/DEBIAN/postrm + # Load project specification -include rules.post