diff options
Diffstat (limited to 'abs/mv-core/MythVantage-config/install_functions.sh')
-rwxr-xr-x | abs/mv-core/MythVantage-config/install_functions.sh | 525 |
1 files changed, 183 insertions, 342 deletions
diff --git a/abs/mv-core/MythVantage-config/install_functions.sh b/abs/mv-core/MythVantage-config/install_functions.sh index 1d217e9..0bc0591 100755 --- a/abs/mv-core/MythVantage-config/install_functions.sh +++ b/abs/mv-core/MythVantage-config/install_functions.sh @@ -1,5 +1,6 @@ #!/bin/bash . /etc/profile + disk=$2 mountpoint=new_boot @@ -10,9 +11,11 @@ CMDLINE=$(cat /proc/cmdline) hostname=`hostname` MYSQLCMD_C="mysql -u$MYTHDBUSER -p$MYTHTVPASSWD mythconverg -B --exec" BASE="" +found_remote=1 function update_db_settings () { + printhl " setting database value $1 to $2 for $hostname" $MYSQLCMD_C "delete from settings where value='${1}' and hostname=\"$hostname\";" $MYSQLCMD_C "REPLACE INTO settings set value='${1}', data='${2}' , hostname=\"$hostname\";" } @@ -29,13 +32,34 @@ theme=($THEMES) # Read into array variable. num_themes=${#theme[*]} # Count how many elements. pick=${theme[$((RANDOM%num_themes))]} -echo "Selected $pick as the theme" +printhl " Selected $pick as the theme" update_db_settings Theme "$pick" } +function parse_cmdline_2_db(){ + echo $CMDLINE | grep -q displayres + if [ $? -eq 0 ] + then + TEMPVAR=${CMDLINE#*displayres=} + update_db_settings HostXres $TEMPVAR + fi + +} + + +function bootsplash_setup (){ + echo $CMDLINE | grep -q splash=silent + if [ $? -eq 0 ] + then + update_db_settings Hostbootsplash 1 + else + update_db_settings Hostbootsplash 0 + fi +} + function setupremote { - mv $BASE/etc/lircd.conf $BASE/etc/lircd.conf.`date +%Y-%m-%d-%H-%M` + [ -e $BASE/etc/lircd.conf ] && mv -f $BASE/etc/lircd.conf $BASE/etc/lircd.conf.`date +%Y-%m-%d-%H-%M` if [ -d $TEMPLATES/remotes/$Remotetype ] then cd $TEMPLATES/remotes/$Remotetype @@ -43,110 +67,162 @@ function setupremote { do cat $i >> $BASE/etc/lircd.conf done - cp lircrc $BASE/etc/lircrc - chmod 755 /etc/lircrc + cp -f lircrc* $BASE/etc/lircrc 2> /dev/null + [ -e /etc/lircrc ] && chmod 755 /etc/lircrc update_db_settings HostRemoteType "$Remotetype" - /usr/sbin/lircd -d /dev/lirc0 - mkdir /root/.mythtv - ln -s /etc/lircrc /root/.mythtv/lircrc - else + #special case for special remote + printhl "Starting with support for $Remotetype" + if [ "$Remotetype" == "dvico" ] + then + /usr/sbin/lircd -d /dev/usb/hiddev0 --driver=dvico + elif [ "$Remotetype" == "Dvico-Dual-Digital4-rev2" ] + then + /usr/sbin/lircd -d /dev/input/irremote --driver=devinput + else + /usr/sbin/lircd -d /dev/lirc0 + fi + [ -e /root/.mythtv ] || mkdir /root/.mythtv 2>/dev/null + ln -s /etc/lircrc /root/.mythtv/lircrc 2>/dev/null + else echo "Couldn't open directory $TEMPLATES/remotes/$Remotetype" fi } function scan_for_hpg_receiver() { -echo "Scanning for Hauppauge receiver" +printhl " Scanning for Hauppauge receiver" for hpgid in `lspci -nm -d4444: |cut -d" " -f6- |tr -d '"'|tr " " :` do line=`grep $hpgid $TEMPLATES/remotes/i2c.id` - if [ $? = 0 ] + if [ $? -eq 0 ] then modprobe lirc_i2c FoundReceiverType=`echo "$line"|cut -d"|" -f2` Remotetype=`echo "$line"|cut -d"|" -f4` statusline=`echo "$line"|cut -d"|" -f2,4` - echo "Found $statusline , $Remotetype" + #echo "Found $statusline , $Remotetype" + echo "Found Hauppauge" + echo "-------------------" + echo " 1) Hauppauge black" + echo " 2) Hauppauge silver" + echo " 3) hauppauge-grey-g3" + echo "" + read -p "Which Hauppauge remote (5 sec): " -t 5 ans + echo + if [ "$?" != "0" ]; then + echo + echo "Using default $Remotetype" + else + case $ans in + 1) Remotetype="hauppauge-black";; + 2) Remotetype="hauppauge-silver";; + 3) Remotetype="hauppauge-grey-g3" ;; + *) echo "Using default $Remotetype";; + esac + fi update_db_settings HostReceiverType $FoundReceiverType + found_remote=0 setupremote break fi - done } + function scan_for_usb_remote () { -echo "Scanning for usb receiver/remote" +#found_remote=1 +printhl " Scanning for usb receiver/remote" while read line do - USBID=`echo "$line"|cut -f1` + USBID=`echo "$line"|cut -d"|" -f1` lsusb -d "$USBID" > /dev/null 2>/dev/null - if [ $? = 0 ] + if [ $? -eq 0 ] then - # Remotetype=`echo "$line"|cut -f2` - Remotetype=`echo "$line"|cut -d"|" -f2` - echo "found $Remotetype" + Remotetype=`echo "$line"|cut -d"|" -f2` + printhl "Found $Remotetype" setupremote + found_remote=0 break fi done <$BASE/$TEMPLATES/remotes/receiver_usb.id -scan_for_hpg_receiver +if [ $found_remote -eq 1 ] +then + scan_for_hpg_receiver +fi +printhl " Scanning for TatIR" +if lsusb | grep 04d8:0004 > /dev/null 2>/dev/null +then + /usr/bin/PyroUsb.py > /dev/null 2>&1 & +fi + +if [ $found_remote -eq 1 ] +then +#No remote found_remote + update_db_settings HostRemoteType "no_remote" +fi + } function rest_of_network () { #netmask - echo $CMDLINE | grep -q netmask - if [ $? = 0 ] + echo $CMDLINE | grep -q cnetmask + if [ $? -eq 0 ] then - TEMPVAR=${CMDLINE#*netmask=} + TEMPVAR=${CMDLINE#*cnetmask=} NETMASK=${TEMPVAR%% *} /sbin/ifconfig eth0 $IP netmask $NETMASK nm=`/usr/bin/nmconv.py -obits $NETMASK` NETMASK="/$nm $NETMASK" - echo $NETMASK + #echo $NETMASK update_db_settings HostNETMASK${MYTHDEFAULT} "$NETMASK" else - echo "netmask not found" + printhl " Netmask not found" fi #gateway - echo $CMDLINE | grep -q gateway - if [ $? = 0 ] + echo $CMDLINE | grep -q cgateway + if [ $? -eq 0 ] then - TEMPVAR=${CMDLINE#*gateway=} + TEMPVAR=${CMDLINE#*cgateway=} GATEWAY=${TEMPVAR%% *} /sbin/route add default gw $GATEWAY update_db_settings HostGW${MYTHDEFAULT} "$GATEWAY" - - else - echo "gateway not found" + else + printhl " Gateway not found" fi #dns - echo $CMDLINE | grep -q dns - if [ $? = 0 ] + echo $CMDLINE | grep -q cdns + if [ $? -eq 0 ] then - TEMPVAR=${CMDLINE#*dns=} + TEMPVAR=${CMDLINE#*cdns=} DNS=${TEMPVAR%% *} echo "nameserver $DNS" >> /etc/resolv.conf update_db_settings HostDNS${MYTHDEFAULT} "$DNS" else - echo "DNS not found" + printhl " DNS not found" + fi + echo $CMDLINE | grep -q chostname + if [ $? -eq 0 ] + then + TEMPVAR=${CMDLINE#*chostname=} + MYHOST=${TEMPVAR%% *} + update_db_settings HostMyhostname "$MYHOST" + else + printhl " hostname not found" fi } function init_network { - echo $CMDLINE |grep -q netdev - if [ $? = 0 ] + echo $CMDLINE |grep -q cnetdev + if [ $? -eq 0 ] then - TEMPVAR=${CMDLINE#*netdev=} + TEMPVAR=${CMDLINE#*cnetdev=} MYTHDEFAULT=${TEMPVAR%% *} else MYTHDEFAULT="eth0" fi - - echo $CMDLINE | grep -q ip - if [ $? = 0 ] + if [ $? -eq 0 ] then update_db_settings HostDefaulteth0 0 update_db_settings HostDefault${MYTHDEFAULT} 1 @@ -155,9 +231,9 @@ function init_network { update_db_settings HostActiveonboot${MYTHDEFAULT} 1 update_db_settings HostNetDevice ${MYTHDEFAULT} - TEMPVAR=${CMDLINE#*ip=} + TEMPVAR=${CMDLINE#*cip=} IP=${TEMPVAR%% *} - if [ x$IP = xdhcp ] + if [ "$IP" == "dhcp" ] then /sbin/dhcpcd $MYTHDEFAULT update_db_settings HostUseDHCP${MYTHDEFAULT} 0 @@ -168,11 +244,74 @@ function init_network { rest_of_network fi fi + + + + +} + +function dev_up_check(){ + /sbin/ifconfig $1 1>/dev/null 2>/dev/null + status=$? + if [ $status -eq 1 ] + then + return 0 + else + devip=`/sbin/ifconfig | grep -C1 $1| grep inet|grep -v inet6 | cut -d: -f2 | awk '{ print $1}'` + if [ "x$devip" = "x" ] + then + return 1 + else + return 0 + fi + fi +} + +function request_dhcp(){ + echo $CMDLINE |grep -q cnetdev + if [ $? -eq 0 ] + then + TEMPVAR=${CMDLINE#*cnetdev=} + MYTHDEFAULT_NET=${TEMPVAR%% *} + else + MYTHDEFAULT_NET="eth0" + fi + for ndev in eth0 eth1 wlan0 wlan1 ath0 + do + dev_up_check $ndev + status=$? + if [ $status -eq 1 ] + then + #interface is down, lets see if dhcp responds + dhcpcd -Td -t2 $ndev -h "" > /tmp/dhcpinfo.$ndev + #check for hostname here + + TEMPVAR=`grep new_ip_address /tmp/dhcpinfo.$ndev |cut -d\= -f2` + if [ ! x$TEMPVAR = x ] + then + update_db_settings HostIP$ndev "$TEMPVAR" + TEMPVAR=`grep new_subnet_mask /tmp/dhcpinfo.$ndev |cut -d\= -f2` + nm=`/usr/bin/nmconv.py -obits $TEMPVAR` + TEMPVAR="/$nm $TEMPVAR" + update_db_settings HostNETMASK$ndev "$TEMPVAR" + TEMPVAR=`grep new_routers /tmp/dhcpinfo.$ndev |cut -d\= -f2` + update_db_settings HostGW$ndev "$TEMPVAR" + TEMPVAR=`grep new_domain_name_servers /tmp/dhcpinfo.$ndev |cut -d\= -f2` + update_db_settings HostDNS$ndev "$TEMPVAR" + fi + fi + done + TEMPVAR=`grep new_host_name /tmp/dhcpinfo.$MYTHDEFAULT_NET |cut -d\= -f2` + if [ ! x$TEMPVAR = x ] + then + update_db_settings HostMyhostname "$TEMPVAR" + fi + } function init_remote { echo $CMDLINE | grep -q remoteport - if [ $? = 0 ] + if [ $? -eq 0 ] then TEMPVAR=${CMDLINE#*remoteport=} REMOTEPORT=${TEMPVAR%% *} @@ -190,7 +329,7 @@ function init_remote { fi echo $CMDLINE | grep -q remote - if [ $? = 0 ] + if [ $? -eq 0 ] then TEMPVAR=${CMDLINE#*remote=} Remotetype=${TEMPVAR%% *} @@ -202,302 +341,4 @@ function init_remote { #----------------------- -#set -x - -partition_it () { -ROOT=$1 -DATA=$2 -SWAP=$3 - -if [ ! x$SWAP = xNO ] - then - SWAPLINE=",$SWAP,S" - MKSWAPCMD="mkswap /dev/${disk}2" - else - SWAPLINE=",0,0" - MKSWAPCMD="" - fi - -if [ x$DATA = xALL ] -then - DATALINE=",,," - EXTRALINE="" -else - DATALINE=",$DATA,," - EXTRALINE=",0,," -fi -sfdisk /dev/$disk -uM << EOF -,$1,,* -$SWAPLINE -$DATALINE -$EXTRALINE -; -EOF - -$MKSWAPCMD -#sfdisk -l /dev/$disk -} - - -function fscmd () { - -case $1 in - reiserfs) FSCMDC="mkreiserfs -q -l ROOT" - ;; - - xfs) FSCMDC="mkfs -t $1 -f" - ;; - ext3) FSCMDC="mkfs.ext3" - ;; - jfs) FSCMDC="mkfs.jfs -q " - ;; - *) FSCMDC="echo $1" - ;; - -esac -} - -format_it () { - fscmd $1 - $FSCMDC /dev/${disk}1| tr -s [:cntrl:] \\n - fscmd $2 - $FSCMDC /dev/${disk}3| tr -s [:cntrl:] \\n -} - -mount_it () { - if [ ! -d \/$mountpoint ] - then - mkdir \/$mountpoint - fi - mount /dev/${disk}1 \/$mountpoint - mkdir \/$mountpoint/data - mount /dev/${disk}3 \/$mountpoint/data -} - -unmount_it () { - umount /dev/${disk}1 - umount /dev/${disk}3 -} - -#linux-live version of copy_it -# copy_it () { -# #rsync -rvp --exclude=/mnt --exclude=\/$mountpoint / \/$mountpoint -# lzmdir=`find /mnt/live/mnt -name data.lzm -execdir pwd \;| tail -1` -# cd $lzmdir -# if [ x$1 = xALL ] -# then -# LIST=`ls *.lzm` -# else -# LIST=`echo $1 | tr , " " ` -# fi -# -# for i in $LIST -# do -# echo "Transferring $i" -# lzm2dir $i \/$mountpoint -# done -# for i in sys proc dev tmp -# do -# mkdir /$mountpoint/$i -# -# done -# chmod 777 /$mountpoint/tmp -# mknod /$mountpoint/dev/null c 1 3 -# mknod /$mountpoint/dev/null c 1 5 -# mknod /$mountpoint/dev/console c 5 1 -# chmod +s /$mountpoint/usr/bin/Xorg -# chmod +s /$mountpoint/usr/bin/crontab -# chmod +s /$mountpoint/usr/bin/sudo -# chmod +s /$mountpoint/bin/mount -# -# } - -copy_it () { - - if [ x$1 = xALL ] - then - echo "Transferring system" - unsquashfs -f -d /$mountpoint /.livesys/medium/system.sqf - else - echo "Upgrading system" - unsquashfs -e $1 -f -d /$mountpoint /.livesys/medium/system.sqf - fi - - for i in sys proc dev tmp - do - mkdir /$mountpoint/$i - - done - chmod 777 /$mountpoint/tmp - mknod /$mountpoint/dev/null c 1 3 - mknod /$mountpoint/dev/null c 1 5 - mknod /$mountpoint/dev/console c 5 1 - chmod +s /$mountpoint/usr/bin/Xorg - chmod +s /$mountpoint/usr/bin/crontab - chmod +s /$mountpoint/usr/bin/sudo - chmod +s /$mountpoint/bin/mount - -} - - -device_node () { - cd /dev - mknod hda b 3 0 - mknod hda1 b 3 1 - mknod hda2 b 3 2 - mknod hda3 b 3 3 - mknod hda4 b 3 4 - mknod hda5 b 3 5 - mknod hda6 b 3 6 - mknod hda7 b 3 7 - mknod hda8 b 3 8 - mknod sda b 8 0 - mknod sda1 b 8 1 - mknod sda2 b 8 2 - mknod sda3 b 8 3 - mknod sda4 b 8 4 - mknod sda5 b 8 5 - mknod sda6 b 8 6 - mknod sda7 b 8 7 - mknod sda8 b 8 8 - mknod sdb b 8 16 - mknod sdb1 b 8 17 - mknod sdb2 b 8 18 - mknod sdb3 b 8 19 - mknod sdb4 b 8 20 - mknod sdb5 b 8 21 - mknod sdb6 b 8 22 - mknod sdb7 b 8 23 - mknod sdb8 b 8 24 - cd - - } - - -function create_fstab() -{ -echo "creating fstab" -cat > /$mountpoint/etc/fstab << EOF -# <file system> <dir> <type> <options> <dump> <pass> -none /dev/pts devpts defaults 0 0 -none /dev/shm tmpfs defaults 0 0 -/dev/cdrom /media/cdrom auto ro,user,noauto,unhide 0 0 -/dev/dvd /media/dvd auto ro,user,noauto,unhide 0 0 -UUID=ROOTUID / auto defaults 0 1 -UUID=DATAUID /data auto defaults 0 1 -UUID=SWAPUID swap swap defaults 0 0 -EOF - - -} - - -function find_uuid() { - uuid=`blkid -s UUID /dev/$1 |cut -d= -f2|cut -d\" -f2` - echo $uuid for $1 - FOUNDUUID=$uuid - -} - - -case $1 in - partition_it ) - #drive ROOT DATA(ALL) SWAP(NO) - for i in `mount | grep $disk | awk ' { print $1 } '` - do - umount $i - done - swap=`cat /etc/fstab |grep $disk|grep swap|awk ' { print $1 } '` - swapoff $swap - partition_it $3 $4 $5 - exit 0 - - ;; - format_it ) - device_node - - format_it $3 $4 - exit 0 - ;; - mount_it ) - mount_it - ;; - copy_it ) - copy_it $3 - - ;; - - - fstab_fix_it) - echo $@ >> /tmp/fstab.input - if [ ! -f /$mountpoint/etc/fstab ] - then - create_fstab - fi - - if [ x$3 = xUPGRADE ] - then - echo "copying old fstab" - cp -f /tmp/etc/fstab /$mountpoint/etc/fstab - FOUNDUUID="" - find_uuid ${2}1 - ROOTUUID=$FOUNDUUID - sed -i -e "s/.*\/\ .*$/UUID=$ROOTUUID \/ auto defaults,noatime 0 1/g" /$mountpoint/etc/fstab - else - #search for UUID - FOUNDUUID="" - find_uuid ${2}1 - ROOTUUID=$FOUNDUUID - - echo "--" - echo $ROOTUUID - echo "--" - - FOUNDUUID="" - find_uuid ${2}2 - SWAPUUID=$FOUNDUUID - - FOUNDUUID="" - find_uuid ${2}3 - DATAUUID=$FOUNDUUID - sed -i -e "s/.*\/\ .*$/UUID=$ROOTUUID \/ auto defaults,noatime 0 1/g" /$mountpoint/etc/fstab - sed -i -e "s/.*\/data\ .*$/UUID=$DATAUUID \/data auto defaults,noatime 0 1/g" /$mountpoint/etc/fstab - sed -i -e "s/.*swap\ .*$/UUID=$SWAPUUID swap swap defaults 0/g" /$mountpoint/etc/fstab - fi - - ;; - - grub_it ) - #linux-live - #grub-install --recheck --no-floppy --root-directory=/$mountpoint /dev/$disk - grub-install --recheck --no-floppy --root-directory=/$mountpoint "(hd0)" - - - #fixing fstab -# if [ ! -f /$mountpoint/etc/fstab ] -# then -# cp -f /$mountpoint/etc/fstab.install /$mountpoint/etc/fstab -# fi -# sed -e s/hda/$disk/g /$mountpoint/etc/fstab > /tmp/newfstab -# cp -f /tmp/newfstab /$mountpoint/etc/fstab - - #fixing grub/menu.1st - FOUNDUUID="" - find_uuid ${disk}1 - ROOTUUID=$FOUNDUUID -# sed -e s/hda/$disk/g /$mountpoint/boot/grub/menu.lst > /tmp/menu.lst - - sed -i -e "s/root=.\S*/root=\/dev\/disk\/by-uuid\/$ROOTUUID/g" /$mountpoint/boot/grub/menu.lst - - -#cp -f /tmp/menu.lst /$mountpoint/boot/grub/menu.lst - #cp /etc/X11/xorg.conf /$mountpoint/etc/X11/xorg.conf - mkinitcpio -g /$mountpoint/boot/kernel26.img - ;; - umount_it) - - umount \/$mountpoint/data - umount \/$mountpoint -esac - - |