From 53c3fd2ff7a839de1535a3168584a7f36b4a02c6 Mon Sep 17 00:00:00 2001 From: nous Date: Fri, 8 Dec 2017 23:54:35 +0200 Subject: Guess script name from systemd service filename Also, write straight to file instead of stdout --- initify.pl | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/initify.pl b/initify.pl index 3aa6960..0d84d3a 100644 --- a/initify.pl +++ b/initify.pl @@ -1,6 +1,9 @@ +#!/usr/bin/perl # (c) goose121, 2017 # Released under the MIT license +use warnings; +#use strict; use v5.10.1; use feature "switch"; my $type = "simple"; @@ -8,6 +11,7 @@ my @cmds_start = (); my @cmds_stop = (); my $pidfile = ""; my $desc = ""; +(my $service=$ARGV[0])=~s/\.service//; while(<>) { #s/\s*|\s*$//g; # Trim whitespace @@ -38,7 +42,7 @@ while(<>) { } } if (m/^Description=(.*)/) { - $desc = $1 + $desc = $1 } } @@ -52,13 +56,17 @@ 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="(fill in)" +name="$service" description="$desc" EOF + +close FH; -- cgit v1.2.3