#!/bin/sh

install_from_default() {
  if [ ! -f $2 ]; then
    echo "Installing $2 from $1 ..."
    cp -p $1 $2
  fi
}

if [ "$1" = "configure" ] && [ "$2" = "" ]; then
  install_from_default /usr/share/base-files/dot.profile /root/.profile
  install_from_default /usr/share/base-files/dot.bashrc  /root/.bashrc
fi

if [ ! -f /etc/adjtime ]; then
  echo "0.000000 809290814 0.000000" > /etc/adjtime
  chmod 644 /etc/adjtime
fi

if [ ! -f /var/run/utmp ]; then
	echo -n>/var/run/utmp
fi
if [ ! -f /var/log/wtmp ]; then
	echo -n>/var/log/wtmp
fi
chown root.root /var/run/utmp /var/log/wtmp
chmod 644 /var/run/utmp /var/log/wtmp

if [ ! -d /usr/local ]; then
	mkdir -p /usr/local
	chown root.staff /usr/local 2> /dev/null || true
	chmod 2775 /usr/local 2> /dev/null || true
	for d in share bin man lib include sbin; do
		cd /usr/local && mkdir -p $d
		chown root.staff /usr/local/$d 2> /dev/null || true
		chmod 2775 /usr/local/$d 2> /dev/null || true
	done
fi

if [ ! -d /var/lib/dpkg ]; then
	mkdir -m 755 -p /var/lib/dpkg
	chown root.root /var/lib/dpkg
fi
if [ ! -f /var/lib/dpkg/status ]; then
	echo > /var/lib/dpkg/status
	chmod 644 /var/lib/dpkg/status
	chown root.root /var/lib/dpkg/status
fi

if [ ! -f /usr/info/dir ]; then
	cat >/usr/info/dir << EOF
-*- Text -*-
This is the file .../info/dir, which contains the topmost node of
the Info hierarchy.  The first time you invoke Info you start off
looking at that node, which is (dir)Top.

File: dir	Node: Top	This is the top of the INFO tree
  This (the Directory node) gives a menu of major topics.  Typing "d"
  returns here, "q" exits, "?" lists all INFO commands, "h"  gives a
  primer for first-timers, "mTexinfo<Return>" visits Texinfo topic,
  etc.
  Or click mouse button 2 on a menu item or cross reference to select
  it.
  --- PLEASE ADD DOCUMENTATION TO THIS TREE. (See INFO topic first.) ---

In Debian Linux, Info \`dir' entries are added with the command
\`install-info'.  Please refer to install-info(8) for usage details.

* Menu: The list of major topics begins on the next line.

General Commands

EOF
	chmod 644 /usr/info/dir
	chown root.root /usr/info/dir
fi
exit 0
