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.patch41
1 files changed, 32 insertions, 9 deletions
diff --git a/pcr/initify/validate_args.patch b/pcr/initify/validate_args.patch
index 515bff05f..447478268 100644
--- a/pcr/initify/validate_args.patch
+++ b/pcr/initify/validate_args.patch
@@ -1,16 +1,39 @@
diff --git a/initify.pl b/initify.pl
-index 7cec3d2..acbfad3 100755
+index 3d8b1bd..fbfbce8 100755
--- a/initify.pl
+++ b/initify.pl
-@@ -9,6 +9,11 @@ use feature "switch";
- use Getopt::Long;
- use Pod::Usage;
+@@ -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});
-+unless (-e $ARGV[0]) {
-+ print "can not find service file: '$ARGV[0]' - quitting\n";
++# 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;
+}
+
- my $type = "simple";
- my @cmds_start = ();
- my @cmds_stop = ();
++# begin
+ while(<>) {
+ #s/\s*|\s*$//g; # Trim whitespace
+ if (m/^Type\s*=\s*(.*)/) {