postinst is in uswsusp 1.0+20120915-4ubuntu1.
This file is a maintainer script. It is executed when installing (*inst) or removing (*rm) the package.
The actual contents of the file can be viewed below.
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | #!/bin/bash
set -e
# uswsusp.postinst -- postinst script for uswsusp debian package
#
# Copyright 2006, 2007 Tim Dijkstra <tim@famdijkstra.org>
# Copyright 2012 Rodolfo Garc�a Pe�as <kix@kix.es>
# 04-2012 Full rewrited
# Released under GPLv2
. /usr/share/debconf/confmodule
CONFIGNAME=uswsusp.conf
CONFIGFILE=/etc/$CONFIGNAME
SWAPOFFSET=/usr/sbin/swap-offset
LOWQ="snapshot_device compute_checksum compress early_writeout image_size suspend_loglevel max_loglevel"
MEDQ="resume_device encrypt"
HIGHQ=""
NOTQ="RSA_key_file shutdown_method resume_offset"
# If we don't have /proc or /sys we can't work, this will probably
# be a chroot or so.
function check_filesystems
{
mountpoint -q /sys || {
echo "/sys not mounted. Can't create $CONFIGNAME" >> /dev/stderr;
exit 0; }
mountpoint -q /proc || {
echo "/proc not mounted. Can't create $CONFIGNAME" >> /dev/stderr;
exit 0; }
}
check_requirements()
{
# Check if we have swap, else exit.
db_fget uswsusp/no_swap hit
[ "$RET" = "false" ] || exit 0;
# Check if we have /dev/snapshot, else exit.
db_fget uswsusp/no_snapshot hit
[ "$RET" = "false" ] || exit 0;
# Check if filesystems /proc and /sys are mounted
check_filesystems
}
case "$1" in
configure)
# Check requirements to continue
check_requirements
# We skip calculating offset if the user agreed to continue
# without swap
db_fget uswsusp/continue_without_swap hit
if [ "$RET" != "true" ];
then
# swap-offset returns only something for a swap file
# Effectively we're also resetting offset in case of a partition
db_get uswsusp/resume_device
dname=$RET
db_set uswsusp/resume_offset $($SWAPOFFSET $dname 2> /dev/null | cut -c17-)
# We have to translate the devid to a device file.
if [ "$(awk '$1=="'$dname'" {print $2}' /proc/swaps)" == "file" ];
then
if ! devid=$(stat -c "%d" $dname);
then
# It is permissible for swap to be a regular file, which
# is typically not available in a chroot (and this script
# needs to work in chroots too).
echo "The swapfile $dname could not be found, exiting." >&1
exit 0
fi
devnode="/dev/"$(awk '$1=='$(($devid>>8))' && $2=='$(($devid&0x00ff))' {print $4}' /proc/partitions)
# This shouldn't happen that much...
if [ ! -b $devnode ];
then
echo "You have a strange /dev layout." >&1
echo "I couldn't find a node with devid $(($devid>>8)):$(($devid&0x00ff))" >&1
exit 0;
fi
db_set uswsusp/resume_device $devnode
fi
fi
if [ ! -f $CONFIGFILE -o ! -s $CONFIGFILE ];
then
echo "# $CONFIGFILE(5) -- Configuration file for s2disk/s2both " > $CONFIGFILE
fi
TMPFILE=`mktemp`
cp -f $CONFIGFILE $TMPFILE
SEDCMD=""
for I in $MEDQ $LOWQ $HIGHQ $NOTQ; do
db_get uswsusp/$I
VAL=$RET
db_metaget uswsusp/$I type
TYPE=$RET
if [ "boolean" = "$TYPE" ];
then
if [ "$VAL" = "true" ];
then
VAL="y";
else
VAL=
fi
fi
PATRN="^[[:space:]]*${I//_/ }[[:space:]]*[:=]"
# If we didn't got a value, we want the hardcoded default, so del
if [ -z "$VAL" ];
then
SEDCMD="$SEDCMD -e '/$PATRN/ d'"
# Else, rewrite the value
elif eval grep -q -e "'$PATRN'" $CONFIGFILE;
then
SEDCMD="$SEDCMD -e 's/$PATRN.*$/${I//_/ } = ${VAL//\//\\/}/'"
# Or add it
else
SEDCMD="$SEDCMD -e '$ a ${I//_/ } = $VAL'"
fi
done
eval sed $SEDCMD < $CONFIGFILE > $TMPFILE
eval cat $TMPFILE > $CONFIGFILE
eval rm $TMPFILE
db_get uswsusp/create_RSA_key
if [ "$RET" = "true" ]; then
db_get uswsusp/RSA_key_bits
BITS=$RET
db_get uswsusp/RSA_key_file
KEYFILE=$RET
db_get uswsusp/RSA_passphrase
PASS=$RET
if [ -n "$BITS" ] && [ -n "$KEYFILE" ] && [ -n "$PASS" ];
then
echo "Generating RSA key, this may take a while ..."
suspend-keygen <<EOFa &> /dev/null
$BITS
$PASS
$PASS
$KEYFILE
EOFa
else
echo "One of the arguments to suspend-keygen was empty!"
echo "No key generated!"
fi
db_reset uswsusp/RSA_passphrase
db_reset uswsusp/RSA_passphrase_v
fi
if [ -x /usr/sbin/update-initramfs -a -e /etc/initramfs-tools/initramfs.conf ];
then
update-initramfs -u;
fi
# Make snapshot device if they choose /dev/snapshot
db_get uswsusp/snapshot_device
if [ -z "$RET" -a ! -c /dev/snapshot ];
then
if [ -x /dev/MAKEDEV ] ; then
# Until MAKEDEV knows how to make it ...
DEV=`cat /sys/class/misc/snapshot/dev `
(cd /dev; ./MAKEDEV snapshot) || mknod /dev/snapshot c ${DEV%:*} ${DEV#*:}
else
echo "The config file is using snapshot device"
echo "But /dev/MAKEDEV do not exists!"
fi
fi
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
exit 0
|