Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate

Advertising

Unnamed
Tuesday, May 29th, 2007 at 10:00:19pm UTC 

  1. #! /bin/sh
  2. # postinst script for boxbackup-server
  3. #
  4. # see: dh_installdeb(1)
  5.  
  6. set -e
  7.  
  8. # summary of how this script can be called:
  9. #        * <postinst> `configure' <most-recently-configured-version>
  10. #        * <old-postinst> `abort-upgrade' <new version>
  11. #        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
  12. #          <new-version>
  13. #        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
  14. #          <failed-install-package> <version> `removing'
  15. #          <conflicting-package> <version>
  16. # for details, see http://www.debian.org/doc/debian-policy/ or
  17. # the debian-policy package
  18. #
  19. # quoting from the policy:
  20. #     Any necessary prompting should almost always be confined to the
  21. #     post-installation script, and should be protected with a conditional
  22. #     so that unnecessary prompting doesn't happen if a package's
  23. #     installation fails and the `postinst' is called with `abort-upgrade',
  24. #     `abort-remove' or `abort-deconfigure'.
  25.  
  26. #loading debconf module
  27. . /usr/share/debconf/confmodule
  28.  
  29. CONFDIR=/etc/boxbackup
  30. DEBCONFRAID=$CONFDIR/raidfile.debconf
  31. DEBCONFBB=$CONFDIR/bbstored.debconf
  32. RAIDCONF=$CONFDIR/raidfile.conf
  33. BBCONF=$CONFDIR/bbstored.conf
  34. BBACCOUNTS=$CONFDIR/bbstored/boxbackup-server-accounts.txt
  35. BBUSER=bbstored
  36. BBPRIVKEY=$CONFDIR/bbstored/boxbackup-server-key.pem
  37. BBCERTREQ=$CONFDIR/bbstored/boxbackup-server-cert-req.pem
  38. BBCERT=$CONFDIR/bbstored/boxbackup-server-cert.pem
  39. BBCACERT=$CONFDIR/bbstored/boxbackup-client-ca-cert.pem
  40.  
  41. case "$1" in
  42.     configure)
  43.  
  44.         # Set up the bbstored user
  45.         if [ -z "`getent passwd $BBUSER`" ]; then
  46.                 echo "Creating $BBUSER user." >&2
  47.                 adduser --system --no-create-home \
  48.                         --disabled-password --disabled-login \
  49.                         --shell /bin/false --group --home /var $BBUSER
  50.         else
  51.                 echo "User $BBUSER already exists." >&2
  52.         fi
  53.  
  54.         db_get boxbackup-server/debconf
  55.         if [ "$RET" = "true" ]; then
  56.             # Generate configuration files
  57.             # raidfile.conf
  58.             echo "#To reconfigure boxbackup-server run #dpkg-reconfigure boxbackup-server" >> $DEBCONFRAID
  59.  
  60.             echo "disc0" >> $DEBCONFRAID
  61.             echo "{" >> $DEBCONFRAID
  62.             echo "      SetNumber = 0" >> $DEBCONFRAID
  63.  
  64.             db_get boxbackup-server/raidBlockSize
  65.             echo "      BlockSize = $RET" >> $DEBCONFRAID
  66.  
  67.             db_get boxbackup-server/raidDirectories
  68.  
  69.             DIR1=`echo "$RET" | awk '{ print $1 }'`
  70.             DIR2=`echo "$RET" | awk '{ print $2 }'`
  71.             DIR3=`echo "$RET" | awk '{ print $3 }'`
  72.  
  73.             if [ -n $DIR1 ]; then
  74.                 if [ -z $DIR2 -o -z $DIR3 ]; then
  75.                     DIR2=$DIR1
  76.                     DIR3=$DIR1
  77.                 fi
  78.             fi
  79.  
  80.             echo "      Dir0 = $DIR1" >> $DEBCONFRAID
  81.             echo "      Dir1 = $DIR2" >> $DEBCONFRAID
  82.             echo "      Dir2 = $DIR3" >> $DEBCONFRAID
  83.  
  84.             echo "}" >> $DEBCONFRAID
  85.  
  86.             # Handle backup directories creation/permissions
  87.             for dir in "$DIR1" "$DIR2" "$DIR3"; do
  88.                 if [ -d "$dir/backup" ]; then
  89.                     # need stat package on Woody
  90.                     #if (`stat -c %U $dir/backup` != $BBUSER); then
  91.                     if [ `ls -ld $dir/backup | awk '{ print $3 }'` != "$BBUSER" ]; then
  92.                         echo "Incorrect owner of backup directory. Changing it to $BBUSER..." >&2
  93.                         chown $BBUSER:$BBUSER $dir/backup
  94.                     fi
  95.  
  96.                     #if [ `stat -c %a $dir/backup` != "700" ]; then
  97.                     if [ `ls -ld $dir/backup | awk '{ print $1 }'` != "drwx------" ]; then
  98.                         chmod 700 $dir/backup
  99.                     fi
  100.                 else
  101.                     echo "Creating $dir/backup directory..." >&2
  102.                     mkdir -p $dir/backup
  103.                     chown $BBUSER:$BBUSER $dir/backup
  104.                     chmod 700 $dir/backup
  105.                 fi
  106.             done
  107.  
  108.             if ! dpkg-statoverride --list $CONFDIR/bbstored > /dev/null; then
  109.                 dpkg-statoverride --update --add $BBUSER $BBUSER 700 $CONFDIR/bbstored
  110.             fi
  111.  
  112.             # Accounts file
  113.             if [ ! -e $BBACCOUNTS ]; then
  114.                 touch $BBACCOUNTS
  115.             fi
  116.  
  117.             #if [ `stat -c %U $BBACCOUNTS` != $BBUSER ]; then
  118.             if [ `ls -ld $BBACCOUNTS | awk '{ print $3 }'` != "$BBUSER" ]; then
  119.                 chown $BBUSER:$BBUSER $BBACCOUNTS
  120.             fi
  121.  
  122.             #if [ `stat -c %a $BBACCOUNTS` != "600" ]; then
  123.             if [ `ls -ld $BBACCOUNTS | awk '{ print $1 }'` != "drw-------" ]; then
  124.                 chmod 600 $BBACCOUNTS
  125.             fi
  126.  
  127.             SERVNAME=`hostname --fqdn`
  128.  
  129.             # SSL stuff
  130.             if [ ! -e $BBPRIVKEY -a ! -e $BBCERT ]; then
  131.                 db_get boxbackup-server/generateCertificate
  132.  
  133.                 if [ "$RET" = "true" ]; then
  134.                     if ! openssl genrsa -out $BBPRIVKEY 2048 >&2; then
  135.                         echo "Private key generation failed! Check why." >&2
  136.                     else
  137.                         chown $BBUSER: $BBPRIVKEY
  138.                         chmod 600 $BBPRIVKEY || true
  139.                     fi
  140.  
  141.                     if ! openssl req -new -key $BBPRIVKEY -sha1 -out $BBCERTREQ >&2 <<EOF
  142. .
  143. .
  144. .
  145. .
  146. .
  147. $SERVNAME
  148. .
  149. .
  150. .
  151. EOF
  152.                     then
  153.                         echo "Certificate request generation failed ! Check why." >&2
  154.                     fi
  155.                 fi
  156.             fi
  157.  
  158.             # Generate bbstored.conf
  159.             echo "#To reconfigure boxbackup-server run #dpkg-reconfigure boxbackup-server" >> $DEBCONFBB
  160.             echo "RaidFileConf = $RAIDCONF" >> $DEBCONFBB
  161.             echo "AccountDatabase = $BBACCOUNTS" >> $DEBCONFBB
  162.             echo  >> $DEBCONFBB
  163.             echo "# Uncomment this line to see exactly what commands are being received from clients." >> $DEBCONFBB
  164.             echo "# ExtendedLogging = yes" >> $DEBCONFBB
  165.             echo  >> $DEBCONFBB
  166.             echo "# scan all accounts for files which need deleting every 15 minutes." >> $DEBCONFBB
  167.             echo "TimeBetweenHousekeeping = 900" >> $DEBCONFBB
  168.             echo >> $DEBCONFBB
  169.             echo "Server" >> $DEBCONFBB
  170.             echo "{" >> $DEBCONFBB
  171.             echo "      PidFile = /var/run/bbstored.pid" >> $DEBCONFBB
  172.             echo "      User = bbstored" >> $DEBCONFBB
  173.             echo "      ListenAddresses = inet:$SERVNAME" >> $DEBCONFBB
  174.             echo "      CertificateFile = $BBCERT"  >> $DEBCONFBB
  175.             echo "      PrivateKeyFile = $BBPRIVKEY" >> $DEBCONFBB
  176.             echo "      TrustedCAsFile = $BBCACERT" >> $DEBCONFBB
  177.             echo "}" >> $DEBCONFBB
  178.  
  179.             db_stop
  180.  
  181.             ucf --three-way $DEBCONFRAID $RAIDCONF >&2 </dev/tty
  182.             rm -f $DEBCONFRAID
  183.             chmod 644 $RAIDCONF || true
  184.             chown root:root $RAIDCONF || true
  185.  
  186.             ucf --three-way $DEBCONFBB $BBCONF >&2 </dev/tty
  187.             rm -f $DEBCONFBB
  188.             chmod 644 $BBCONF || true
  189.             chown root:root $BBCONF || true
  190.         else
  191.             db_stop
  192.         fi
  193.     ;;
  194.  
  195.     abort-upgrade|abort-remove|abort-deconfigure)
  196.         db_stop
  197.     ;;
  198.  
  199.     *)
  200.         echo "postinst called with unknown argument \`$1'" >&2
  201.         db_stop
  202.         exit 1
  203.     ;;
  204. esac
  205.  
  206. # dh_installdeb will replace this with shell code automatically
  207. # generated by other debhelper scripts.
  208.  
  209. # Automatically added by dh_installinit
  210. if [ -x "/etc/init.d/boxbackup-server" ]; then
  211.         update-rc.d boxbackup-server defaults >/dev/null
  212.         if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
  213.                 invoke-rc.d boxbackup-server start || exit $?
  214.         else
  215.                 /etc/init.d/boxbackup-server start || exit $?
  216.         fi
  217. fi
  218. # End automatically added section
  219.  
  220.  
  221. exit 0

advertising

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will not expire by default. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

comments powered by Disqus
worth-right
worth-right