Updated sysd2v script in contrib directory to version 0.3,
to match latest upstream.
This commit is contained in:
parent
3accc5e30c
commit
e48bfdc5dc
@ -1,5 +1,5 @@
|
||||
#!/bin/sh
|
||||
# sysd2v v0.2 -- systemd unit to sysvinit script converter
|
||||
# sysd2v v0.3 -- systemd unit to sysvinit script converter
|
||||
# Copyright (C) 2019 Trek http://www.trek.eu.org/devel/sysd2v
|
||||
# distributed under the terms of the GNU General Public License 3
|
||||
|
||||
@ -57,8 +57,7 @@ read_unit()
|
||||
tr '[:upper:]' '[:lower:]'
|
||||
)
|
||||
eval ini_$var=\$val
|
||||
# FIXME: only to debug
|
||||
echo "ini_$var=$val" >&2
|
||||
[ -n "$debug" ] && echo "ini_$var=$val" >&2
|
||||
done
|
||||
done
|
||||
|
||||
@ -95,7 +94,7 @@ get_provides ()
|
||||
# read systemd units list and write LSB facilities to stdout
|
||||
# usage: get_depends dependencies [ignores]
|
||||
# dependencies list of required units
|
||||
# ignores units to ignore
|
||||
# ignores facilities to ignore
|
||||
get_depends ()
|
||||
{
|
||||
lst=
|
||||
@ -159,7 +158,40 @@ write_env ()
|
||||
done
|
||||
|
||||
IFS=$oldifs
|
||||
[ -n "$env" ] && echo
|
||||
}
|
||||
|
||||
|
||||
# write an environment variable containing paths
|
||||
# usage: write_path name prefix list
|
||||
# name name of the environment variable
|
||||
# prefix path prefix to append directories
|
||||
# list paths separated by spaces or newlines
|
||||
write_path ()
|
||||
{
|
||||
lst=
|
||||
for dir in $3
|
||||
do
|
||||
lst=${lst:+$lst:}$2/$dir
|
||||
done
|
||||
|
||||
[ -z "$3" ] || printf '%s=%s\n' $1 $lst
|
||||
}
|
||||
|
||||
|
||||
# write a list of directories to be created
|
||||
# usage: write_install prefix list [user [group [mode]]]
|
||||
# prefix path prefix to append directories
|
||||
# list paths separated by spaces or newlines
|
||||
# user user ownership
|
||||
# group group ownership
|
||||
# mode permission mode
|
||||
write_install ()
|
||||
{
|
||||
for dir in $2
|
||||
do
|
||||
printf ' install -d %s%s/%s || return 2\n' \
|
||||
"${3:+-o $3 }${4:+-g $4 }${5:+-m $5 }" "$1" "$dir"
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
@ -287,7 +319,7 @@ write_init ()
|
||||
start_args="$start_args --background"
|
||||
[ -z "$pidfile" -a "$ini_service_killmode" != none ] &&
|
||||
start_args="$start_args --make-pidfile" &&
|
||||
pidfile="/run/$name-sysd2v.pid"
|
||||
pidfile="/var/run/$name-sysd2v.pid"
|
||||
fi
|
||||
|
||||
if [ "$service_type" = notify ]
|
||||
@ -313,6 +345,15 @@ write_init ()
|
||||
limitnofile=$ini_service_limitnofile
|
||||
[ "$limitnofile" = infinity ] && limitnofile=unlimited
|
||||
|
||||
need_install=$ini_service_runtimedirectory
|
||||
need_install=$need_install$ini_service_statedirectory
|
||||
need_install=$need_install$ini_service_cachedirectory
|
||||
need_install=$need_install$ini_service_logsdirectory
|
||||
need_install=$need_install$ini_service_configurationdirectory
|
||||
|
||||
need_do_start=$ini_service_execstartpre$ini_service_execstartpost
|
||||
need_do_start=$need_do_start$need_install
|
||||
|
||||
execstop=$ini_service_execstop
|
||||
|
||||
if [ "$service_type" != oneshot ]
|
||||
@ -332,8 +373,7 @@ write_init ()
|
||||
fi
|
||||
|
||||
# TODO: test if already running before start (pretest="+do_status_cmd")
|
||||
[ -n "$ini_service_execstartpre$ini_service_execstartpost" -o \
|
||||
-z "$errcheck" ] &&
|
||||
[ -n "$need_do_start" -o -z "$errcheck" ] &&
|
||||
execstart="-+do_start_cmd$errcheck"
|
||||
|
||||
errcheck=' || return $?'
|
||||
@ -353,6 +393,7 @@ write_init ()
|
||||
runstart=$run
|
||||
fi
|
||||
|
||||
need_do_start=$need_do_start$execstart
|
||||
start_args=${start_args# }
|
||||
stop_args=${stop_args# }
|
||||
|
||||
@ -377,7 +418,7 @@ write_init ()
|
||||
|
||||
cat <<EOF
|
||||
#!/bin/sh
|
||||
# Generated by sysd2v v0.2 -- http://www.trek.eu.org/devel/sysd2v
|
||||
# Generated by sysd2v v0.3 -- http://www.trek.eu.org/devel/sysd2v
|
||||
# kFreeBSD do not accept scripts as interpreters, using #!/bin/sh and sourcing.
|
||||
if [ true != "\$INIT_D_SCRIPT_SOURCED" ] ; then
|
||||
set "\$0" "\$@"; INIT_D_SCRIPT_SOURCED=true . /lib/init/init-d-script
|
||||
@ -396,7 +437,19 @@ ${default_stop:+# X-Stop-After: $start_before
|
||||
### END INIT INFO
|
||||
EOF
|
||||
|
||||
write_env "$ini_service_environmentfile"
|
||||
if [ -n "$ini_service_environment$ini_service_environmentfile$need_install" ]
|
||||
then
|
||||
echo set -a
|
||||
write_path RUNTIME_DIRECTORY /run "$ini_service_runtimedirectory"
|
||||
write_path STATE_DIRECTORY /var/lib "$ini_service_statedirectory"
|
||||
write_path CACHE_DIRECTORY /var/cache "$ini_service_cachedirectory"
|
||||
write_path LOGS_DIRECTORY /var/log "$ini_service_logsdirectory"
|
||||
write_path CONFIGURATION_DIRECTORY /etc \
|
||||
"$ini_service_configurationdirectory"
|
||||
printf '%s' "${ini_service_environment:+$ini_service_environment$nl}"
|
||||
write_env "$ini_service_environmentfile"
|
||||
printf 'set +a\n\n'
|
||||
fi
|
||||
|
||||
cat <<EOF
|
||||
${name:+DESC=\"$name\"
|
||||
@ -410,9 +463,23 @@ ${daemon_args:+DAEMON_ARGS=\"$daemon_args\"
|
||||
}
|
||||
EOF
|
||||
|
||||
if [ -n "$ini_service_execstartpre$execstart$ini_service_execstartpost" ]
|
||||
if [ -n "$need_do_start" ]
|
||||
then
|
||||
{
|
||||
write_install /run "$ini_service_runtimedirectory" \
|
||||
"$ini_service_user" "$ini_service_group" \
|
||||
"$ini_service_runtimedirectorymode"
|
||||
write_install /var/lib "$ini_service_statedirectory" \
|
||||
"$ini_service_user" "$ini_service_group" \
|
||||
"$ini_service_statedirectorymode"
|
||||
write_install /var/cache "$ini_service_cachedirectory" \
|
||||
"$ini_service_user" "$ini_service_group" \
|
||||
"$ini_service_cachedirectorymode"
|
||||
write_install /var/log "$ini_service_logsdirectory" \
|
||||
"$ini_service_user" "$ini_service_group" \
|
||||
"$ini_service_logsdirectorymode"
|
||||
write_install /etc "$ini_service_configurationdirectory" '' '' \
|
||||
"$ini_service_configurationdirectorymode"
|
||||
write_commands "$chdir"
|
||||
write_commands "$ini_service_execstartpre" "$run" "$runpriv"
|
||||
write_commands "$execstart" "$runstart" "$runprivstart"
|
||||
@ -462,12 +529,14 @@ EOF
|
||||
|
||||
|
||||
# parse command line
|
||||
while getopts i:n: opt
|
||||
while getopts di:n: opt
|
||||
do
|
||||
case $opt in
|
||||
d) debug=1;;
|
||||
i) instance=$OPTARG;;
|
||||
n) name=$OPTARG;;
|
||||
?) printf "Usage: %s [-i instance] [-n servicename] [filename]\n" "$0"
|
||||
?) printf "Usage: %s [-d] [-i instance] [-n servicename] [filename]\n" \
|
||||
"$0"
|
||||
exit 2;;
|
||||
esac
|
||||
done
|
||||
|
Loading…
Reference in New Issue
Block a user