aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore125
-rwxr-xr-xcronify.pl71
-rwxr-xr-x[-rw-r--r--]initify.pl39
3 files changed, 235 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..4df4753
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,125 @@
+
+# Created by https://www.gitignore.io/api/perl,linux,emacs
+
+### Emacs ###
+# -*- mode: gitignore; -*-
+*~
+\#*\#
+/.emacs.desktop
+/.emacs.desktop.lock
+*.elc
+auto-save-list
+tramp
+.\#*
+
+# Org-mode
+.org-id-locations
+*_archive
+
+# flymake-mode
+*_flymake.*
+
+# eshell files
+/eshell/history
+/eshell/lastdir
+
+# elpa packages
+/elpa/
+
+# reftex files
+*.rel
+
+# AUCTeX auto folder
+/auto/
+
+# cask packages
+.cask/
+dist/
+
+# Flycheck
+flycheck_*.el
+
+# server auth directory
+/server/
+
+# projectiles files
+.projectile
+projectile-bookmarks.eld
+
+# directory configuration
+.dir-locals.el
+
+# saveplace
+places
+
+# url cache
+url/cache/
+
+# cedet
+ede-projects.el
+
+# smex
+smex-items
+
+# company-statistics
+company-statistics-cache.el
+
+# anaconda-mode
+anaconda-mode/
+
+### Linux ###
+
+# temporary files which can be created if a process still has a handle open of a deleted file
+.fuse_hidden*
+
+# KDE directory preferences
+.directory
+
+# Linux trash folder which might appear on any partition or disk
+.Trash-*
+
+# .nfs files are created when an open file is removed but is still being accessed
+.nfs*
+
+### Perl ###
+!Build/
+.last_cover_stats
+/META.yml
+/META.json
+/MYMETA.*
+*.o
+*.pm.tdy
+*.bs
+
+# Devel::Cover
+cover_db/
+
+# Devel::NYTProf
+nytprof.out
+
+# Dizt::Zilla
+/.build/
+
+# Module::Build
+_build/
+Build
+Build.bat
+
+# Module::Install
+inc/
+
+# ExtUitls::MakeMaker
+/blib/
+/_eumm/
+/*.gz
+/Makefile
+/Makefile.old
+/MANIFEST.bak
+/pm_to_blib
+/*.zip
+
+# End of https://www.gitignore.io/api/perl,linux,emacs
+
+*.save
+*.service
+*.timer \ No newline at end of file
diff --git a/cronify.pl b/cronify.pl
new file mode 100755
index 0000000..e354b44
--- /dev/null
+++ b/cronify.pl
@@ -0,0 +1,71 @@
+#!/bin/env perl
+
+my @timestamps;
+
+while(<>) {
+ my @timestamp = ("*", "*", "*", "*", "*");
+ if(m/OnCalendar=(.*)/) {
+ if ($1 =~ /^(hourly|daily|monthly|yearly)$/) {
+ # Use cron's special strings for better readability
+ @timestamp = ('@' . "$1");
+ } elsif ($1 =~ /minutely/) {
+ @timestamp = ("*", "*", "*", "*", "*");
+ } elsif ($1 =~ /weekly/) {
+ # Systemd does weekly on Mondays, but cron
+ # does it on Sundays. We don't want unexpected
+ # behaviour, so we force cron to do it on Mondays
+ @timestamp = ("0", "0", "*", "*", "Mon");
+ } elsif ($1 =~ /quarterly/) {
+ @timestamp = ("0", "0", "1,4,7,10", "1", "*");
+ } elsif ($1 =~ /semianually/) {
+ @timestamp = ("0", "0", "1,7", "1", "*")
+ } else {
+ my @sysd_date = split / /, lc $1;
+
+ # Regex which matches the first three letters of
+ # the day of the week
+ my $dotw = "(?|(mon|fri|sun)(?:day)?|(tue)(?:sday)?|(wed)(?:nesday)?|(thu)(?:rsday)?|(sat)(?:urday)?)";
+
+ my @ts_dotw = ("*");
+
+ if ($sysd_date[0] =~ /${dotw}(?:\.\.${dotw})?/i) {
+ @ts_dotw = ();
+ $days = shift @sysd_date;
+ foreach $day (split /,/, $days) {
+ $day =~ m/(${dotw})(?:\.\.(${dotw}))?/;
+ print $2, "\n";
+ push @ts_dotw, (($1 == $2) ? "$1" : "$1-$2");
+ }
+ }
+
+ print @ts_dotw, "\n";
+ $timestamp[4] = join ",", @ts_dotw;
+
+ $date = shift @sysd_date;
+ print $date, "\n";
+ $date =~ m/([0-9]{4}|\*)-([0-9]{1,2}|\*)-([0-9]{1,2}|\*)/;
+ if($1 != "*") {
+ print STDERR "Warning: Ignoring non-'*' year field in timer\n";
+ }
+ $date =~ m/^([0-9]{4}|\*)-([0-9]{1,2}|\*)-([0-9]{1,2}|\*)$/;
+ $timestamp[2] = $2;
+ $timestamp[3] = $3;
+
+ $time = shift @sysd_date;
+ print $time, "\n";
+ $time =~ m/^([0-9]{1,2}):([0-9]{1,2})(?::([0-9]{1,2}))?$/;
+ if(int($3)) {
+ print STDERR "Warning: Ignoring non-zero seconds field in timer\n";
+ }
+ $time =~ m/^([0-9]{1,2}):([0-9]{1,2})(?::([0-9]{1,2}))?$/;
+ $timestamp[0] = $1;
+ $timestamp[1] = $2;
+ print @timestamp, "\n";
+ }
+ push @timestamps, \@timestamp;
+ }
+}
+
+foreach $timestamp (@timestamps) {
+ print join " ", @$timestamp, "\n";
+}
diff --git a/initify.pl b/initify.pl
index 0d84d3a..7cec3d2 100644..100755
--- a/initify.pl
+++ b/initify.pl
@@ -6,6 +6,9 @@ use warnings;
#use strict;
use v5.10.1;
use feature "switch";
+use Getopt::Long;
+use Pod::Usage;
+
my $type = "simple";
my @cmds_start = ();
my @cmds_stop = ();
@@ -13,6 +16,15 @@ my $pidfile = "";
my $desc = "";
(my $service=$ARGV[0])=~s/\.service//;
+my %opt;
+GetOptions(\%opt,
+ "name=s",
+ "help|?") || pod2usage(2);
+
+pod2usage() if ($opt{help});
+
+$service = $opt{name} if (length $opt{name});
+
while(<>) {
#s/\s*|\s*$//g; # Trim whitespace
if (m/^Type\s*=\s*(.*)/) {
@@ -70,3 +82,30 @@ description="$desc"
EOF
close FH;
+
+
+__END__
+
+=head1 NAME
+
+initify - Convert systemd units to OpenRC init-files
+
+=head1 SYNOPSIS
+
+ initify [options] file
+
+=head2 Options
+
+=over 12
+
+=item -h, --help
+
+Print this message
+
+=item -n <name>, --name=<name>
+
+Set the name of the unit created
+
+=back
+
+=cut