From 490e0df91b0d82dc54aa94e1abdcad686952b4db Mon Sep 17 00:00:00 2001 From: goose121 Date: Wed, 6 Dec 2017 13:45:41 -0700 Subject: Initial commit --- initify.pl | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 initify.pl diff --git a/initify.pl b/initify.pl new file mode 100644 index 0000000..104d252 --- /dev/null +++ b/initify.pl @@ -0,0 +1,61 @@ +use v5.10.1; +use feature "switch"; +my $type = "simple"; +my @cmds_start = (); +my @cmds_stop = (); +my $pidfile = ""; +my $desc = ""; + +while(<>) { + #s/\s*|\s*$//g; # Trim whitespace + if (m/^Type\s*=\s*(.*)/) { + $type=$1; + } + if (m/^ExecStart\s*=\s*(.*)/) { + if (length $1) { + push(@cmds_start, $1); + } + else { + @cmds_start = (); # If the line is "ExecStart=", + # it means to clear ExecStart. + } + } + if (m/^ExecStop\s*=\s*(.*)/) { + if (length $1) { + push(@cmds_stop, $1); + } + else { + @cmds_stop = (); # If the line is "ExecStop=", + # it means to clear ExecStop. + } + } + if (m/^PIDFile=(.*)/) { + if(length $1) { + $pidfile = $1; + } + } + if (m/^Description=(.*)/) { + $desc = $1 + } +} + +my @cmds; + +my @cmd_path; +my @cmd_argl; + +map {my @sep = split(/ /, $_, 2); + push(@cmd_path, $sep[0]); + push(@cmd_argl, $sep[1]); +} @cmds_start; + +print <<"EOF"; +\#!/sbin/openrc-run + +command=$cmd_path[0] +command_args="$cmd_argl[0]" +pidfile=$pidfile + +name="(fill in)" +description="$desc" +EOF -- cgit v1.2.3