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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
#!/bin/bash
#CD=/mnt/cd
. /etc/profile
. /etc/systemconfig
current_hostname=`hostname`
echo $@ > /tmp/diskless_build.call
TFTP=/data/srv/tftp
CD=/data/srv/tftp/live
DESTCD=/data/srv/tftp/CD
BASE=/data/srv/tftp/masterbuild
MODULES=$DESTCD/MythVantage/base/
#only supports eth0 at this point
myip=`ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'|head -n1`
SRCFILES=$BASE/.livesys/medium
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/system.sqf ]
then
mkdir $HOST_IMG_DIR
cd $SRCFILES
echo "Creating image..." > $BASE/tmp/.install_state
echo "Transferring system"
unsquashfs -i -f -d \/$HOST_IMG_DIR $DESTCD/system.sqf
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
echo "configuring boot" > $BASE/tmp/.install_state
sed -ie 's/^MODULES=.*$/MODULES="nfs"/g' $HOST_IMG_DIR/etc/mkinitcpio.conf
sed -ie 's/^HOOKS=.*$/HOOKS="base net udev autodetect pata scsi sata filesystems"/g' $HOST_IMG_DIR/etc/mkinitcpio.conf
#chroot $DEST mkinitcpio -p kernel26
#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
# mount --bind /dev/pts $HOST_IMG_DIR/dev/pts
mount --bind /proc $HOST_IMG_DIR/proc
mount --bind /sys $HOST_IMG_DIR/sys
chroot "$HOST_IMG_DIR" $MV_ROOT/bin/systemconfig.sh misc,hostype,network,this_is_install,NETINSTALL
#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
echo "Running MythVantage to restore settings"
DISPLAY=$DISPLAY HOME=/root 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,NETINSTALL
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,NETINSTALL
cp -f $BASE/etc/X11/xorg.conf $HOST_IMG_DIR/etc/X11/xorg.conf
echo "Done" > $BASE/tmp/.install_state
DISPLAY=$OLDDISPLAY
#umount $HOST_IMG_DIR/dev/pts
umount $HOST_IMG_DIR/dev
#umount $HOST_IMG_DIR/dev/pts
#umount $HOST_IMG_DIR/dev
umount $HOST_IMG_DIR/proc
umount $HOST_IMG_DIR/sys
#umount $HOST_IMG_DIR/sys
#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/vmlinuz26" >> $CFGFILE
echo "append vga=normal root=/dev/nfs rw netboot nfsroot=$myip:/data/srv/tftp/$1 ip=dhcp init=/sbin/runit initrd=masterbuild/boot/kernel26.img" >> $CFGFILE
echo "TIMEOUT 2" >> $CFGFILE
}
function create_nfs_export () {
grep -q "/data/srv/tftp/$1" /etc/exports
status=$?
if [ ! $status = 0 ]
then
echo "adding $1 to nfs exports"
echo "/data/srv/tftp/$1 *(rw,no_root_squash,anonuid=1000,anongid=1000) " >> /etc/exports
exportfs -arv
fi
}
#-------------------------------------------------------------------------------MAIN PROGRAM ---------------------------------------------------------------------
if [ x$1 = x -o x$2 = x ]
then
echo "usage: hostname macaddress"
echo "example: Love 00-0C-29-E6-8A-A9"
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
hostname $current_hostname
umount $HOST_IMG_DIR/dev
create_tftp_boot $image_name $mac_address
create_nfs_export $image_name
echo "Finshed!"
#create_dhcp_entry $mac_address
|