#!/bin/sh

#
# Randomizes the root password on first boot
#
# * When the file /root/firstboot is present, this script will
#   randomize the root password.
#
#   who: delano@solutious.com
#  when: 2009-03-13
#

# NOTE: Works on Gentoo
# TODO: Fix for debian

if [ -f "/root/firstrun" ] ; then
  dd if=/dev/urandom count=50|md5sum|passwd --stdin root
  rm -f /root/firstrun
else
  echo "* Firstrun *" && touch /root/firstrun
fi

# New Gentoo (to be tested)
#if [ -f "/root/firstrun" ] ; then
#  pword=`dd if=/dev/urandom count=51 | sha1sum`
#  echo $pword | passwd --stdin root
#  rm -f /root/firstrun
#else
#  echo "* Firstrun *" && touch /root/firstrun
#fi

# Fix for debian
#if [ -f "/root/firstrun" ] ; then
#  pword=`dd if=/dev/urandom count=51 | sha1sum`
#  echo "root:$pword" | chpasswd
#  rm -f /root/firstrun
#else
#  echo "* Firstrun *" && touch /root/firstrun
#fi

# Random root password for Gentoo: 
#dd if=/dev/urandom count=51 | sha1sum | passwd --stdin root

# Random root password for Debian/Ubuntu:
#echo "root:`dd if=/dev/urandom count=51 | sha1sum`" | chpasswd