### # Gentoox Magic functions # Copyright (C) Thomas "ShALLaX" Pedley (gentoox@shallax.com) # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ### ### # Welcome. ### welcomeToMagic() { magicHeader echo -en "${redtxt}" echo -e " WELCOME TO MAGIC " echo -e " PLEASE WAIT! " echo -en "${normaltxt}" echo -e " --------------------------------------------------------------------" echo -e "${bluetxt} PERFORMING FINAL TASKS${normaltxt}" magicFooter sleep 0.5 } ### # Prelaunch complete ### prelaunchComplete() { magicHeader echo -en "${redtxt}" echo -e " WELCOME TO MAGIC " echo -e " PLEASE WAIT! " echo -en "${normaltxt}" echo -e " --------------------------------------------------------------------" echo -e "${greentxt} ALL PRELAUNCH TASKS COMPLETE${normaltxt}" magicFooter sleep 0.5 } ### # Display version. ### displayVersion() { magicHeader echo -e "${redtxt} Powered by ShAPAChE${normaltxt}" echo -e " --------------------------------------------------------------------" if [ -f /etc/gentoox_version ]; then if [ ! -z `cat /etc/gentoox_version | grep "home"` ]; then gentoox_edition="Home" gentoox_major=`cat /etc/gentoox_version | sed "s/home//"` gentoox_version="${redtxt}Gentoox ${bluetxt}${gentoox_edition} ${gentoox_major}" elif [ ! -z `cat /etc/gentoox_version | grep "pro"` ]; then gentoox_edition="Pro" gentoox_major=`cat /etc/gentoox_version | sed "s/pro//"` gentoox_version="${redtxt}Gentoox ${bluetxt}${gentoox_edition} ${gentoox_major}" else gentoox_version="${redtxt}an UNSUPPORTED version of Gentoox" fi else gentoox_version="${redtxt}an UNSUPPORTED version of Gentoox" fi echo -e " You are running ${gentoox_version}${normaltxt}" magicFooter echo -e "${redtxt} Patch serial: ${greentxt} ${gentooxpatchesversion}${normaltxt}" echo -e "${redtxt} wget: ${bluetxt} ${wget}${normaltxt}\n" cat ~/motd.gentoox rm -rf ~/motd.gentoox #echo -e "\n You are using mirror:${redtxt} $gentooxurl${normaltxt}" #echo -e " If downloads fail, try a different mirror (if available)" $important echo -en "\n ${greentxt}Press enter to continue...${normaltxt}" read clear $good } ### # Updating banner. ### updatingMagicDone() { magicHeader echo -en "${redtxt}" echo -e " UPDATING MAGIC SCRIPT ${normaltxt}- ${bluetxt}DONE " echo -e "${redtxt}" echo -en "${normaltxt}" echo -e " --------------------------------------------------------------------" echo -e "" $good magicFooter sleep 1 } ### # Downloading Patches ### downloadingPatches() { magicHeader echo -en "${redtxt}" echo -e " DOWNLOADING PATCH INFORMATION" echo -e " PLEASE WAIT! " echo -en "${normaltxt}" echo -e " --------------------------------------------------------------------" echo -en "${bluetxt}" echo -e " CURRENT LIMIT: ${limithuman}KBPS" echo -en "${normaltxt}" magicFooter } ### # The top of the magic banner. ### magicHeader() { echo -e "\n\n\n${redtxt} Gentoox Magic (c) ShALLaX ${normaltxt}(${bluetxt}gentoox@shallax.com${normaltxt})" echo -e "${normaltxt} Be sure to check ${bluetxt}http://gentoox.shallax.com${normaltxt} regularly for updates!" echo -e " --------------------------------------------------------------------" } ### # The tail of the magic banner. ### magicFooter() { echo -e " --------------------------------------------------------------------" echo -e "\n Gentoox is distributed under the GNU General Public License. \n\n\n" } ### # This warns about a deprecated version of Gentoox which magic may not be # compatible with. ### deprecatedWarning() { $important clear magicHeader echo -en "${redtxt}" echo -e " !!THIS VERSION OF GENTOOX MAY NOT BE COMPATIBLE WITH MAGIC ANYMORE!!" echo -e " !RUNNING MAGIC MAY CAUSE UNEXPECTED BEHAVIOUR OR EVEN A NON-BOOTING!" echo -e " !SYSTEM, PRESS CTRL-C TO CANCEL, OR PRESS ENTER TO CONTINUE AT YOUR!" echo -e " !! OWN RISK !!" echo -en "${normaltxt}" echo -e " --------------------------------------------------------------------" echo -en "${bluetxt}" echo -e " PLEASE UPGRADE TO $1 $2" echo -en "${normaltxt}" magicFooter ding read clear magicHeader echo -en "${redtxt}" echo -e " !! CONTINUING !!" echo -en "${normaltxt}" echo -e " --------------------------------------------------------------------" echo -e "" ding magicFooter $good } ### # This is basically a library of functions used throughout magic # such as failure routines, patch management... etc ### failCheck() { if [ $? != "0" ]; then echo -ne "\n${redtxt} !! " if [ $1 = "decompress" ]; then echo "Decompression failed." elif [ $1 = "download" ]; then echo "Download failed." elif [ $1 = "compile" ]; then echo "Compilation failed." elif [ $1 = "emerge" ]; then echo "Emerge failed." elif [ $1 = "unmerge" ]; then echo "Unmerge failed." elif [ $1 = "patch" ]; then echo "$2 patch failed." network elif [ $1 = "sync" ]; then echo "Sync failed." metadata network else echo "Failed because of an unknown error! Please report to gentoox@shallax.com" fi exit 1 fi } metadata() { echo " !! If the error occurred during 'Updating Portage cache', try" echo " !! running 'emerge --metadata' then re-running magic." } network() { echo " !! Check your network settings and try again." } doPatch() { $downloading cd ~/ && $wget --limit-rate=${limitrate} $gentooxurl/b0x/${filename} failCheck download $busy sh ~/${filename} failCheck patch ${friendlyname} } ding() { export dingcount="0" while [ $dingcount -ne 5 ]; do echo -en "\a" sleep 0.1 echo -en "\a" sleep 1 export dingcount=`expr $dingcount + 1` done } dots() { export dotcount="0" sleep 1 while [ $dotcount -ne 3 ]; do echo -n "." sleep 1 export dotcount=`expr $dotcount + 1` done echo "" } ### # magicUpdated function shows the update splash, then quits ### magicUpdated() { $important clear magicHeader echo -en "${redtxt}" echo -e " MAGIC HAS BEEN UPDATED " echo -e " MAGIC WILL NOW RESTART TO APPLY CHANGES. " echo -en "${normaltxt}" echo -e " --------------------------------------------------------------------" echo -e "" magicFooter ding $good rm -rf /tmp/.shutupled } ### # queryDatabase function - checks to see which patches are installed ### queryDatabase() { if [ ! -z `grep -m1 -i ${patchname} /etc/conf.d/magic-database 2> /dev/null` ]; then export patchinstalled="true" else export patchinstalled="false" fi chown root:root /etc/conf.d/magic-database chmod 600 /etc/conf.d/magic-database } ### # delDatabase function - removes a patch from the database ### delDatabase() { grep -vi `echo $patchname | sed "s/[0-9]//g"` /etc/conf.d/magic-database >> /etc/conf.d/magic-database.tmp mv /etc/conf.d/magic-database.tmp /etc/conf.d/magic-database chown root:root /etc/conf.d/magic-database chmod 600 /etc/conf.d/magic-database } ### # delDatabaseOld function - removes an old patch from the database ### delDatabaseOld() { export patchnameold=`echo $patchname | sed "s/[0-9]//g"` ### # If it was an old kernel, then delete the downloaded line too ### if [ $patchnameold == "kernel-patch" ]; then echo "Clearing out old kernel entries:" export i="22000" while [ $i -lt $kernelver ]; do ### # Re-formatted the kernel version line, so it needs to be advanced to this: ### if [ $i -eq 22017 ]; then export i="2422017" fi echo -n "$i of `expr $kernelver - 1`" echo -en "\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r" grep -vi kernel-downloaded${i} /etc/conf.d/magic-database >> /etc/conf.d/magic-database.tmp mv /etc/conf.d/magic-database.tmp /etc/conf.d/magic-database sleep 0.1 export i=`expr $i + 1` done ### # Get rid of all kernel 2.6.11 references ### grep -vi kernel-downloaded2611 /etc/conf.d/magic-database >> /etc/conf.d/magic-database.tmp mv /etc/conf.d/magic-database.tmp /etc/conf.d/magic-database chown root:root /etc/conf.d/magic-database chmod 600 /etc/conf.d/magic-database clear fi grep -vi $patchnameold /etc/conf.d/magic-database >> /etc/conf.d/magic-database.tmp mv /etc/conf.d/magic-database.tmp /etc/conf.d/magic-database chown root:root /etc/conf.d/magic-database chmod 600 /etc/conf.d/magic-database } ### # addDatabase function - adds a patch to the database ### addDatabase() { echo $patchname >> /etc/conf.d/magic-database chown root:root /etc/conf.d/magic-database chmod 600 /etc/conf.d/magic-database } ### # installedCheck function - generates output for available) ### installedCheck() { export patchcounter=`expr $patchcounter + 1` if [ $patchinstalled == "true" ]; then export patchstatus="${bluetxt}" else export patchstatus="${redtxt}" fi export patchver=`echo $patchname | sed "s/[A-z]//g" | sed "s/\-//g"` export patchname=`echo $patchname | sed "s/[0-9]//g"` export patchverold=`grep -m1 $patchname /etc/conf.d/magic-database | sed "s/[A-z]//g" | sed "s/\-//g"` if [ `echo ${#patchfriendly}` -gt 7 ]; then export tabulation="\t" else export tabulation="\t\t" fi if [ `echo ${#patchver}` -gt 3 ]; then export tabulation2="\t\t" else export tabulation2="\t\t\t" fi if [ ! -z $patchverold ]; then if [ `echo -en $patchver` -gt `echo -en $patchverold` ]; then export patchstatus="${greentxt}" export oldstatus="${redtxt}" fi if [ `echo -en $patchver` -eq `echo -en $patchverold` ]; then export patchstatus="${normaltxt}" export oldstatus="${normaltxt}" fi if [ `echo -en $patchver` -lt `echo -en $patchverold` ]; then export patchstatus="${bluetxt}" export oldstatus="${redtxt}" fi else export patchverold="${redtxt}None." export patchstatus="${greentxt}" fi echo -e " ${normaltxt}| ${patchstatus}${patchfriendly} $tabulation ${normaltxt}| ${patchstatus}${patchver}${normaltxt} ${tabulation2}| ${oldstatus}${patchverold}${tabulation2}${normaltxt}|" if [ $patchcounter = 17 ]; then echo -en "${normaltxt} More...\r\r\r\r\r\r\r\r\r\r\r\r" read -s echo -en "${normaltxt} \r\r\r\r\r\r\r\r\r\r\r\r" export patchcounter="0" fi } ### # kernelUpdate and xbvsetUpdate functions tell magic that either # the kernel or xbvset have been updated ### kernelUpdate() { echo "newkernel1" >> /etc/conf.d/magic-database chown root:root /etc/conf.d/magic-database chmod 600 /etc/conf.d/magic-database } xbvsetUpdate() { echo "xbvsetupdate1" >> /etc/conf.d/magic-database chown root:root /etc/conf.d/magic-database chmod 600 /etc/conf.d/magic-database } ### # Magic error ### magicError() { $error echo -e "${bluetxt}" echo -e " !! Note the error(s) above then ${redtxt}press enter to continue${bluetxt}. Submit the full" echo -n " !! error when posting a bug report OR I WILL IGNORE YOU" read echo -e "${redtxt}" echo "Magic encountered the above error(s), please try again later." echo -e "${bluetxt}" echo "Emerge/ Unmerge errors are problems with portage, please try resyncing or" echo "waiting before running magic again. Emerge errors are also common with" echo "UNSET CLOCKS! To set your clock, as root run: date MMDDhhmmYYYY" echo "" echo "Download errors are most likely to be Gentoox central server/ DNS errors" echo "and should be fixed almost immediately. If you get a download error, " echo "simply try running magic again straight away." echo "" echo "An 'Invalid selection' error means that your input to a question was not" echo "correct - please note that CaSe matters. If you receive an invalid" echo "selection error, please re-run magic and answer all questions correctly" echo "questions have valid answer syntax printed in brackets." echo "" echo "'Decompression Failed.' means that data got corrupted whilst downloading" echo "a compressed archive. Try running magic again to see if the problem" echo "corrects itself." echo -e "" echo -ne "${redtxt}Press enter to quit...${normaltxt}" read ### # Backup the magic-database file after running but failed ### cp -a /etc/conf.d/magic-database /etc/conf.d/magic.backup/magic-database-postmagic-fail_`date +%Y-%m-%d_%H%M.%S` 1> /dev/null 2> /dev/null exit 1 }