DEBIAN SCRIPTS
8.8.2926

PREINST

#!/usr/bin/bash

# Ubuntu preinstall
# backup the header, database and cbb.config if any of these exists already
if [ -r /usr/lib/cryptobone/safewebdrop.header ] ; then
     /usr/bin/cp /usr/lib/cryptobone/safewebdrop.header /usr/lib/cryptobone/header.backup
fi     
if [ -r /usr/lib/cryptobone/database ] ; then
     /usr/bin/cp /usr/lib/cryptobone/database /usr/lib/cryptobone/database.backup
fi     
if [ -r /usr/lib/cryptobone/cbb.config ] ; then
     /usr/bin/cp /usr/lib/cryptobone/cbb.config /usr/lib/cryptobone/cbb.config.backup
fi

exit 0




PRERM

#!/usr/bin/bash

# Ubuntu prerm (no parameters)
# removal only, not running before update, but before install
# stop running daemons

systemctl stop cryptoboned
systemctl stop cryptoboneexternd
systemctl stop cryptobone-fetch.timer

# make bootswitch removable
if [ -f /usr/lib/cryptobone/bootswitch ] ; then
     chattr -i /usr/lib/cryptobone/bootswitch
     rm -f /usr/lib/cryptobone/bootswitch 2> /dev/null
fi

exit 0



POSTRM

#!/bin/bash

# Ubuntu postremove
# called with $1 == "purge" or $1 == "remove" after files are removed

if [[ "$1" = "purge" ]] ; then
     echo "PURGING all sensitive information"

     if [ -f /usr/lib/cryptobone/bootswitch ] ; then
          chattr -i /usr/lib/cryptobone/bootswitch
          /usr/bin/rm -f /usr/lib/cryptobone/bootswitch 2> /dev/null
     fi

     # remove all messages from the ramdisks
     /usr/bin/rm -rf /dev/shm/RAM 2>/dev/null
     /usr/bin/rm -rf /dev/shm/EXRAM 2>/dev/null
 
     if grep cryptobone /etc/passwd >/dev/null 2>/dev/null; then
            /usr/sbin/userdel cryptobone
     fi

     # umount the keys directory
     /usr/bin/umount /usr/lib/cryptobone/keys 2> /dev/null
     # delete all config files in main cryptobone directories

     /usr/bin/rm -rf /usr/lib/cryptobone/keys/* 2> /dev/null
     /usr/bin/rm -rf /usr/lib/cryptobone/cryptobone 2> /dev/null
     /usr/bin/rm -f /usr/lib/cryptobone/database* 2> /dev/null
     /usr/bin/rm -f /usr/lib/cryptobone/cbb.config 2> /dev/null
     /usr/bin/rm -f /usr/lib/cryptobone/keys.tgz 2> /dev/null
     /usr/bin/rm -f /usr/lib/cryptobone/masterkey 2> /dev/null
     /usr/bin/rm -f /usr/lib/cryptobone/pinghost 2> /dev/null
     /usr/bin/rm -f /usr/lib/cryptobone/safewebdrop/p* 2> /dev/null
     /usr/bin/rm -f /usr/lib/cryptobone/ext/masterkey 2> /dev/null
     /usr/bin/rm -f /usr/lib/cryptobone/ext/database* 2> /dev/null
     /usr/bin/rm -f /usr/lib/cryptobone/ext/safewebdrop/p* 2> /dev/null
     /usr/bin/rm -rf /usr/lib/cryptobone/ext/cryptobone 2> /dev/null
     /usr/bin/rm -f /usr/lib/cryptobone/ext/*.hash 2> /dev/null
     /usr/bin/rm -rf /usr/lib/cryptobone/cltls 2> /dev/null
     /usr/bin/rm -rf /usr/lib/cryptobone/ext/cltls 2> /dev/null

     # remove the sudo file
     /usr/bin/rm -f /etc/sudoers.d/cbcontrol 2> /dev/null
     # disable all daemons
     /usr/bin/systemctl disable cryptoboned 2> /dev/null
     /usr/bin/systemctl disable cryptoboneexternd 2> /dev/null
     /usr/bin/systemctl disable cryptobone-fetch.timer 2> /dev/null
fi

/usr/bin/touch --no-create /usr/share/icons/default &>/dev/null
/usr/bin/gtk-update-icon-cache /usr/share/icons/default &>/dev/null  || :

exit 0



POSTINST

#!/usr/bin/bash

# Ubuntu postinstall 
chmod 700 /usr/lib/cryptobone ;
chmod 700 /usr/lib/cryptobone/bin ;
chmod 700 /usr/lib/cryptobone/cryptobone ;
chmod 700 /usr/lib/cryptobone/cryptoboned ;
chmod 700 /usr/lib/cryptobone/keys ;
chmod 700 /usr/lib/cryptobone/ext ;
chmod 700 /usr/lib/cryptobone/cbcontrol ;
chmod 700 /usr/lib/cryptobone/cbcontrol.functions ;
chmod 700 /usr/lib/cryptobone/check* ;
chmod 700 /usr/lib/cryptobone/createmasterkey ;
chmod 700 /usr/lib/cryptobone/initdatabase ;
chmod 700 /usr/lib/cryptobone/get*;
chmod 700 /usr/lib/cryptobone/rc.local ;
chmod 700 /usr/lib/cryptobone/safewebdrop ;
chmod 700 /usr/lib/cryptobone/safewebdrop/bin/* ;
chmod 700 /usr/lib/cryptobone/systemd.fetch ;
chmod 700 /usr/lib/cryptobone/init.d ;
chmod 700 /usr/lib/cryptobone/init.d/cryptoboned ;
chmod 700 /usr/lib/cryptobone/ext/bin ;
chmod 700 /usr/lib/cryptobone/ext/cbcontrol ;
chmod 700 /usr/lib/cryptobone/ext/cbcontrol.functions ;
chmod 700 /usr/lib/cryptobone/ext/cryptoboneshell ;
chmod 700 /usr/lib/cryptobone/ext/cryptoboneexternd ;
chmod 700 /usr/lib/cryptobone/ext/firewall ;
chmod 700 /usr/lib/cryptobone/ext/initialkeysetup ;
chmod 700 /usr/lib/cryptobone/ext/destroy ;
chmod 700 /usr/lib/cryptobone/ext/rc.local ;
chmod 700 /usr/lib/cryptobone/ext/init.d ;
chmod 700 /usr/lib/cryptobone/ext/init.d/cryptoboneexternd ;

# restore the header, cbb.config and database if it was backed up 
if [ -r /usr/lib/cryptobone/header.backup ] ; then
     /usr/bin/mv /usr/lib/cryptobone/header.backup /usr/lib/cryptobone/safewebdrop.header
fi	
if [ -r /usr/lib/cryptobone/database.backup ] ; then
     /usr/bin/mv /usr/lib/cryptobone/database.backup /usr/lib/cryptobone/database
fi
if [ -r /usr/lib/cryptobone/cbb.config.backup ] ; then
     /usr/bin/mv /usr/lib/cryptobone/cbb.config.backup /usr/lib/cryptobone/cbb.config
fi


exit 0
