summaryrefslogtreecommitdiff
path: root/pcr/initify/validate_args.patch
diff options
context:
space:
mode:
Diffstat (limited to 'pcr/initify/validate_args.patch')
-rw-r--r--pcr/initify/validate_args.patch39
1 files changed, 39 insertions, 0 deletions
diff --git a/pcr/initify/validate_args.patch b/pcr/initify/validate_args.patch
new file mode 100644
index 000000000..447478268
--- /dev/null
+++ b/pcr/initify/validate_args.patch
@@ -0,0 +1,39 @@
+diff --git a/initify.pl b/initify.pl
+index 3d8b1bd..fbfbce8 100755
+--- a/initify.pl
++++ b/initify.pl
+@@ -14,18 +14,31 @@ my @cmds_start = ();
+ my @cmds_stop = ();
+ my $pidfile = "";
+ my $desc = "";
+-(my $service = $ARGV[0]) =~ s/\.service//;
+-(my $svc_name = $ARGV[0]) =~ s|(.*/)?([^/.]*)\.service|$2|;
+
++# parse CLI args
+ my %opt;
+ GetOptions(\%opt,
+ "name=s",
+ "help|?") || pod2usage(2);
+-
+ pod2usage() if ($opt{help});
+
++# get systemd service source file, and target service name
++(my $service = $ARGV[0])=~s/\.service//;
++(my $svc_name = $ARGV[0])=~s|(.*/)?([^/.]*)\.service|$2|;
+ $svc_name = $opt{name} if (length $opt{name});
+
++# sanity checks
++my $USAGE = "Usage: initify [options] some-systemd.service";
++unless ($ARGV[0] =~ /(.*\/)?([^\/.]*)\.service/) {
++ print "no *.service file specified - quitting\n$USAGE\n";
++ exit;
++}
++unless (-e "$ARGV[0]") {
++ print "can not find *.service file: '$ARGV[0]' - quitting\n$USAGE\n";
++ exit;
++}
++
++# begin
+ while(<>) {
+ #s/\s*|\s*$//g; # Trim whitespace
+ if (m/^Type\s*=\s*(.*)/) {