aboutsummaryrefslogtreecommitdiffstats
path: root/initify.pl
diff options
context:
space:
mode:
authorgoose121 <goose121@users.noreply.github.com>2017-12-09 16:20:51 -0700
committergoose121 <goose121@users.noreply.github.com>2017-12-09 16:22:51 -0700
commit226f71497112b7e1a6395e9770b978ac1e7faf6a (patch)
tree3c009caf254de1e69f2ed22f291f97e0a97778ed /initify.pl
parent8cbed5c5066cd80f36d58024ddec43f37b8ef304 (diff)
parent682d1a6150dcddcda87b5f552c6d08e2da05dc82 (diff)
downloadinitify-226f71497112b7e1a6395e9770b978ac1e7faf6a.tar.lz
initify-226f71497112b7e1a6395e9770b978ac1e7faf6a.tar.xz
initify-226f71497112b7e1a6395e9770b978ac1e7faf6a.zip
Merge pull request #1 from archnous/patch-1
Diffstat (limited to 'initify.pl')
-rwxr-xr-xinitify.pl24
1 files changed, 17 insertions, 7 deletions
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