summaryrefslogtreecommitdiff
path: root/pcr/initify/validate_args.patch
blob: 4474782684f982bea8bebb30e30ba952017b6f29 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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*(.*)/) {