File cron2timers of Package systemd-generator-cron2timer

#!/bin/bash
# SPDX-License-Identifier: MIT
# SPDX-FileCopyrightText: Copyright 2022-2023 SUSE LLC
set -e
out="${1:?}"
shopt -s nullglob
mkdir -p "$out/timers.target.wants/"
for interval in hourly daily weekly monthly yearly; do
	for script in /etc/cron."$interval"/*; do
		f="${script##*/}"
		cat > "$out/$interval-$f.timer" <<-EOF
		[Unit]
		Description=Timer created from $script

		[Timer]
		OnCalendar=$interval
		AccuracySec=1h
		Persistent=true

		[Install]
		WantedBy=timers.target
		EOF
		cat > "$out/$interval-$f.service" <<-EOF
		[Unit]
		Description=Service created from $script
		ConditionACPower=true

		[Service]
		ExecStart=$script
		EOF
		ln -s "../$interval-$f.timer" "$out/timers.target.wants/$interval-$f.timer"
	done
done
openSUSE Build Service is sponsored by