Advertisement
Guest User

prepare_install_2_5.sh

a guest
Oct 23rd, 2012
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.39 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # @author Bram van Oploo
  4. # @date 2012-10-06
  5. # @version 2.5.0
  6. #
  7.  
  8. THIS_FILE=$0
  9. SCRIPT_VERSION="2.5.0"
  10. VIDEO_DRIVER=""
  11. HOME_DIRECTORY="/home/xbmc/"
  12. TEMP_DIRECTORY=$HOME_DIRECTORY"temp/"
  13. ENVIRONMENT_FILE="/etc/environment"
  14. CRONTAB_FILE="/etc/crontab"
  15. DIST_UPGRADE_FILE="/etc/cron.d/dist_upgrade.sh"
  16. DIST_UPGRADE_LOG_FILE="/var/log/updates.log"
  17. XBMC_INIT_FILE="/etc/init.d/xbmc"
  18. XBMC_ADDONS_DIR=$HOME_DIRECTORY".xbmc/addons/"
  19. XBMC_USERDATA_DIR=$HOME_DIRECTORY".xbmc/userdata/"
  20. XBMC_KEYMAPS_DIR=$XBMC_USERDATA_DIR"keymaps/"
  21. XBMC_ADVANCEDSETTINGS_FILE=$XBMC_USERDATA_DIR"advancedsettings.xml"
  22. XBMC_INIT_CONF_FILE="/etc/init/xbmc.conf"
  23. XBMC_CUSTOM_EXEC="/usr/bin/runXBMC"
  24. UPSTART_JOB_FILE="/lib/init/upstart-job"
  25. XWRAPPER_FILE="/etc/X11/Xwrapper.config"
  26. GRUB_CONFIG_FILE="/etc/default/grub"
  27. GRUB_HEADER_FILE="/etc/grub.d/00_header"
  28. SYSTEM_LIMITS_FILE="/etc/security/limits.conf"
  29. INITRAMFS_SPLASH_FILE="/etc/initramfs-tools/conf.d/splash"
  30. INITRAMFS_MODULES_FILE="/etc/initramfs-tools/modules"
  31. XWRAPPER_CONFIG_FILE="/etc/X11/Xwrapper.config"
  32. REMOTE_WAKEUP_RULS_FILE="/etc/udev/rules.d/90-enable-remote-wakeup.rules"
  33. SYSCTL_CONF_FILE="/etc/sysctl.conf"
  34. POWERMANAGEMENT_DIR="/var/lib/polkit-1/localauthority/50-local.d/"
  35. DOWNLOAD_URL="https://github.com/Bram77/xbmc-ubuntu-minimal/raw/master/12.10/download/"
  36. XBMC_PPA="ppa:wsnipex/xbmc-xvba"
  37. HTS_TVHEADEND_PPA="ppa:jabbors/hts-stable"
  38. OSCAM_PPA="ppa:oscam/ppa"
  39.  
  40. LOG_FILE=$HOME_DIRECTORY"xbmc_installation.log"
  41. DIALOG_WIDTH=70
  42. SCRIPT_TITLE="XBMC installation script v$SCRIPT_VERSION for Ubuntu 12.10 by Bram van Oploo :: bram@sudo-systems.com :: www.sudo-systems.com"
  43.  
  44. GFX_CARD=$(lspci |grep VGA |awk -F: {' print $3 '} |awk {'print $1'})
  45.  
  46. ## ------ START functions ---------
  47.  
  48. function showInfo()
  49. {
  50. CUR_DATE=$(date +%Y-%m-%d" "%H:%M)
  51. echo "$CUR_DATE - INFO :: $@" >> $LOG_FILE
  52. dialog --title "Installing & configuring..." --backtitle "$SCRIPT_TITLE" --infobox "\n$@" 5 $DIALOG_WIDTH
  53. }
  54.  
  55. function showError()
  56. {
  57. CUR_DATE=$(date +%Y-%m-%d" "%H:%M)
  58. echo "$CUR_DATE - ERROR :: $@" >> $LOG_FILE
  59. dialog --title "Error" --backtitle "$SCRIPT_TITLE" --msgbox "$@" 8 $DIALOG_WIDTH
  60. }
  61.  
  62. function showDialog()
  63. {
  64. dialog --title "XBMC installation script" \
  65. --backtitle "$SCRIPT_TITLE" \
  66. --msgbox "\n$@" 12 $DIALOG_WIDTH
  67. }
  68.  
  69. function update()
  70. {
  71. sudo apt-get update > /dev/null 2>&1
  72. }
  73.  
  74. function createFile()
  75. {
  76. FILE="$1"
  77. IS_ROOT="$2"
  78. REMOVE_IF_EXISTS="$3"
  79.  
  80. if [ -e "$FILE" ] && [ "$REMOVE_IF_EXISTS" == "1" ]; then
  81. sudo rm "$FILE" > /dev/null
  82. else
  83. if [ "$IS_ROOT" == "0" ]; then
  84. touch "$FILE" > /dev/null
  85. else
  86. sudo touch "$FILE" > /dev/null
  87. fi
  88. fi
  89. }
  90.  
  91. function createDirectory()
  92. {
  93. DIRECTORY="$1"
  94. GOTO_DIRECTORY="$2"
  95. IS_ROOT="$3"
  96.  
  97. if [ ! -d "$DIRECTORY" ];
  98. then
  99. if [ "$IS_ROOT" == "0" ]; then
  100. mkdir -p "$DIRECTORY" > /dev/null 2>&1
  101. else
  102. sudo mkdir -p "$DIRECTORY" > /dev/null 2>&1
  103. fi
  104. fi
  105.  
  106. if [ "$GOTO_DIRECTORY" == "1" ];
  107. then
  108. cd $DIRECTORY
  109. fi
  110. }
  111.  
  112. function handleFileBackup()
  113. {
  114. FILE="$1"
  115. BACKUP="$1.bak"
  116. IS_ROOT="$2"
  117. DELETE_ORIGINAL="$3"
  118.  
  119. if [ -e "$BACKUP" ];
  120. then
  121. if [ "$IS_ROOT" == "1" ]; then
  122. sudo rm "$FILE" > /dev/null 2>&1
  123. sudo cp "$BACKUP" "$FILE" > /dev/null 2>&1
  124. else
  125. rm "$FILE" > /dev/null 2>&1
  126. cp "$BACKUP" "$FILE" > /dev/null 2>&1
  127. fi
  128. else
  129. if [ "$IS_ROOT" == "1" ]; then
  130. sudo cp "$FILE" "$BACKUP" > /dev/null 2>&1
  131. else
  132. cp "$FILE" "$BACKUP" > /dev/null 2>&1
  133. fi
  134. fi
  135.  
  136. if [ "$DELETE_ORIGINAL" == "1" ]; then
  137. sudo rm "$FILE" > /dev/null 2>&1
  138. fi
  139. }
  140.  
  141. function appendToFile()
  142. {
  143. FILE="$1"
  144. CONTENT="$2"
  145. IS_ROOT="$3"
  146.  
  147. if [ "$IS_ROOT" == "0" ]; then
  148. echo "$CONTENT" | tee -a "$FILE" > /dev/null 2>&1
  149. else
  150. echo "$CONTENT" | sudo tee -a "$FILE" > /dev/null 2>&1
  151. fi
  152. }
  153.  
  154. function addRepository()
  155. {
  156. REPOSITORY=$@
  157. KEYSTORE_DIR=$HOME_DIRECTORY".gnupg/"
  158. createDirectory "$KEYSTORE_DIR" 0 0
  159. sudo add-apt-repository -y $REPOSITORY > /dev/null 2>&1
  160.  
  161. if [ "$?" == "0" ]; then
  162. update
  163. showInfo "$REPOSITORY repository successfully added"
  164. echo 1
  165. else
  166. showError "Repository $REPOSITORY could not be added (error code $?)"
  167. echo 0
  168. fi
  169. }
  170.  
  171. function isPackageInstalled()
  172. {
  173. PACKAGE=$@
  174. sudo dpkg-query -l $PACKAGE > /dev/null 2>&1
  175.  
  176. if [ "$?" == "0" ]; then
  177. echo 1
  178. else
  179. echo 0
  180. fi
  181. }
  182.  
  183. function aptInstall()
  184. {
  185. PACKAGE=$@
  186. IS_INSTALLED=$(isPackageInstalled $PACKAGE)
  187.  
  188. if [ "$IS_INSTALLED" == "1" ]; then
  189. showInfo "Skipping installation of $PACKAGE. Already installed."
  190. echo 1
  191. else
  192. sudo apt-get -f install > /dev/null 2>&1
  193. sudo apt-get -y install $PACKAGE > /dev/null 2>&1
  194.  
  195. if [ "$?" == "0" ]; then
  196. showInfo "$PACKAGE successfully installed"
  197. echo 1
  198. else
  199. showError "$PACKAGE could not be installed (error code: $?)"
  200. echo 0
  201. fi
  202. fi
  203. }
  204.  
  205. function download()
  206. {
  207. URL="$@"
  208. wget -q "$URL" > /dev/null 2>&1
  209. }
  210.  
  211. function move()
  212. {
  213. SOURCE="$1"
  214. DESTINATION="$2"
  215. IS_ROOT="$3"
  216.  
  217. if [ -e "$SOURCE" ];
  218. then
  219. if [ "$IS_ROOT" == "0" ]; then
  220. mv "$SOURCE" "$DESTINATION" > /dev/null 2>&1
  221. else
  222. sudo mv "$SOURCE" "$DESTINATION" > /dev/null 2>&1
  223. fi
  224.  
  225. if [ "$?" == "0" ]; then
  226. echo 1
  227. else
  228. showError "$SOURCE could not be moved to $DESTINATION (error code: $?)"
  229. echo 0
  230. fi
  231. else
  232. showError "$SOURCE could not be moved to $DESTINATION because the file does not exist"
  233. echo 0
  234. fi
  235. }
  236.  
  237. ------------------------------
  238.  
  239. function installDependencies()
  240. {
  241. echo "-- Installing installation dependencies..."
  242. echo ""
  243.  
  244. sudo apt-get -y install dialog software-properties-common > /dev/null 2>&1
  245. }
  246.  
  247. function fixLocaleBug()
  248. {
  249. createFile $ENVIRONMENT_FILE
  250. handleFileBackup $ENVIRONMENT_FILE 1
  251. appendToFile $ENVIRONMENT_FILE "LC_MESSAGES=\"C\""
  252. appendToFile $ENVIRONMENT_FILE "LC_ALL=\"en_US.UTF-8\""
  253. showInfo "Locale environment bug fixed"
  254. }
  255.  
  256. function applyXbmcNiceLevelPermissions()
  257. {
  258. createFile $SYSTEM_LIMITS_FILE
  259. appendToFile $SYSTEM_LIMITS_FILE "xbmc - nice -1"
  260. showInfo "Allowed XBMC to prioritize threads"
  261. }
  262.  
  263. function addUserToRequiredGroups()
  264. {
  265. sudo adduser xbmc video > /dev/null 2>&1
  266. sudo adduser xbmc audio > /dev/null 2>&1
  267. sudo adduser xbmc users > /dev/null 2>&1
  268. showInfo "XBMC user added to required groups"
  269. }
  270.  
  271. function addXbmcPpa()
  272. {
  273. showInfo "Adding Wsnipex xbmc-xvba PPA..."
  274. IS_ADDED=$(addRepository "$XBMC_PPA")
  275. }
  276.  
  277. function distUpgrade()
  278. {
  279. showInfo "Updating Ubuntu with latest packages (may take a while)..."
  280. update
  281. sudo apt-get -y dist-upgrade > /dev/null 2>&1
  282. showInfo "Ubuntu installation updated"
  283. }
  284.  
  285. function installXinit()
  286. {
  287. showInfo "Installing xinit..."
  288. IS_INSTALLED=$(aptInstall xinit)
  289. }
  290.  
  291. function installPowerManagement()
  292. {
  293. showInfo "Installing power management packages..."
  294. createDirectory "$TEMP_DIRECTORY" 1 0
  295. IS_INSTALLED=$(aptInstall policykit-1)
  296. IS_INSTALLED=$(aptInstall upower)
  297. IS_INSTALLED=$(aptInstall udisks)
  298. IS_INSTALLED=$(aptInstall acpi-support)
  299. download $DOWNLOAD_URL"custom-actions.pkla"
  300. createDirectory "$POWERMANAGEMENT_DIR"
  301. IS_MOVED=$(move $TEMP_DIRECTORY"custom-actions.pkla" "$POWERMANAGEMENT_DIR")
  302. }
  303.  
  304. function installAudio()
  305. {
  306. showInfo "Installing audio packages....\n!! Please make sure no used channels are muted !!"
  307. IS_INSTALLED=$(aptInstall linux-sound-base)
  308. IS_INSTALLED=$(aptInstall alsa-base)
  309. IS_INSTALLED=$(aptInstall alsa-utils)
  310. IS_INSTALLED=$(aptInstall libasound2)
  311. sudo alsamixer
  312. }
  313.  
  314. function installLirc()
  315. {
  316. clear
  317. echo ""
  318. echo "Installing lirc..."
  319. echo ""
  320. echo "------------------"
  321. echo ""
  322.  
  323. sudo apt-get -y install lirc
  324.  
  325. if [ "$?" == "0" ]; then
  326. showInfo "Lirc successfully installed"
  327. else
  328. showError "Lirc could not be installed (error code: $?)"
  329. fi
  330. }
  331.  
  332. function allowRemoteWakeup()
  333. {
  334. showInfo "Allowing for remote wakeup (won't work for all remotes)..."
  335. createDirectory "$TEMP_DIRECTORY" 1 0
  336. handleFileBackup "$REMOTE_WAKEUP_RULS_FILE" 1 1
  337. download $DOWNLOAD_URL"remote_wakeup_rules"
  338.  
  339. if [ -e $TEMP_DIRECTORY"remote_wakeup_rules" ]; then
  340. sudo mv $TEMP_DIRECTORY"remote_wakeup_rules" "$REMOTE_WAKEUP_RULS_FILE" > /dev/null 2>&1
  341. showInfo "Remote wakeup rules successfully applied"
  342. else
  343. showError "Remote wakeup rules could not be downloaded"
  344. fi
  345. }
  346.  
  347. function installTvHeadend()
  348. {
  349. showInfo "Adding jabbors hts-stable PPA..."
  350. addRepository "$HTS_TVHEADEND_PPA"
  351.  
  352. clear
  353. echo ""
  354. echo "Installing tvheadend..."
  355. echo ""
  356. echo "------------------"
  357. echo ""
  358.  
  359. sudo apt-get -y install tvheadend
  360.  
  361. if [ "$?" == "0" ]; then
  362. showInfo "TvHeadend successfully installed"
  363. else
  364. showError "TvHeadend could not be installed (error code: $?)"
  365. fi
  366. }
  367.  
  368. function installOscam()
  369. {
  370. showInfo "Adding oscam PPA..."
  371. addRepository "$OSCAM_PPA"
  372.  
  373. showInfo "Installing oscam..."
  374. IS_INSTALLED=$(aptInstall oscam-svn)
  375. }
  376.  
  377. function installXbmc()
  378. {
  379. showInfo "Installing XBMC..."
  380. IS_INSTALLED=$(aptInstall xbmc)
  381. }
  382.  
  383. function enableDirtyRegionRendering()
  384. {
  385. showInfo "Enabling XBMC dirty region rendering..."
  386. createDirectory "$TEMP_DIRECTORY" 1 0
  387. handleFileBackup $XBMC_ADVANCEDSETTINGS_FILE 0 1
  388. download $DOWNLOAD_URL"dirty_region_rendering.xml"
  389. createDirectory "$XBMC_USERDATA_DIR" 0 0
  390. IS_MOVED=$(move $TEMP_DIRECTORY"dirty_region_rendering.xml" "$XBMC_ADVANCEDSETTINGS_FILE")
  391.  
  392. if [ "$IS_MOVED" == "1" ]; then
  393. showInfo "XBMC dirty region rendering enabled"
  394. else
  395. showError "XBMC dirty region rendering could not be enabled"
  396. fi
  397. }
  398.  
  399. function installXbmcAddonRepositoriesInstaller()
  400. {
  401. showInfo "Installing Addon Repositories Installer addon..."
  402. createDirectory "$TEMP_DIRECTORY" 1 0
  403. download $DOWNLOAD_URL"plugin.program.repo.installer-1.0.5.tar.gz"
  404. createDirectory "$XBMC_ADDONS_DIR" 0 0
  405.  
  406. if [ -e $TEMP_DIRECTORY"plugin.program.repo.installer-1.0.5.tar.gz" ]; then
  407. tar -xvzf $TEMP_DIRECTORY"plugin.program.repo.installer-1.0.5.tar.gz" -C "$XBMC_ADDONS_DIR" > /dev/null 2>&1
  408.  
  409. if [ "$?" == "0" ]; then
  410. showInfo "Addon Repositories Installer addon successfully installed"
  411. else
  412. showError "Addon Repositories Installer addon could not be installed (error code: $?)"
  413. fi
  414. else
  415. showError "Addon Repositories Installer addon could not be downloaded"
  416. fi
  417. }
  418.  
  419. function configureAtiDriver()
  420. {
  421. sudo aticonfig --initial -f > /dev/null 2>&1
  422. sudo aticonfig --sync-vsync=on > /dev/null 2>&1
  423. sudo aticonfig --set-pcs-u32=MCIL,HWUVD_H264Level51Support,1 > /dev/null 2>&1
  424. }
  425.  
  426. function disbaleAtiUnderscan()
  427. {
  428. sudo kill $(pidof X) > /dev/null 2>&1
  429. sudo aticonfig --set-pcs-val=MCIL,DigitalHDTVDefaultUnderscan,0 > /dev/null 2>&1
  430. showInfo "Underscan successfully disabled"
  431. }
  432.  
  433. function enableAtiUnderscan()
  434. {
  435. sudo kill $(pidof X) > /dev/null 2>&1
  436. sudo aticonfig --set-pcs-val=MCIL,DigitalHDTVDefaultUnderscan,1 > /dev/null 2>&1
  437. showInfo "Underscan successfully enabled"
  438. }
  439.  
  440. function installVideoDriver()
  441. {
  442. showInfo "Installing $GFX_CARD video drivers (may take a while)..."
  443.  
  444. if [[ $GFX_CARD == NVIDIA ]]; then
  445. VIDEO_DRIVER="nvidia-current"
  446. elif [[ $GFX_CARD == ATI ]] || [[ $GFX_CARD == AMD ]]; then
  447. VIDEO_DRIVER="fglrx"
  448. elif [[ $GFX_CARD == INTEL ]]; then
  449. VIDEO_DRIVER="i965-va-driver"
  450. else
  451. cleanUp
  452. clear
  453. echo ""
  454. echo "$(tput setaf 1)$(tput bold)Installation aborted...$(tput sgr0)"
  455. echo "$(tput setaf 1)Only NVIDIA, ATI/AMD or INTEL videocards are supported. Please install a compatible videocard and run the script again.$(tput sgr0)"
  456. echo ""
  457. echo "$(tput setaf 1)You have a $GFX_CARD videocard.$(tput sgr0)"
  458. echo ""
  459. exit
  460. fi
  461.  
  462. IS_INSTALLED=$(aptInstall $VIDEO_DRIVER)
  463.  
  464. if [ "$IS_INSTALLED" == "1"]; then
  465. if [ "$GFX_CARD" == "ATI" ] || [ "$GFX_CARD" == "AMD" ]; then
  466. configureAtiDriver
  467.  
  468. dialog --title "Disable underscan" \
  469. --backtitle "$SCRIPT_TITLE" \
  470. --yesno "Do you want to disable underscan (removes black borders)? Do this only if you're sure you need it!" 7 $DIALOG_WIDTH
  471.  
  472. RESPONSE=$?
  473. case ${RESPONSE//\"/} in
  474. 0)
  475. disableAtiUnderscan
  476. ;;
  477. 1)
  478. enableAtiUnderscan
  479. ;;
  480. 255)
  481. showInfo "ATI underscan configuration skipped"
  482. ;;
  483. esac
  484. fi
  485.  
  486. showInfo "$GFX_CARD video drivers successfully installed and configured"
  487. fi
  488. }
  489.  
  490. function installAutomaticDistUpgrade()
  491. {
  492. showInfo "Enabling automatic system upgrade..."
  493. createDirectory "$TEMP_DIRECTORY" 1 0
  494. download $DOWNLOAD_URL"dist_upgrade.sh"
  495. IS_MOVED=$(move $TEMP_DIRECTORY"dist_upgrade.sh" "$DIST_UPGRADE_FILE" 1)
  496.  
  497. if [ "$IS_MOVED" == "1" ]; then
  498. IS_INSTALLED=$(aptInstall cron)
  499. sudo chmod +x "$DIST_UPGRADE_FILE" > /dev/null 2>&1
  500. handleFileBackup "$CRONTAB_FILE" 1
  501. appendToFile "$CRONTAB_FILE" "0 */4 * * * root $DIST_UPGRADE_FILE >> $DIST_UPGRADE_LOG_FILE"
  502. else
  503. showError "Automatic system upgrade interval could not be enabled"
  504. fi
  505. }
  506.  
  507. function removeAutorunFiles()
  508. {
  509. if [ -e "$XBMC_INIT_FILE" ]; then
  510. showInfo "Removing existing autorun script..."
  511. sudo update-rc.d xbmc remove > /dev/null 2>&1
  512. sudo rm "$XBMC_INIT_FILE" > /dev/null 2>&1
  513.  
  514. if [ -e "$XBMC_INIT_CONF_FILE" ]; then
  515. sudo rm "$XBMC_INIT_CONF_FILE" > /dev/null 2>&1
  516. fi
  517.  
  518. if [ -e "$XBMC_CUSTOM_EXEC" ]; then
  519. sudo rm "$XBMC_CUSTOM_EXEC" > /dev/null 2>&1
  520. fi
  521.  
  522. showInfo "Old autorun script successfully removed"
  523. fi
  524. }
  525.  
  526. function installXbmcInitScript()
  527. {
  528. removeAutorunFiles
  529. showInfo "Installing XBMC init.d autorun support..."
  530. createDirectory "$TEMP_DIRECTORY" 1 0
  531. download $DOWNLOAD_URL"xbmc_init_script"
  532.  
  533. if [ -e $TEMP_DIRECTORY"xbmc_init_script" ]; then
  534. if [ -e $XBMC_INIT_FILE ]; then
  535. sudo rm $XBMC_INIT_FILE > /dev/null 2>&1
  536. fi
  537.  
  538. IS_MOVED=$(move $TEMP_DIRECTORY"xbmc_init_script" "$XBMC_INIT_FILE")
  539.  
  540. if [ "$IS_MOVED" == "1" ]; then
  541. sudo chmod a+x "$XBMC_INIT_FILE" > /dev/null 2>&1
  542. sudo update-rc.d xbmc defaults > /dev/null 2>&1
  543.  
  544. if [ "$?" == "0" ]; then
  545. showInfo "XBMC autorun succesfully configured"
  546. else
  547. showError "XBMC autorun script could not be activated (error code: $?)"
  548. fi
  549. else
  550. showError "XBMC autorun script could not be installed"
  551. fi
  552. else
  553. showError "Download of XBMC autorun script failed"
  554. fi
  555. }
  556.  
  557. function installXbmcRunFile()
  558. {
  559. showInfo "Installing custom XBMC startup executable..."
  560. createDirectory "$TEMP_DIRECTORY" 1 0
  561. download $DOWNLOAD_URL"xbmc_run_script"
  562.  
  563. if [ -e $TEMP_DIRECTORY"xbmc_run_script" ]; then
  564. IS_MOVED=$(move $TEMP_DIRECTORY"xbmc_run_script" "$XBMC_CUSTOM_EXEC")
  565.  
  566. if [ "$IS_MOVED" == "1" ]; then
  567. sudo chmod a+x "$XBMC_CUSTOM_EXEC" > /dev/null 2>&1
  568. showInfo "Installation of custom XBMC startup executable successfull"
  569. else
  570. showError "Installation of custom XBMC startup executable failed"
  571. fi
  572. else
  573. showError "Download of custom XBMC startup executable failed"
  574. fi
  575. }
  576.  
  577. function installXbmcUpstartScript()
  578. {
  579. removeAutorunFiles
  580. showInfo "Installing XBMC upstart autorun support..."
  581. createDirectory "$TEMP_DIRECTORY" 1 0
  582. download $DOWNLOAD_URL"xbmc_upstart_script"
  583.  
  584. if [ -e $TEMP_DIRECTORY"xbmc_upstart_script" ]; then
  585. if [ -e "$XBMC_INIT_CONF_FILE" ]; then
  586. sudo rm "$XBMC_INIT_CONF_FILE" > /dev/null &2>1
  587. fi
  588.  
  589. IS_MOVED=$(move $TEMP_DIRECTORY"xbmc_upstart_script" "$XBMC_INIT_CONF_FILE")
  590.  
  591. if [ "$IS_MOVED" == "1" ]; then
  592. sudo ln -s "$UPSTART_JOB_FILE" "$XBMC_INIT_FILE" > /dev/null 2>&1
  593. installXbmcRunFile
  594. else
  595. showError "XBMC upstart configuration failed"
  596. fi
  597. else
  598. showError "Download of XBMC upstart configuration file failed"
  599. fi
  600. }
  601.  
  602. function installNyxBoardKeymap()
  603. {
  604. showInfo "Applying Pulse-Eight Motorola NYXboard advanced keymap..."
  605. createDirectory "$TEMP_DIRECTORY" 1 0
  606. download $DOWNLOAD_URL"nyxboard.tar.gz"
  607. createDirectory "$XBMC_KEYMAPS_DIR" 0 0
  608.  
  609. if [ -e $XBMC_KEYMAPS_DIR"keyboard.xml" ]; then
  610. handleFileBackup $XBMC_KEYMAPS_DIR"keyboard.xml" 0 1
  611. fi
  612.  
  613. if [ -e $TEMP_DIRECTORY"nyxboard.tar.gz" ]; then
  614. tar -xvzf $TEMP_DIRECTORY"nyxboard.tar.gz" -C "$XBMC_KEYMAPS_DIR" > /dev/null 2>&1
  615.  
  616. if [ "$?" == "0" ]; then
  617. showInfo "Pulse-Eight Motorola NYXboard advanced keymap successfully applied"
  618. else
  619. showError "Pulse-Eight Motorola NYXboard advanced keymap could not be applied (error code: $?)"
  620. fi
  621. else
  622. showError "Pulse-Eight Motorola NYXboard advanced keymap could not be downloaded"
  623. fi
  624. }
  625.  
  626. function installXbmcBootScreen()
  627. {
  628. showInfo "Installing XBMC boot screen (please be patient)..."
  629. #IS_INSTALLED=$(aptInstall v86d)
  630. #IS_INSTALLED=$(aptInstall plymouth-label)
  631. sudo apt-get install plymouth-label v86d > /dev/null
  632. createDirectory "$TEMP_DIRECTORY" 1 0
  633. download $DOWNLOAD_URL"plymouth-theme-xbmc-logo.deb"
  634.  
  635. if [ -e $TEMP_DIRECTORY"plymouth-theme-xbmc-logo.deb" ]; then
  636. sudo dpkg -i $TEMP_DIRECTORY"plymouth-theme-xbmc-logo.deb" > /dev/null
  637. handleFileBackup "$INITRAMFS_SPLASH_FILE" 1 1
  638. createFile "$INITRAMFS_SPLASH_FILE" 1 1
  639. appendToFile "$INITRAMFS_SPLASH_FILE" "FRAMEBUFFER=y"
  640. showInfo "XBMC boot screen successfully installed"
  641. else
  642. showError "Download of XBMC boot screen package failed"
  643. fi
  644. }
  645.  
  646. function applyScreenResolution()
  647. {
  648. RESOLUTION="$1"
  649.  
  650. showInfo "Applying bootscreen resolution (will take a minute or so)..."
  651. handleFileBackup "$GRUB_HEADER_FILE" 1 0
  652. sudo sed -i '/gfxmode=/ a\ set gfxpayload=keep' "$GRUB_HEADER_FILE" > /dev/null 2>&1
  653.  
  654. handleFileBackup "$GRUB_CONFIG_FILE" 1 0
  655. appendToFile "$GRUB_CONFIG_FILE" "GRUB_CMDLINE_LINUX_DEFAULT=\"quiet splash nomodeset video=uvesafb:mode_option=$RESOLUTION-24,mtrr=3,scroll=ywrap\""
  656. appendToFile "$GRUB_CONFIG_FILE" "GRUB_GFXMODE=$RESOLUTION"
  657.  
  658. handleFileBackup "$INITRAMFS_MODULES_FILE" 1 0
  659. appendToFile "$INITRAMFS_MODULES_FILE" "uvesafb mode_option=$RESOLUTION-24 mtrr=3 scroll=ywrap"
  660.  
  661. sudo update-grub > /dev/null 2>&1
  662. sudo update-initramfs -u > /dev/null
  663.  
  664. if [ "$?" == "0" ]; then
  665. showInfo "Bootscreen resolution successfully applied"
  666. else
  667. showError "Bootscreen resolution could not be applied"
  668. fi
  669. }
  670.  
  671. function installLmSensors()
  672. {
  673. showInfo "Installing temperature monitoring package (apply all defaults)..."
  674. aptInstall lm-sensors
  675. clear
  676. echo ""
  677. echo "$(tput setaf 2)$(tput bold)INSTALLATION INFO: Please confirm all questions with ENTER (applying the suggested option)."
  678. echo "$(tput setaf 2)The XBMC installation will continue automatically when finished.$(tput sgr0)"
  679. echo ""
  680. echo ""
  681.  
  682. sudo sensors-detect
  683.  
  684. if [ ! -e "$XBMC_ADVANCEDSETTINGS_FILE" ]; then
  685. createDirectory "$TEMP_DIRECTORY" 1 0
  686. download $DOWNLOAD_URL"temperature_monitoring.xml"
  687. createDirectory "$XBMC_USERDATA_DIR" 0 0
  688. IS_MOVED=$(move $TEMP_DIRECTORY"temperature_monitoring.xml" "$XBMC_ADVANCEDSETTINGS_FILE")
  689.  
  690. if [ "$IS_MOVED" == "1" ]; then
  691. showInfo "Temperature monitoring successfully enabled in XBMC"
  692. else
  693. showError "Temperature monitoring could not be enabled in XBMC"
  694. fi
  695. fi
  696.  
  697. showInfo "Temperature monitoring successfully configured"
  698. }
  699.  
  700. function reconfigureXServer()
  701. {
  702. showInfo "Configuring X-server..."
  703. handleFileBackup "$XWRAPPER_FILE" 1
  704. createFile "$XWRAPPER_FILE" 1 1
  705. appendToFile "$XWRAPPER_FILE" "allowed_users=anybody"
  706. showInfo "X-server successfully configured"
  707. }
  708.  
  709. function selectXbmcStartupMethod()
  710. {
  711. cmd=(dialog --backtitle "XBMC autorun method"
  712. --radiolist "Please select the method used to start XBMC (default recommended):"
  713. 15 $DIALOG_WIDTH 3)
  714.  
  715. options=(1 "init.d" on
  716. 2 "upstart (experimental)" off)
  717.  
  718. choice=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
  719.  
  720. case ${choice//\"/} in
  721. 1)
  722. installXbmcInitScript
  723. ;;
  724. 2)
  725. installXbmcUpstartScript
  726. ;;
  727. *)
  728. selectStartupMethod
  729. ;;
  730. esac
  731. }
  732.  
  733. function selectXbmcTweaks()
  734. {
  735. cmd=(dialog --title "Optional XBMC tweaks and additions"
  736. --backtitle "$SCRIPT_TITLE"
  737. --checklist "Plese select to install or apply:"
  738. 15 $DIALOG_WIDTH 6)
  739.  
  740. options=(1 "Enable dirty region rendering (improved performance)" on
  741. 2 "Enable temperature monitoring (confirm with ENTER)" on
  742. 3 "Install Addon Repositories Installer addon" on
  743. 4 "Apply improved Pulse-Eight Motorola NYXboard keymap" off)
  744.  
  745. choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
  746.  
  747. for choice in $choices
  748. do
  749. case ${choice//\"/} in
  750. 1)
  751. enableDirtyRegionRendering
  752. ;;
  753. 2)
  754. installLmSensors
  755. ;;
  756. 3)
  757. installXbmcAddonRepositoriesInstaller
  758. ;;
  759. 4)
  760. installNyxBoardKeymap
  761. ;;
  762. esac
  763. done
  764. }
  765.  
  766. function selectScreenResolution()
  767. {
  768. cmd=(dialog --backtitle "Select bootscreen resolution (required)"
  769. --radiolist "Please select your screen resolution, or the one sligtly lower then it can handle if an exact match isn't availabel:"
  770. 15 $DIALOG_WIDTH 6)
  771.  
  772. options=(1 "720 x 480 (NTSC)" off
  773. 2 "720 x 576 (PAL)" off
  774. 3 "1280 x 720 (HD Ready)" off
  775. 4 "1366 x 768 (HD Ready)" on
  776. 5 "1920 x 1080 (Full HD)" off)
  777.  
  778. choice=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
  779.  
  780. case ${choice//\"/} in
  781. 1)
  782. applyScreenResolution "720x480"
  783. ;;
  784. 2)
  785. applyScreenResolution "720x576"
  786. ;;
  787. 3)
  788. applyScreenResolution "1280x720"
  789. ;;
  790. 4)
  791. applyScreenResolution "1366x768"
  792. ;;
  793. 5)
  794. applyScreenResolution "1920x1080"
  795. ;;
  796. *)
  797. selectScreenResolution
  798. ;;
  799. esac
  800. }
  801.  
  802. function selectAdditionalPackages()
  803. {
  804. cmd=(dialog --title "Other optional packages and features"
  805. --backtitle "$SCRIPT_TITLE"
  806. --checklist "Plese select to install:"
  807. 15 $DIALOG_WIDTH 6)
  808.  
  809. options=(1 "Lirc (IR remote support)" off
  810. 2 "Hts tvheadend (live TV backend)" off
  811. 3 "Oscam (live HDTV decryption tool)" off
  812. 4 "Automatic upgrades (every 4 hours)" off)
  813.  
  814. choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
  815.  
  816. for choice in $choices
  817. do
  818. case ${choice//\"/} in
  819. 1)
  820. installLirc
  821. ;;
  822. 2)
  823. installTvHeadend
  824. ;;
  825. 3)
  826. installOscam
  827. ;;
  828. 4)
  829. installAutomaticDistUpgrade
  830. ;;
  831. esac
  832. done
  833. }
  834.  
  835. function optimizeInstallation()
  836. {
  837. showInfo "Optimizing installation..."
  838. sudo service apparmor stop > /dev/null &2>1
  839. sudo service apparmor teardown > /dev/null &2>1
  840. sudo apt-get -y remove apparmor > /dev/null &2>1
  841. handleFileBackup "$SYSCTL_CONF_FILE" 1 0
  842. createFile "$SYSCTL_CONF_FILE" 1 0
  843. appendToFile "$SYSCTL_CONF_FILE" "dev.cdrom.lock=0"
  844. appendToFile "$SYSCTL_CONF_FILE" "vm.swappiness=10"
  845. }
  846.  
  847. function cleanUp()
  848. {
  849. showInfo "Cleaning up..."
  850. sudo apt-get -y autoremove > /dev/null 2>&1
  851. sudo apt-get -y autoclean > /dev/null 2>&1
  852. sudo apt-get -y clean > /dev/null 2>&1
  853.  
  854. if [ -e "$TEMP_DIRECTORY" ]; then
  855. sudo rm -R "$TEMP_DIRECTORY" > /dev/null 2>&1
  856. fi
  857.  
  858. if [ -e "$HOME_DIRECTORY$THIS_FILE" ]; then
  859. rm "$HOME_DIRECTORY$THIS_FILE" > /dev/null 2>&1
  860. fi
  861. }
  862.  
  863. function rebootMachine()
  864. {
  865. showInfo "Reboot system..."
  866. dialog --title "Installation complete" \
  867. --backtitle "$SCRIPT_TITLE" \
  868. --yesno "Do you want to reboot now?" 7 $DIALOG_WIDTH
  869.  
  870. case $? in
  871. 0)
  872. showInfo "Installation complete. Rebooting..."
  873. clear
  874. echo ""
  875. echo "Installation complete. Rebooting..."
  876. echo ""
  877. sudo reboot now > /dev/null 2>&1
  878. ;;
  879. 1)
  880. showInfo "Installation complete. Not rebooting."
  881. quit
  882. ;;
  883. 255)
  884. showInfo "Installation complete. Not rebooting."
  885. quit
  886. ;;
  887. esac
  888. }
  889.  
  890. function quit()
  891. {
  892. clear
  893. exit
  894. }
  895.  
  896. control_c()
  897. {
  898. cleanUp
  899. echo "Installation aborted..."
  900. quit
  901. }
  902.  
  903. ## ------- END functions -------
  904.  
  905. clear
  906.  
  907. createFile "$LOG_FILE" 0 1
  908.  
  909. echo ""
  910. installDependencies
  911. echo "Loading installer..."
  912. showDialog "Welcome to the XBMC minimal installation script. Some parts may take a while to install depending on your internet connection speed.\n\nPlease be patient..."
  913. trap control_c SIGINT
  914.  
  915. fixLocaleBug
  916. applyXbmcNiceLevelPermissions
  917. addUserToRequiredGroups
  918. addXbmcPpa
  919. distUpgrade
  920. installVideoDriver
  921. installXinit
  922. installXbmc
  923. selectXbmcStartupMethod
  924. installXbmcBootScreen
  925. selectScreenResolution
  926. reconfigureXServer
  927. installPowerManagement
  928. installAudio
  929. selectXbmcTweaks
  930. selectAdditionalPackages
  931. allowRemoteWakeup
  932. optimizeInstallation
  933. cleanUp
  934. rebootMachine
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement