summaryrefslogtreecommitdiffstats
path: root/abs/core-testing/LinHES-config-22/build_diskless.sh
blob: 4dfd5fc32a094bc592305f3b0ae5717b4ea93439 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/bin/bash
#CD=/mnt/cd
. /etc/profile
. /etc/systemconfig

TFTP=/data/srv/tftp
CD=/data/srv/tftp/live
DESTCD=/data/srv/tftp/CD
BASE=/data/srv/tftp/masterbuild

MODULES=$DESTCD/MythVantage/base/
myip=`ifconfig  | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'|head -n1`
SRCFILES=$BASE/mnt/live/mnt/MythVantage/base/

function log () {
echo $1
}

function check_xvfb () {
export    DISPLAY=127.0.0.1:25
 Xvfb -ac :25  &

}


function create_base_image() {
echo $SRCFILES
if [ -f $SRCFILES/data.lzm ]
then
    mkdir $HOST_IMG_DIR
    cd $SRCFILES
    echo "Creating image.." > $BASE/tmp/.install_state
    LIST=`ls *.lzm`
    for i in  $LIST
    do
       echo  $i
       echo  $i > $BASE/tmp/.install_percent
       lzm2dir $i \/$HOST_IMG_DIR
    done

    for i in sys proc dev tmp
    do
         mkdir /$HOST_IMG_DIR/$i
    done

    chmod 777 /$HOST_IMG_DIR/tmp
    mknod /$HOST_IMG_DIR/dev/null c 1 3
    mknod /$HOST_IMG_DIR/dev/null c 1 5
    mknod /$HOST_IMG_DIR/dev/console c 5 1
    chmod +s /$HOST_IMG_DIR/usr/bin/Xorg
    chmod +s /$HOST_IMG_DIR/usr/bin/crontab
    chmod +s /$HOST_IMG_DIR/usr/bin/sudo
    chmod +s /$HOST_IMG_DIR/bin/mount
    #copy fstab from masterbuild
    cp -f $BASE/etc/fstab /$HOST_IMG_DIR/etc/fstab
    echo "Done: installing data" > $BASE/tmp/.install_state
    return 0
else
    echo "Error: no modules" > $BASE/tmp/.install_state
    log "couldn't find modules to install"
    return 1
fi
}

function configure_image () {
    echo "Configuring system" > $BASE/tmp/.install_state
    cp -f $BASE/etc/systemconfig  $HOST_IMG_DIR/etc/systemconfig
    chown root:mythtv $HOST_IMG_DIR/etc/systemconfig
    chmod 775 "$HOST_IMG_DIR" /etc/systemconfig
    cp /etc/mtab $HOST_IMG_DIR/etc/mtab
     mount --bind /dev $HOST_IMG_DIR/dev

    chroot "$HOST_IMG_DIR" $MV_ROOT/bin/systemconfig.sh misc,hostype,network,this_is_install
#copy syssettings template to here.
    SE=$BASE$TEMPLATES/settings/syssettings
    mkdir -p  $HOST_IMG_DIR/$TEMPLATES/settings/syssettings
    cp -rp $SE/*  ${HOST_IMG_DIR}/$TEMPLATES/settings/syssettings
    chown root:mythtv $HOST_IMG_DIR/etc/systemconfig
    chown -R mythtv:mythtv $HOST_IMG_DIR/$TEMPLATES/settings/syssettings
    chmod -R 775  $HOST_IMG_DIR/$TEMPLATES/settings/syssettings
#update remotedb with this host settings
    OLDDISPLAY=$DISPLAY
    check_xvfb
    chroot $HOST_IMG_DIR  $MV_ROOT/bin/MythVantage  -t  restore,default_1
    chroot $HOST_IMG_DIR  $MV_ROOT/bin/restore_default_settings.sh -c restore -t syssettings
    if [ !  $? = 0 ]
    then
            touch $mountpoint/tmp/.dbsysfailed
            chmod 777 $mountpoint/tmp/.dbsysfailed
    else
        #Run second time
        chroot "$HOST_IMG_DIR" $MV_ROOT/bin/systemconfig.sh misc,hostype,network,this_is_install
        chroot "$HOST_IMG_DIR" $MV_ROOT/bin/restore_default_settings.sh -c  ACCESSCONTROL
    fi
chroot "$HOST_IMG_DIR" $MV_ROOT/bin/systemconfig.sh advanced,this_is_install
cp -f $BASE/etc/X11/xorg.conf   $HOST_IMG_DIR/etc/X11/xorg.conf
echo "Done" > $BASE/tmp/.install_state
DISPLAY=$OLDDISPLAY

#cp /tmp/mythvantage_install.log  $HOST_IMG_DIR/var/log/
}

function create_tftp_boot () {

    CFGFILE=$TFTP/pxelinux.cfg/01-$2
    echo "DEFAULT mythfe" > $CFGFILE
    echo "LABEL mythfe" >> $CFGFILE
    echo "kernel masterbuild/boot/vmlinuz26STB" >> $CFGFILE
    echo "append vga=normal root=/dev/nfs rw netboot  nfsroot=$myip:/data/srv/tftp/$1 ip=dhcp init=/sbin/runit" >> $CFGFILE
    echo "TIMEOUT 2" >>  $CFGFILE
}

function create_nfs_export () {
echo "/data/srv/tftp/$1    *(rw,no_root_squash,anonuid=1000,anongid=1000) " >> /etc/exports
exportfs -arv
}

#-------------------------------------------------------------------------------MAIN PROGRAM ---------------------------------------------------------------------
if [ x$1 = x  -o   x$2 = x ]
then
    echo "usage:  hostname macaddress"
	exit 1
fi

image_name=$1
mac_address=`echo $2| tr "[:upper:]" "[:lower:]"`

echo "using image_name of $image_name"
echo "using mac_address of $mac_address"

HOST_IMG_DIR=$TFTP/$1

create_base_image $image_name
configure_image
umount $HOST_IMG_DIR/dev
create_tftp_boot $image_name $mac_address
create_nfs_export $image_name




#create_dhcp_entry $mac_address