Debian Codegraph @

lib/fai-divert

raw
1 #! /bin/bash
2
3 #*********************************************************************
4 #
5 # fai-divert -- add or remove a diversion for fai
6 #
7 # This script is part of FAI (Fully Automatic Installation)
8 # (c) 2002-2007 by Thomas Lange, [email protected]
9 # Universitaet zu Koeln
10 #
11 #*********************************************************************
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2 of the License, or
15 # (at your option) any later version.
16 #
17 # This program is distributed in the hope that it will be useful, but
18 # WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 # General Public License for more details.
21 #
22 # A copy of the GNU General Public License is available as
23 # `/usr/share/common-licences/GPL' in the Debian GNU/Linux distribution
24 # or on the World Wide Web at http://www.gnu.org/copyleft/gpl.html. You
25 # can also obtain it by writing to the Free Software Foundation, Inc.,
26 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
27 #*********************************************************************
28
29 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
30 mkdivert() {
31
32 # make a diversion of a file
33 [ "$debug" ] || local divertquiet=--quiet
34 $ROOTCMD dpkg-divert $divertquiet --package fai --rename --add $1 &&
35 cat > $FAI_ROOT/$1 <<-EOF
36 #! /bin/sh
37 # diversion of $1 created by FAI
38 exit 0
39 EOF
40 chmod a+rx $FAI_ROOT/$1
41 }
42 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
43 adddivert() {
44
45 # add an executable to the list of diversions
46 local item
47 for item in "$@"; do
48 mkdivert $item
49 done
50 }
51 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
52 rmdivert() {
53
54 # remove diversion
55 [ "$debug" ] || local divertquiet=--quiet
56 rm -f $FAI_ROOT/$1
57 $ROOTCMD dpkg-divert $divertquiet --package fai --rename --remove $1
58 # when a diversion was made before the file exists
59 [ -f $FAI_ROOT/$1.distrib.dpkg-new ] && mv $FAI_ROOT/$1.distrib.dpkg-new $FAI_ROOT/$1
60 }
61 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
62 rmalldivert() {
63
64 # remove all diversions made by fai
65 local item
66 for item in $($ROOTCMD dpkg-divert --list fai | awk '{ print $3 }'); do
67 rmdivert $item
68 done
69 }
70 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
71 usage() {
72
73 cat <<EOF
74 fai-divert, add or remove a diversion for fai.
75
76 Copyright (C) 2002-2024 by Thomas Lange
77
78 Usage: fai-divert [OPTION] ... FILE
79
80 -a FILE ... Replace each file by a dummy script.
81 -R Remove all diversion made by fai.
82 -r FILE Remove a diversion.
83 -v Be verbose.
84
85 Report bugs to <[email protected]>.
86 EOF
87 exit 0
88 }
89
90 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
91
92 [ "$1" ] || usage
93
94 # do not execute if command is not available
95 if [ ! -f $FAI_ROOT/usr/bin/dpkg-divert ]; then
96 exit 0
97 fi
98
99 while getopts arRhv opt ; do
100 case "$opt" in
101 v) verbose=1 ;;
102 R) rmalldivert ;;
103 r) shift ; rmdivert $1 ;;
104 a) shift ; adddivert $@ ;;
105 h) usage ;;
106 esac
107 done
108