1 # by ddzeko & ico, Fri, 18 Mar 2005 14:44:08 +0100
3 [ "$CP_SCRIPT_DEBUG" ] && set -vx
7 [ -z "$interface" ] && interface=lo
9 if ! ifconfig $interface 2> /dev/null >> /dev/null; then
10 [ -z "$CP_ECHO_RETURN" ] || echo "cp_get_ifaddr: $interface: No such interface"
14 ifaddr="`/sbin/ifconfig $interface | awk '/inet/{ printf("%s\n",substr($2,index($2,":")+1)) }'`"
16 if [ -z $ifaddr ]; then
17 [ -z "$CP_ECHO_RETURN" ] || echo "cp_get_ifaddr: $interface: No such ipaddress"
22 [ -z "$CP_ECHO_RETURN" ] || echo $RET
25 # by ddzeko & ico, Fri, 18 Mar 2005 14:44:08 +0100
27 [ "$CP_SCRIPT_DEBUG" ] && set -vx
28 local ifmask interface
31 [ -z "$interface" ] && interface=lo
33 if ! ifconfig $interface 2> /dev/null >> /dev/null; then
34 [ -z "$CP_ECHO_RETURN" ] || echo "cp_get_ifmask: $interface: No such interface"
38 ifmask="`/sbin/ifconfig $interface | awk '/Mask/{if($3~/Mask/)a=$3;else if ($4~/Mask/)a=$4;printf ("%s\n", substr(a,index(a,":")+1))}'`"
40 if [ -z "$ifmask" ]; then
41 [ -z "$CP_ECHO_RETURN" ] || echo "cp_get_ifmask: $interface: No such netmask"
46 [ -z "$CP_ECHO_RETURN" ] || echo $RET
49 # by ddzeko, Mon, 21 Mar 2005 07:00:22 +0100
51 [ "$CP_SCRIPT_DEBUG" ] && set -vx
54 dev) RET=`route -n | awk '/^0.0.0.0/{print $8}'` ;;
55 addr) RET=`route -n | awk '/^0.0.0.0/{print $2}'` ;;
56 *) echo "cp_get_ifdefault: Argument required (dev or addr)" >&2 ;;
58 [ -z "$RET" -a "$1" -a "$CP_VERBOSE" ] && echo "cp_get_ifdefault: No default route" >&2
59 [ -z "$CP_ECHO_RETURN" ] || echo $RET
60 [ -z "$RET" ] && return 1
63 # by ico, Tue, 15 Mar 2005 14:04:21 +0100
65 [ "$CP_SCRIPT_DEBUG" ] && set -vx
66 local netmask ipaddress interface cidr echo_return
67 echo_return="$CP_ECHO_RETURN" # since we're making our own calls
68 # in our own way we need to set CP_ECHO_RETURN the way we want it
69 # but preserving initial state so it could be used afterwards
73 if [ -z "$interface" ]; then
76 [ -z "$interface" ] && interface=lo
79 if ! ifconfig $interface 2> /dev/null >> /dev/null; then
80 [ "$CP_VERBOSE" ] || echo "cp_get_cidr: $interface: No such interface"
84 cp_get_ifaddr "$interface"
86 if [ -z $ipaddress ]; then
87 [ "$CP_VERBOSE" ] || echo "cp_get_cidr: $interface: No such ipaddress"
90 cp_get_ifmask "$interface"
92 if [ -z $netmask ]; then
93 [ "$CP_VERBOSE" ] || echo "cp_get_cidr: $interface: No such netmask"
96 if [ "$netmask" = "255.255.255.255" ]; then
99 cidr="`ipcalc -ncb $ipaddress $netmask | awk '/^Network:/{print $2}'`"
103 [ -z "$echo_return" ] || echo $RET
104 CP_ECHO_RETURN="$echo_return"
108 CP_ECHO_RETURN="$echo_return"
112 # by ico, Tue, 15 Mar 2005 14:04:21 +0100
113 cp_backup_conffile() {
114 [ "$DEBIAN_SCRIPT_DEBUG" ] && set -vx
118 [ -z "$CP_ECHO_RETURN" ] || echo "Usage: cp_backup_conffile <file>"
122 [ -z "$CP_ECHO_RETURN" ] || echo "cp_backup_conffile: $1: No such file"
126 file_bak="/var/backups/`basename $1`.bak"
128 if [ ! -f $file_bak ]; then
131 if ! cmp -s $1 $file_bak; then
132 /usr/bin/savelog -p -c 7 $file_bak > /dev/null 2> /dev/null
138 # by jelly, Tue, 15 Mar 2005 14:04:21 +0100
139 # A sed wrapper, to use instead of perl -pi -e
140 # - relatively safe in-place s///g
141 # - takes care of symlinks and ownership
142 # returns true if changed, false if nothing happened
145 [ "$CP_SCRIPT_DEBUG" ] && set -vx
154 [ -e "$i" ] || continue
155 egrep -q "$s" "$i" || continue
156 [ -h "$i" ] && i=$(readlink -f "$i")
157 sed "$sedcmd" "$i" > "$i.dpkg-tmp"
158 if ! cmp -s "$i" "$i.dpkg-tmp"; then
159 chown --reference "$i" "$i.dpkg-tmp"
160 chmod --reference "$i" "$i.dpkg-tmp"
161 mv "$i.dpkg-tmp" "$i"
170 # by jelly, Sun, 20 Mar 2005 20:12:19 +0100
172 [ "$CP_SCRIPT_DEBUG" ] && set -vx
173 if [ "x$1" = "x-mailonly" -o "x$1" = "x-m" ]; then
178 CP_NOTICE="$CP_NOTICE$1"
179 if [ `echo -n "$*" | wc -l` -eq 0 ]; then
180 CP_NOTICE="$CP_NOTICE
185 # by jelly, Sun, 20 Mar 2005 20:12:19 +0100
187 [ "$CP_SCRIPT_DEBUG" ] && set -vx
188 local pkg version quiet
189 if [ "x$1" = "x-q" ]; then
193 [ -n "$1" ] && pkg="$1" # barf if no package
194 [ -n "$2" ] && version=" $2" || true
195 if [ "$(echo $CP_NOTICE|wc -w)" -gt 0 ]; then
196 [ -n "$quiet" ] || echo "Mailing upgrade output to root."
197 CP_NOTICE="From: $pkg postinst script <root>
199 Subject: $pkg$version package install log
200 Date: $(/bin/date +'%a, %d %b %Y %H:%M:%S %z')
204 The $pkg package has been successfully installed on your computer.
205 For your convenience, a partial output of the last $pkg installation
209 ${CP_NOTICE}----------"
211 echo "$CP_NOTICE" | /usr/sbin/sendmail -t &