aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--LICENSE21
-rw-r--r--README.md13
-rwxr-xr-xinitify.pl24
3 files changed, 51 insertions, 7 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..1f49021
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2017 goose121
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..c7d2cef
--- /dev/null
+++ b/README.md
@@ -0,0 +1,13 @@
+# initify
+This utility converts simple systemd services to OpenRC init-scripts.
+
+## Usage
+ initify.pl [filename]
+
+NOTE: The service name will initially be `(fill in)`. This is due to the ability to pipe service-files from `stdin`, as well
+as the lack of a service-name field in systemd services.
+
+## TODO
+
+- Handle the targets which directly map to OpenRC runlevels
+- Convert systemd timers to crontab entries
diff --git a/initify.pl b/initify.pl
index 1c9f8b2..7cec3d2 100755
--- a/initify.pl
+++ b/initify.pl
@@ -1,15 +1,20 @@
-#!/bin/env perl
+#!/usr/bin/perl
+# (c) goose121, 2017
+# Released under the MIT license
+
+use warnings;
+#use strict;
use v5.10.1;
use feature "switch";
use Getopt::Long;
use Pod::Usage;
-my $name = "(fill in)";
my $type = "simple";
my @cmds_start = ();
my @cmds_stop = ();
my $pidfile = "";
my $desc = "";
+(my $service=$ARGV[0])=~s/\.service//;
my %opt;
GetOptions(\%opt,
@@ -18,7 +23,7 @@ GetOptions(\%opt,
pod2usage() if ($opt{help});
-$name = $opt{name} if (length $opt{name});
+$service = $opt{name} if (length $opt{name});
while(<>) {
#s/\s*|\s*$//g; # Trim whitespace
@@ -49,7 +54,7 @@ while(<>) {
}
}
if (m/^Description=(.*)/) {
- $desc = $1
+ $desc = $1
}
}
@@ -63,17 +68,22 @@ map {my @sep = split(/ /, $_, 2);
push(@cmd_argl, $sep[1]);
} @cmds_start;
-print <<"EOF";
+open(FH, '>', "$service") || die("Cannot create $service: $!\n");
+
+print FH <<"EOF";
\#!/sbin/openrc-run
command=$cmd_path[0]
command_args="$cmd_argl[0]"
pidfile=$pidfile
-name="$name"
+name="$service"
description="$desc"
EOF
+close FH;
+
+
__END__
=head1 NAME
@@ -98,4 +108,4 @@ Set the name of the unit created
=back
-=cut \ No newline at end of file
+=cut