import build scripts from systemd-cron
This commit is contained in:
parent
9fa4ae1271
commit
f58e2ea6dd
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
||||
target/
|
||||
Makefile
|
||||
|
224
Makefile.in
Normal file
224
Makefile.in
Normal file
@ -0,0 +1,224 @@
|
||||
CFLAGS ?= -O2
|
||||
CFLAGS += -Wall
|
||||
|
||||
package := $(shell cat README.md | head -n1)
|
||||
version := $(shell cat VERSION)
|
||||
|
||||
schedules := @schedules@
|
||||
schedules_not := @schedules_not@
|
||||
enable_persistent := @enable_persistent@
|
||||
enable_setgid := @enable_setgid@
|
||||
|
||||
prefix := @prefix@
|
||||
bindir := @bindir@
|
||||
confdir := @confdir@
|
||||
datadir := @datadir@
|
||||
libdir := @libdir@
|
||||
statedir := @statedir@
|
||||
mandir := @mandir@
|
||||
docdir := @docdir@
|
||||
unitdir := @unitdir@
|
||||
|
||||
runparts := @runparts@
|
||||
stale_stamps := @stale_stamps@
|
||||
|
||||
srcdir := $(CURDIR)/src
|
||||
outdir := $(CURDIR)/out
|
||||
builddir := $(outdir)/build
|
||||
distname := $(package)-$(version)
|
||||
distdir := $(outdir)/dist/$(distname)
|
||||
tarball := $(outdir)/dist/$(distname).tar.xz
|
||||
|
||||
out_services := $(foreach schedule,$(schedules),$(builddir)/units/cron-$(schedule).service)
|
||||
out_timers := $(foreach schedule,$(schedules),$(builddir)/units/cron-$(schedule).timer)
|
||||
out_targets := $(foreach schedule,$(schedules),$(builddir)/units/cron-$(schedule).target)
|
||||
out_units := $(out_services) $(out_timers) $(out_targets) $(builddir)/units/cron.target \
|
||||
$(builddir)/units/cron-update.path $(builddir)/units/cron-update.service \
|
||||
$(builddir)/units/cron-failure@.service
|
||||
out_manuals := $(patsubst $(srcdir)/man/%.in,$(builddir)/man/%,$(wildcard $(srcdir)/man/*))
|
||||
out_programs := $(patsubst $(srcdir)/bin/%.py,$(builddir)/bin/%,$(wildcard $(srcdir)/bin/*.py))
|
||||
outputs := $(out_units) $(out_manuals) $(out_programs) $(builddir)/bin/crontab_setgid
|
||||
|
||||
define \n
|
||||
|
||||
|
||||
endef
|
||||
|
||||
null :=
|
||||
requires = $(subst ${null} ${null},\n,$(foreach schedule,$(schedules),Requires=cron-$(schedule).timer))
|
||||
persistent = $(if $(filter $(enable_persistent),yes),True,False)
|
||||
|
||||
# $(call in2out,$input,$output,$schedule,$requires)
|
||||
define in2out
|
||||
|
||||
sed \
|
||||
-e "s|\@package\@|$(package)|g" \
|
||||
-e "s|\@confdir\@|$(confdir)|g" \
|
||||
-e "s|\@statedir\@|$(statedir)|g" \
|
||||
-e "s|\@bindir\@|$(bindir)|g" \
|
||||
-e "s|\@libdir\@|$(libdir)|g" \
|
||||
-e "s|\@unitdir\@|$(unitdir)|g" \
|
||||
-e "s|\@runparts\@|$(runparts)|g" \
|
||||
-e "s|\@version\@|$(version)|g" \
|
||||
-e "s|\@persistent\@|$(persistent)|g" \
|
||||
-e "s|\@schedule\@|$3|g" \
|
||||
-e "s|\@requires\@|$4|g" \
|
||||
$1 > $2
|
||||
endef
|
||||
|
||||
all: $(builddir) $(outputs)
|
||||
|
||||
clean:
|
||||
rm -rf $(outdir)
|
||||
|
||||
distprep: $(distdir)
|
||||
cp -a configure $(distdir)
|
||||
cp -a Makefile.in $(distdir)
|
||||
cp -a LICENSE $(distdir)
|
||||
cp -a README.md $(distdir)
|
||||
cp -a VERSION $(distdir)
|
||||
cp -a src $(distdir)
|
||||
|
||||
dist: $(tarball)
|
||||
|
||||
test: all
|
||||
$(foreach manpage,$(out_manuals),\
|
||||
man --warnings --encoding=utf8 --local-file $(manpage) 2>&1 > /dev/null${\n})
|
||||
$(foreach program,$(out_programs),\
|
||||
pyflakes3 $(program) ${\n})
|
||||
|
||||
install: all
|
||||
install -m755 -D $(builddir)/bin/crontab $(DESTDIR)$(bindir)/crontab
|
||||
install -m755 -D $(builddir)/bin/systemd-crontab-generator $(DESTDIR)$(libdir)/systemd/system-generators/systemd-crontab-generator
|
||||
install -m755 -D $(builddir)/bin/remove_stale_stamps $(DESTDIR)$(stale_stamps)
|
||||
install -m755 -D $(builddir)/bin/mail_on_failure $(DESTDIR)$(libdir)/$(package)/mail_on_failure
|
||||
install -m755 -D $(builddir)/bin/boot_delay $(DESTDIR)$(libdir)/$(package)/boot_delay
|
||||
ifneq ($(enable_setgid),no)
|
||||
install -m755 -D $(builddir)/bin/crontab_setgid $(DESTDIR)$(libdir)/$(package)/crontab_setgid
|
||||
if getent group cron > /dev/null 2>&1; then \
|
||||
chgrp cron $(DESTDIR)$(libdir)/$(package)/crontab_setgid ; \
|
||||
chmod 2755 $(DESTDIR)$(libdir)/$(package)/crontab_setgid ; \
|
||||
fi
|
||||
endif
|
||||
|
||||
install -m644 -D $(builddir)/man/systemd.cron.7 $(DESTDIR)$(mandir)/man7/systemd.cron.7
|
||||
install -m644 -D $(builddir)/man/crontab.1 $(DESTDIR)$(mandir)/man1/crontab.1
|
||||
install -m644 -D $(builddir)/man/crontab.5 $(DESTDIR)$(mandir)/man5/crontab.5
|
||||
install -m644 -D $(builddir)/man/anacrontab.5 $(DESTDIR)$(mandir)/man5/anacrontab.5
|
||||
install -m644 -D $(builddir)/man/systemd-crontab-generator.8 $(DESTDIR)$(mandir)/man8/systemd-crontab-generator.8
|
||||
|
||||
install -m644 -D $(builddir)/units/cron.target $(DESTDIR)$(unitdir)/cron.target
|
||||
install -m644 $(builddir)/units/cron-update.path $(DESTDIR)$(unitdir)
|
||||
install -m644 $(builddir)/units/cron-update.service $(DESTDIR)$(unitdir)
|
||||
install -m644 $(builddir)/units/cron-failure@.service $(DESTDIR)$(unitdir)
|
||||
|
||||
$(foreach schedule,$(schedules),\
|
||||
install -m644 $(builddir)/units/cron-$(schedule).timer $(DESTDIR)$(unitdir)${\n})
|
||||
$(foreach schedule,$(schedules),\
|
||||
install -m644 $(builddir)/units/cron-$(schedule).target $(DESTDIR)$(unitdir)${\n})
|
||||
$(foreach schedule,$(schedules),\
|
||||
install -m644 $(builddir)/units/cron-$(schedule).service $(DESTDIR)$(unitdir)${\n})
|
||||
|
||||
uninstall:
|
||||
rm -f $(DESTDIR)$(bindir)/crontab
|
||||
rm -f $(DESTDIR)$(libdir)/systemd/system-generators/systemd-crontab-generator
|
||||
rm -f $(DESTDIR)$(stale_stamps)
|
||||
rm -f $(DESTDIR)$(libdir)/$(package)/mail_on_failure
|
||||
rm -f $(DESTDIR)$(libdir)/$(package)/boot_delay
|
||||
rm -f $(DESTDIR)$(libdir)/$(package)/crontab_setgid
|
||||
|
||||
rm -f $(DESTDIR)$(mandir)/man7/systemd.cron.7
|
||||
rm -f $(DESTDIR)$(mandir)/man1/crontab.1
|
||||
rm -f $(DESTDIR)$(mandir)/man5/crontab.5
|
||||
rm -f $(DESTDIR)$(mandir)/man5/anacrontab.5
|
||||
rm -f $(DESTDIR)$(mandir)/man8/systemd-crontab-generator.8
|
||||
|
||||
rm -f $(DESTDIR)$(unitdir)/cron.target
|
||||
rm -f $(DESTDIR)$(unitdir)/cron-update.path
|
||||
rm -f $(DESTDIR)$(unitdir)/cron-update.service
|
||||
rm -f $(DESTDIR)$(unitdir)/cron-failure@.service
|
||||
|
||||
$(foreach schedule,$(schedules),\
|
||||
rm -f $(DESTDIR)$(unitdir)/cron-$(schedule).timer${\n})
|
||||
$(foreach schedule,$(schedules),\
|
||||
rm -f $(DESTDIR)$(unitdir)/cron-$(schedule).target${\n})
|
||||
$(foreach schedule,$(schedules),\
|
||||
rm -f $(DESTDIR)$(unitdir)/cron-$(schedule).service${\n})
|
||||
|
||||
|
||||
|
||||
$(builddir)/units/cron-update.path: $(srcdir)/units/cron-update.path.in
|
||||
$(call in2out,$<,$@)
|
||||
|
||||
$(builddir)/units/cron-update.service: $(srcdir)/units/cron-update.service.in
|
||||
$(call in2out,$<,$@)
|
||||
|
||||
$(builddir)/units/cron-failure@.service: $(srcdir)/units/cron-failure@.service.in
|
||||
$(call in2out,$<,$@)
|
||||
|
||||
$(builddir)/units/cron-%.service: $(srcdir)/units/cron-schedule.service.in
|
||||
$(call in2out,$<,$@,$*)
|
||||
|
||||
$(builddir)/units/cron-boot.service: $(srcdir)/units/cron-boot.service.in
|
||||
$(call in2out,$<,$@,boot)
|
||||
|
||||
$(builddir)/units/cron-%.timer: $(srcdir)/units/cron-schedule.timer.in
|
||||
$(call in2out,$<,$@,$*)
|
||||
ifneq ($(enable_persistent),yes)
|
||||
sed -i -e '/^Persistent=/d' $@
|
||||
endif
|
||||
|
||||
$(builddir)/units/cron-boot.timer: $(srcdir)/units/cron-boot.timer.in
|
||||
$(call in2out,$<,$@,boot)
|
||||
|
||||
$(builddir)/units/cron-%.target: $(srcdir)/units/cron-schedule.target.in
|
||||
$(call in2out,$<,$@,$*)
|
||||
|
||||
$(builddir)/units/cron.target: $(srcdir)/units/cron.target.in
|
||||
$(call in2out,$<,$@,,$(requires))
|
||||
|
||||
$(builddir)/man/%: $(srcdir)/man/%.in
|
||||
$(call in2out,$<,$@)
|
||||
|
||||
$(builddir)/man/systemd.cron.7: $(srcdir)/man/systemd.cron.7.in
|
||||
$(call in2out,$<,$@)
|
||||
$(foreach schedule_not,$(schedules_not),\
|
||||
sed -i $@ -e '/cron-$(schedule_not).timer/d' \
|
||||
-e '/cron\.$(schedule_not)/,+3d' \
|
||||
-e '/journalctl -u cron-$(schedule_not)/,+1d' ${\n})
|
||||
|
||||
$(builddir)/bin/systemd-crontab-generator: $(srcdir)/bin/systemd-crontab-generator.py
|
||||
$(call in2out,$<,$@)
|
||||
# BUG: this should only run if schedule_not in hourly/daily/weekly/monthly
|
||||
$(foreach schedule_not,$(schedules_not),\
|
||||
sed -i $@ -e '/\/etc\/cron.$(schedule_not)/d' ${\n})
|
||||
chmod +x $@
|
||||
|
||||
$(builddir)/bin/%: $(srcdir)/bin/%.py
|
||||
$(call in2out,$<,$@)
|
||||
chmod +x $@
|
||||
|
||||
$(builddir)/bin/crontab_setgid: $(srcdir)/bin/crontab_setgid.c
|
||||
ifneq ($(enable_setgid),no)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) $< -DCRONTAB_DIR='"$(statedir)"' -o $@
|
||||
endif
|
||||
|
||||
$(outputs): | $(builddir)
|
||||
|
||||
$(outdir):
|
||||
mkdir -p $@
|
||||
|
||||
$(builddir):
|
||||
mkdir -p $@
|
||||
mkdir -p $@/bin
|
||||
mkdir -p $@/man
|
||||
mkdir -p $@/units
|
||||
|
||||
$(distdir):
|
||||
mkdir -p $(distdir)
|
||||
|
||||
$(tarball): distprep
|
||||
cd $(distdir)/..; tar -cJ --owner=root --group=root --file $(tarball) $(distname)
|
||||
|
||||
.PHONY: all clean dist distprep install uninstall
|
||||
|
237
configure
vendored
Executable file
237
configure
vendored
Executable file
@ -0,0 +1,237 @@
|
||||
#!/bin/sh
|
||||
|
||||
prefix='/usr/local'
|
||||
bindir='$(prefix)/bin'
|
||||
confdir='$(prefix)/etc'
|
||||
datadir='$(prefix)/share'
|
||||
libdir='$(prefix)/lib'
|
||||
statedir='/var/spool/cron'
|
||||
mandir='$(datadir)/man'
|
||||
docdir='$(datadir)/doc/$(package)'
|
||||
unitdir='$(libdir)/systemd/system'
|
||||
runparts='/usr/bin/run-parts'
|
||||
enable_setgid=no
|
||||
|
||||
# systemd ≥ 197
|
||||
enable_boot=yes
|
||||
enable_hourly=yes
|
||||
enable_daily=yes
|
||||
enable_weekly=yes
|
||||
enable_monthly=yes
|
||||
|
||||
# systemd ≥ 209
|
||||
enable_yearly=no
|
||||
|
||||
# systemd ≥ 212
|
||||
enable_persistent=no
|
||||
stale_stamps='$(libdir)/$(package)/remove_stale_stamps'
|
||||
|
||||
# systemd ≥ 217
|
||||
enable_minutely=no
|
||||
enable_quarterly=no
|
||||
enable_semi_annually=no
|
||||
|
||||
ARGS=$(getopt -n "$(basename "${0}")" -o '' -l '
|
||||
prefix:,
|
||||
bindir:,
|
||||
confdir:,
|
||||
datadir:,
|
||||
libdir:,
|
||||
statedir:,
|
||||
mandir:,
|
||||
docdir:,
|
||||
unitdir:,
|
||||
runparts:,
|
||||
stale-stamps:,
|
||||
enable-boot::,
|
||||
enable-minutely::,
|
||||
enable-hourly::,
|
||||
enable-daily::,
|
||||
enable-weekly::,
|
||||
enable-monthly::,
|
||||
enable-quarterly::,
|
||||
enable-semi_annually::,
|
||||
enable-yearly::,
|
||||
enable-persistent::,
|
||||
enable-setgid::,
|
||||
' -- "${@}")
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
set_enable_flag()
|
||||
{
|
||||
if [ -z ${2} ]; then
|
||||
eval "enable_${1}=yes"
|
||||
elif [ ${2} = 'yes' ] || [ ${2} = 'no' ]; then
|
||||
eval "enable_${1}=${2}"
|
||||
else
|
||||
echo "ERROR: Unkown value for enable-${1}: '${2}'. Expected 'yes' or 'no'."
|
||||
fi
|
||||
}
|
||||
|
||||
eval set -- "${ARGS}"
|
||||
while true;
|
||||
do
|
||||
case "${1}" in
|
||||
'--prefix')
|
||||
prefix="${2}"
|
||||
shift 2;;
|
||||
|
||||
'--bindir')
|
||||
bindir="${2}"
|
||||
shift 2;;
|
||||
|
||||
'--confdir')
|
||||
confdir="${2}"
|
||||
shift 2;;
|
||||
|
||||
'--datadir')
|
||||
datadir="${2}"
|
||||
shift 2;;
|
||||
|
||||
'--libdir')
|
||||
libdir="${2}"
|
||||
shift 2;;
|
||||
|
||||
'--statedir')
|
||||
statedir="${2}"
|
||||
shift 2;;
|
||||
|
||||
'--mandir')
|
||||
mandir="${2}"
|
||||
shift 2;;
|
||||
|
||||
'--docdir')
|
||||
docdir="${2}"
|
||||
shift 2;;
|
||||
|
||||
'--unitdir')
|
||||
unitdir="${2}"
|
||||
shift 2;;
|
||||
|
||||
'--runparts')
|
||||
runparts="${2}"
|
||||
shift 2;;
|
||||
|
||||
'--stale-stamps')
|
||||
stale_stamps="${2}"
|
||||
shift 2;;
|
||||
|
||||
'--enable-boot')
|
||||
set_enable_flag boot ${2}
|
||||
shift 2;;
|
||||
|
||||
'--enable-minutely')
|
||||
set_enable_flag minutely ${2}
|
||||
shift 2;;
|
||||
|
||||
'--enable-hourly')
|
||||
set_enable_flag hourly ${2}
|
||||
shift 2;;
|
||||
|
||||
'--enable-daily')
|
||||
set_enable_flag daily ${2}
|
||||
shift 2;;
|
||||
|
||||
'--enable-weekly')
|
||||
set_enable_flag weekly ${2}
|
||||
shift 2;;
|
||||
|
||||
'--enable-monthly')
|
||||
set_enable_flag monthly ${2}
|
||||
shift 2;;
|
||||
|
||||
'--enable-quarterly')
|
||||
set_enable_flag quarterly ${2}
|
||||
shift 2;;
|
||||
|
||||
'--enable-semi_annually')
|
||||
set_enable_flag semi_annually ${2}
|
||||
shift 2;;
|
||||
|
||||
'--enable-yearly')
|
||||
set_enable_flag yearly ${2}
|
||||
shift 2;;
|
||||
|
||||
'--enable-persistent')
|
||||
set_enable_flag persistent ${2}
|
||||
shift 2;;
|
||||
|
||||
'--enable-setgid')
|
||||
set_enable_flag setgid ${2}
|
||||
shift 2;;
|
||||
|
||||
'--')
|
||||
shift
|
||||
break;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ ${enable_boot} = 'yes' ]; then
|
||||
schedules="${schedules} boot"
|
||||
else
|
||||
schedules_not="${schedules_not} boot"
|
||||
fi
|
||||
|
||||
if [ ${enable_minutely} = 'yes' ]; then
|
||||
schedules="${schedules} minutely"
|
||||
else
|
||||
schedules_not="${schedules_not} minutely"
|
||||
fi
|
||||
if [ ${enable_hourly} = 'yes' ]; then
|
||||
schedules="${schedules} hourly"
|
||||
else
|
||||
schedules_not="${schedules_not} hourly"
|
||||
fi
|
||||
if [ ${enable_daily} = 'yes' ]; then
|
||||
schedules="${schedules} daily"
|
||||
else
|
||||
schedules_not="${schedules_not} daily"
|
||||
fi
|
||||
if [ ${enable_weekly} = 'yes' ]; then
|
||||
schedules="${schedules} weekly"
|
||||
else
|
||||
schedules_not="${schedules_not} weekly"
|
||||
fi
|
||||
if [ ${enable_monthly} = 'yes' ]; then
|
||||
schedules="${schedules} monthly"
|
||||
else
|
||||
schedules_not="${schedules_not} monthly"
|
||||
fi
|
||||
if [ ${enable_quarterly} = 'yes' ]; then
|
||||
schedules="${schedules} quarterly"
|
||||
else
|
||||
schedules_not="${schedules_not} quarterly"
|
||||
fi
|
||||
if [ ${enable_semi_annually} = 'yes' ]; then
|
||||
schedules="${schedules} semi-annually"
|
||||
else
|
||||
schedules_not="${schedules_not} semi-annually"
|
||||
fi
|
||||
if [ ${enable_yearly} = 'yes' ]; then
|
||||
schedules="${schedules} yearly"
|
||||
else
|
||||
schedules_not="${schedules_not} yearly"
|
||||
fi
|
||||
|
||||
echo '# Generated by ./configure' > Makefile
|
||||
sed "
|
||||
s|@schedules@|${schedules}|g
|
||||
s|@schedules_not@|${schedules_not}|g
|
||||
s|@enable_persistent@|${enable_persistent}|g
|
||||
s|@enable_setgid@|${enable_setgid}|g
|
||||
s|@prefix@|${prefix}|g
|
||||
s|@bindir@|${bindir}|g
|
||||
s|@confdir@|${confdir}|g
|
||||
s|@datadir@|${datadir}|g
|
||||
s|@libdir@|${libdir}|g
|
||||
s|@statedir@|${statedir}|g
|
||||
s|@mandir@|${mandir}|g
|
||||
s|@docdir@|${docdir}|g
|
||||
s|@unitdir@|${unitdir}|g
|
||||
s|@runparts@|${runparts}|g
|
||||
s|@stale_stamps@|${stale_stamps}|g
|
||||
" Makefile.in >> Makefile
|
||||
|
Loading…
x
Reference in New Issue
Block a user