#!/bin/bash

ROOTDIR=$1

usage () {
    echo "usage: mkdevnodes <root_dir>" >&2
    exit 1
}

notroot () {
    echo "You must be root to run this script" >&2
    exit 1
}

[ -d "$ROOTDIR" ] || usage
[ $UID -eq 0 ] || notroot

mkdir $ROOTDIR/dev/input

umask 0000
awk '{ printf("mknod %s/dev/%s %s %s %s\n", $1, $2, $3, $4, $5);
       printf("chmod %s %s/dev/%s\n", $6, $1, $2);
       printf("chown %s %s/dev/%s\n", $7, $1, $2); 
     }' <<EOF | sh
    $ROOTDIR console c 5 1 600 root:root
    $ROOTDIR ttyS0 c 4 64 600 root:root
    $ROOTDIR ttyS1 c 4 65 600 root:root
    $ROOTDIR ttyS2 c 4 66 600 root:root
    $ROOTDIR ttyS3 c 4 67 600 root:root
    $ROOTDIR psaux c 10 1 644 root:root
    $ROOTDIR null c 1 3 666 root:root
    $ROOTDIR zero c 1 5 666 root:root
    $ROOTDIR md0 b 9 0 644 root:root
    $ROOTDIR mem c 1 1 600 root:root
    $ROOTDIR ram b 1 1 640 root:root
    $ROOTDIR ptmx c 5 2 666 root:root
    $ROOTDIR tty0 c 4 0 600 root:tty
    $ROOTDIR tty1 c 4 1 600 root:tty
    $ROOTDIR tty2 c 4 2 600 root:tty
    $ROOTDIR tty3 c 4 3 600 root:tty
    $ROOTDIR tty4 c 4 4 600 root:tty
    $ROOTDIR tty5 c 4 5 600 root:tty
    $ROOTDIR tty6 c 4 6 600 root:tty
    $ROOTDIR tty7 c 4 7 600 root:tty
    $ROOTDIR tty8 c 4 8 600 root:tty
    $ROOTDIR tty9 c 4 9 600 root:tty
    $ROOTDIR fb0 c 29 0 600 root:tty
    $ROOTDIR fb1 c 29 32 600 root:tty
    $ROOTDIR fb2 c 29 64 600 root:tty
    $ROOTDIR fb3 c 29 96 600 root:tty
    $ROOTDIR fb4 c 29 128 600 root:tty
    $ROOTDIR fb5 c 29 160 600 root:tty
    $ROOTDIR fb6 c 29 192 600 root:tty
    $ROOTDIR fb7 c 29 224 600 root:tty
    $ROOTDIR openprom c 10 139 644 root:root
    $ROOTDIR kbd c 11 0 644 root:root
    $ROOTDIR ptyp0 c 2 0 644 root:root
    $ROOTDIR ttyp0 c 3 0 644 root:root
    $ROOTDIR agpgart c 10 175 664 root:root
    $ROOTDIR input/mice c 13 63 664 root:root
    $ROOTDIR fd0 b 2 0 644 root:root
    $ROOTDIR fd1 b 2 1 644 root:root
    $ROOTDIR urandom c 1 9 644 root:root
    $ROOTDIR tty c 5 0 666 root:root
    $ROOTDIR dsp c 14 3 666 root:root
    $ROOTDIR fr400cc_i2s c 10 250 666 root:root
    $ROOTDIR fr400cc_vcc c 10 240 666 root:root
    $ROOTDIR fr400cc_vdc c 10 244 666 root:root
EOF
