File: update_init_d.sh

package info (click to toggle)
orphan-sysvinit-scripts 0.21
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 220 kB
  • sloc: sh: 1,498; makefile: 5
file content (52 lines) | stat: -rwxr-xr-x 1,699 bytes parent folder | download | duplicates (2)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
# Script to update contents of /etc/init.d/ with scripts from
# /usr/share/orphan-sysvinit-scripts.
# This should be called automatically by dpkg
# If $1 is --purge, removes everything, otherwise will add
# scripts corresponding to installed service files.

set -e

if [ -z "$1" ]; then
    action=add
elif [ "$1" = "--purge" ]; then
    action=purge
else
    echo "update_init_d.sh: Error: only allowed argument is --purge"
    exit 1
fi

while read -r systemd sysv rcd rest ; do
    #Comment lines
    if [[ $systemd =~ ^# ]]; then
	continue
    fi
    if [ -n "$rest" ]; then
	echo "Unable to parse line: $systemd $sysv $rcd $rest"
	exit 1
    fi
    if [ -e "/lib/systemd/system/$systemd" ] && [ "$action" = "add" ]; then
	if dpkg-query -S "/etc/init.d/$sysv" >/dev/null 2>&1 ; then
	    # This file still belongs to an installed package
	    # so do nothing for now
	    continue
	fi
	ucf "/usr/share/orphan-sysvinit-scripts/$sysv" "/etc/init.d/$sysv"
	ucfr orphan-sysvinit-scripts "/etc/init.d/$sysv"
	update-rc.d "$sysv" "${rcd:-defaults}" >/dev/null
    elif [ -e "/etc/init.d/$sysv" ] && [ "$action" = "purge" ]; then
	#Only remove scripts if we are reasonably sure we have previously
	#registered them with ucf (to minimise user surprise)
	if which ucfq >/dev/null; then
	    if ucfq "/etc/init.d/$sysv" | grep -q orphan-sysvinit-scripts ; then
		for ext in '~' '%' .bak .ucf-new .ucf-old .ucf-dist; do
		    rm -f "/etc/init.d/${sysv}.$ext"
		done
		rm -f "/etc/init.d/$sysv"
		ucf --purge "/etc/init.d/$sysv"
		ucfr --purge orphan-sysvinit-scripts "/etc/init.d/$sysv"
		update-rc.d "$sysv" remove >/dev/null
	    fi
	fi
    fi
done < /usr/lib/orphan-sysvinit-scripts/mapping