All pastes #461588 Raw Edit

Miscellany

public text v1 · immutable
#461588 ·published 2007-04-27 19:35 UTC
rendered paste body
#!/bin/bash
draw_box () {
clear
size=$2
if [ "$size" = "1" ] || [ "$size" = "0" ]
then
  size=2
fi
box_size_x=64
box_size_y=17
#parse :(
bar_size2=$(echo "scale=2; 0.55 * $size" | bc)
bar_size_p=${bar_size2##*.} 
bar_size=${bar_size2//.$bar_size_p/}
#parse :)
x=0
y=2
full_line=$x
export "hasu$1"="\033[0;32m"

print_numbah () {
u=$1
while (( u >= 1 ))
do 
  echo -ne "$2"
  let "u -= 1"
done
u=0
}

draw_full_line () {
let "x += 2"
while (( "$box_size_x" >= "$x" ))
do
  echo -n "#"
  let "x += 1"
done
echo "#"
x=0
}

while (( "$box_size_y" >= "$y" ))
do
 if [ "$y" = "2" ] || [ "$y" = "$box_size_y" ]
 then
   draw_full_line
 else
   echo -n "#"
   x=3
   while (( "$box_size_x" >= "$x" ))
   do
     echo -n " " 
     let "x += 1"
   done
   echo "#"
   x=0
 fi
if [ "$y" = 3 ]
then 
  echo -ne "#" "${hasu1}1. Update\033[0m"
  print_numbah 52 " "
  echo -n "#"
  echo #
fi
if [ "$y" = 4 ]
then 
  echo -ne "# ${hasu2}2. backups\033[0m" 
  print_numbah 51 " "
  echo -n "#"
  echo #
fi
if [ "$y" = 5 ]
then 
  echo -ne "# ${hasu3}3. install and compile\033[0m" 
  print_numbah 39 " "
  echo -n "#"
  echo #
fi
if [ "$y" = "14" ]
then
  echo -n "#   |" 
  print_numbah $bar_size '\E[33;40m#\033[0m'
  let "printade = 55 - $bar_size"
  print_numbah $printade " " 
  echo -n "|  #"
  echo " "
  echo -n "#   |" 
  print_numbah $bar_size '\E[33;40m#\033[0m'
  let "printade = 55 - $bar_size"
  print_numbah $printade " " 
  echo -n "|  #"
  echo " "
fi
let "y += 1"
done
}

echo_err () {
#red on black bg
echo -e '\E[31;40m'ERROR: $1; tput sgr0
}

svn_get () {
echo "Downloading source of "$1
if svn co $1 > /dev/null
 then
 return 0
else 
 echo_err "failed to get source of "$1
 echo "exiting..." && exit
 return 1
fi
}

#updates everything, dir name
svn_update () {
if [ $(svn update $1 | wc -l) > 1 ] || [ "$2" = "f" ]
then 
  #echo "$1 updated"
  return 0
else
  #echo "$1 is already latest version"
  return 1
fi
}

dir_check () {
if [ -d mythtv ]
  then 
  if [ -d mythplugins ]
    then 
    if [ -d myththemes ]
      then 
      return 0
    else return 2
    fi
  else return 2
  fi
else return 2
fi
}

#will check if user is valid and if all needed programs are installed, valid_user
bas_check () {
if [ $(id -un) = $1 ] 
 then 
   if [ -e /usr/bin/gcc ] ||  [ -e /usr/local/bin/gcc ]
     then 
        if [ -e /usr/bin/svn ] || [ -e /usr/local/bin/svn ]
          then
            if [ -e /usr/bin/bc ] || [ -e /usr/local/bin/bc ]
              then
                return 0
              else 
              echo "you need to install bc"
              return 2
            fi
          else 
          echo "You need to install subversion"
          fi 
   else 
   echo "you need to install gcc" 
   return 2
   fi
else 
echo "you need to be" $1 "please do 'su" $1"' and come back"
return 2
fi
}

#Compile+configure for mythtv part compile_options,name
compile_1 () {
cd $2
if ./configure $1 > /dev/null
then
  if qmake "$2".pro > /dev/null
   then
     if make > /dev/null 2>/dev/null
     then
       cd ..
       return 0
     else echo_err "failed at make of" $2 && return 3
     fi  
  else echo_err "failed at qmake of" $2 && return 2
  fi
else echo_err "failed at configure of" $2 && return 1
fi
}

#name  compile_options, mythtv:myththemes:mythplugins, no_root,need to compile
compile_23 () {
if [[ $4 = 0 ]]
then
if compile_1 "$1" $2
then 
  if [[ $3 = 0 ]]
    then 
      echo "Using sudo to install $2"
      sudo /etc/init.d/mythtv-backend stop
      #sudo /etc/init.d/mythtv-frontend stop
      sleep 1
      #just to make sure
      killc mythbackend
      killc mythfrontend
      cd $2
      sudo make install > /dev/null
      cd .. 
      return 0
    else
      #echo "you cannot proceed because rooting is not allowed"
      return 2
  fi
else
echo_err "compile or install failed!" $2
echo "You need to run following as root to restore backups: "cd / && tar zxvf ~/mythlibs.tgz""
return 1
fi
else 
echo "no need to compile or install" $2
return 0
fi
}

#Will tell time used, $(date +%s) at start
timer () {
let "erotus = $(date +%s) - $1"
if [[ $erotus > 60 ]]
then
  aika=$(echo "scale=2; "$erotus"/60" | bc)
  echo "Total process took "$aika" minutes"
else
  echo "Total process took "$erotus" seconds"
fi
} 

#Runs endless loop untill program is down   
killc () {
while [ "$a" != "0" ]
do
if echo "$(ps -C $1)" | grep -q $1
   then
   #echo "Killing $1"
   killall -9 $1
else
   a=0
fi
done
}

svn_mythtv=http://svn.mythtv.org/svn/branches/release-0-20-fixes/mythtv
svn_myththemes=http://svn.mythtv.org/svn/branches/release-0-20-fixes/myththemes
svn_mythplugins=http://svn.mythtv.org/svn/branches/release-0-20-fixes/mythplugins
valid_user=mythtv

mythtv_options="--enable-dvb --prefix=/usr"
myththemes_options="--prefix=/usr"
mythplugins_options="--prefix=/usr"

clear

echo "#########################################################################################"
echo "#         Following script will compile mythtv from svn.                                #"
echo "#       Run this in directory where keep your mythtv source                             #"
echo "#########################################################################################"
echo "#                      ***Current settings are****                                      #"
echo "# mythtv source      = $svn_mythtv          "
echo "# mythplugins source = $svn_mythplugins"
echo "# myththemes source  = $svn_myththemes  "
echo "# gcc version        = $(gcc -dumpversion) "
echo "#"
echo "#                      ***Current configure options***"
echo "# mythtv               $mythtv_options "
echo "# mytplugins           $mythplugins_options "
echo "# myththemes           $myththemes_options "
echo " "
echo "#for force mode run this with -f"
force_mode=${1//"-"/}
vastus=s
while [ "$vastus" != "y" ]
do
echo "Do you wish to continue (y/n)"
read vastus 
 if [ $vastus = "n" ] 
    then
    exit 0
 fi     
done
unset vastus

clear

#echo "Now checking if everything is right...."
draw_box 0 4
if bas_check $valid_user
 then 
 echo "Everything seems to be right."
 else 
 echo exiting...
 exit
fi

echo "Install of mythtv requires root previgles do you wish to login as root? (y/n)"

vastus=s
while [ "$vastus" != "y" ]
do
read a
case "$a" in
  [Yy] )  vastus=y && no_root=0 ;;
  [Nn] )  no_root=2 && vastus=y ;;
  *    ) echo "Give 'y' or 'n'" ;;
esac 
done

time=$(date +%s)
#echo "TIMER STARTED!"
draw_box 0 1

#echo "Checking if sources need to be downloaded or just updated"
draw_box 1 20
if dir_check
 then 
  echo "good you have already downloaded it, updating ..."
   if svn_update mythtv $force_mode
   then
     mythtv_c=0
   fi
   if svn_update mythplugins $force_mode
   then
     mythplugins_c=0
   fi
   if svn_update myththemes $force_mode
   then
     myththemes_c=0
   fi
 else
   echo "Downloading svn"
   svn_get $svn_mythtv
   svn_get $svn_myththemes
   svn_get $svn_mythplugins
fi  
draw_box 2 40
 
if [ myththemes_c=0 ] || [ mythplugins_c=0 ] || [ mythtv_c=0 ]
then
  echo "Making backups..."
  if [ -d backups_$(date +%d.%m) ]
    then 
      rm -rf backups_$(date +%d.%m)_old > /dev/null
      mv backups_$(date +%d.%m) backups_$(date +%d.%m)_old
  fi
  mkdir backups_$(date +%d.%m)
  tar czvf backups_$(date +%d.%m)/mythlibs.tgz /usr/lib/libmyth* /usr/bin/myth* > /dev/null 2>/dev/null
#  mythbackup > /dev/null
  cp /usr/share/mythtv/mainmenu.xml backups_$(date +%d.%m) > /dev/null
  cp /usr/share/mythtv/optical_menu.xml backups_$(date +%d.%m) > /dev/null
fi

draw_box 3 50
echo "Now configuring, compiling and installing ( if you gave root previgles)"
cd mythtv
export QTDIR=/usr/share/qt3
cd ..
if compile_23 "$mythtv_options" mythtv $no_root $mythtv_c
  then
   draw_box 3 70
   if compile_23 "$mythplugins_options" mythplugins $no_root $mythplugins_c
     then
     draw_box 3 85
       if compile_23 "$myththemes_options" myththemes $no_root $myththemes_c
         then
         draw_box 3 100
         sudo /etc/init.d/mythtv-backend start
         echo "great you have succesfully installed mythtv"
         #sudo /etc/init.d/mythtv-frontend start
         timer $time
         exit 0
       else
         echo_err "failed to compile or install myththemes"
       fi
     else
       echo_err "failed to compile or install mythplugins"
   fi
  else
    echo_err "failed to compile or install mythtv. Leaving..."
    timer $time
    exit 2
fi