Guest User

Untitled

a guest
Jul 19th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.64 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. if [[ -n "$HEADER_Utils" ]]; then
  4. return 0
  5. fi
  6. HEADER_Utils=included
  7.  
  8. . /usr/pluto/bin/SQL_Ops.sh
  9. . /usr/pluto/bin/Config_Ops.sh
  10.  
  11. DEVICETEMPLATE_OnScreen_Orbiter=62
  12. DEVICEDATA_Use_OpenGL_effects=172
  13. DEVICEDATA_Use_alpha_blended_UI=169
  14. DEVICEDATA_PK_UI=104
  15.  
  16. function AddBookmark {
  17. return 0
  18. Url="$1"
  19. Name="$2"
  20.  
  21. [[ ! -f /home/public/bookmarks.html ]] || return 0
  22.  
  23. # Generate an id for this bookmark
  24. ID=$(echo "$Url" | sha1sum)
  25. ID='rdf:#$'${ID:0:6}
  26.  
  27. # Generate the bookmark entry
  28. Bookmark=' <DT><A HREF="'$Url'" ADD_DATE="1126869382" LAST_MODIFIED="1126869442" ID="'$ID'">'$Name'</A>'
  29. Bookmark=$(echo $Bookmark | sed 's/"/\\\"/g')
  30.  
  31. for BookmarksFile in /home/public/bookmarks.html /home/user_*/bookmarks.html ;do
  32. # See if the bookmark is already there
  33. if grep -q "ID=\"$ID\"" $BookmarksFile ;then
  34. continue
  35. fi
  36.  
  37. # Add the bookmark string to the file
  38. awk '
  39. BEGIN { HR=0 }
  40. HR==0 && /<HR>/ {print "'"$Bookmark"'"; HR=1}
  41. {print}
  42. ' $BookmarksFile > $BookmarksFile.$$
  43. mv $BookmarksFile.$$ $BookmarksFile
  44. done
  45.  
  46. }
  47.  
  48. function DelBookmark {
  49. return 0
  50. Url="$1"
  51. Name="$2"
  52.  
  53. [[ ! -f /home/public/bookmarks.html ]] || return 0
  54.  
  55. # Generate an id for this bookmark
  56. ID=$(echo "$Url" | sha1sum)
  57. ID='rdf:#$'${ID:0:6}
  58.  
  59. for BookmarksFile in /home/public/bookmarks.html /home/user_*/bookmarks.html ;do
  60. grep -v "ID=\"$ID\"" $BookmarksFile >> $BookmarksFile.$$
  61. mv $BookmarksFile.$$ $BookmarksFile
  62. done
  63. }
  64.  
  65. TranslateSerialPort()
  66. {
  67. local SearchFor="$1"
  68. local PCI USB
  69.  
  70. SerialPort=
  71. if [[ "$SearchFor" == pci* ]]; then
  72. if [[ -d /sys/class/tty ]]; then
  73. pushd /sys/class/tty &>/dev/null
  74. for dev in ttyUSB*/device ttyACM*/device; do
  75. id=$(readlink -f "$dev" | sed -r 's,^.*(pci.*)/usb[0-9]*/[0-9./-]*/[0-9]*-([0-9.]*):[0-9.]*(/ttyUSB[0-9]*)?$,\1+\2,g')
  76. if [[ "$id" == "$SearchFor" ]]; then
  77. SerialPort="/dev/$(dirname "$dev")"
  78. break;
  79. fi
  80. done
  81. popd &>/dev/null
  82. fi
  83. else
  84. SerialPort="$SearchFor"
  85. fi
  86.  
  87. builtin echo "$SerialPort"
  88. }
  89.  
  90. TranslateSoundCard()
  91. {
  92. local SoundCard="$1" AlsaCard=
  93. local PCI USB
  94. local Cards Card Dev
  95.  
  96. if [[ -d /sys/class/sound && "$SoundCard" == pci* ]]; then
  97. if [[ "$SoundCard" == *+* ]]; then
  98. PCI="${SoundCard%+*}"
  99. USB="${SoundCard#*+}"
  100. else
  101. PCI="${SoundCard}"
  102. USB=
  103. fi
  104. pushd /sys/class/sound &>/dev/null
  105. Cards=$(find -name 'controlC*')
  106. for Card in $Cards; do
  107. Card="${Card#./}"
  108. Dev=$(readlink "$Card/device"|cut -f3 -d/)
  109. if [[ -n "$USB" ]]; then
  110. if [[ "$Dev" == *"$PCI"*usb*"$USB:"* ]]; then
  111. AlsaCard="${Card#controlC}"
  112. break
  113. fi
  114. else
  115. if [[ "$PCI" == *"$Dev" ]]; then
  116. AlsaCard="${Card#controlC}"
  117. break
  118. fi
  119. fi
  120. done
  121. popd &>/dev/null
  122. fi
  123.  
  124. builtin echo "$AlsaCard"
  125. }
  126.  
  127. UseAlternativeLibs()
  128. {
  129. export LD_LIBRARY_PATH=/opt/libsdl/lib:/opt/libxine/lib:/opt/libsdl1.2-1.2.7+1.2.8cvs20041007/lib:/opt/linphone-1.3.5/lib
  130. }
  131.  
  132. function ListTemplates_Category {
  133. local FK_DeviceCategory_Parent="$1"
  134. local PK_DeviceTemplate_List=""
  135. local PK_DeviceCategory=""
  136. local PK_DeviceTemplate=""
  137.  
  138. R=$(RunSQL "SELECT PK_DeviceCategory FROM DeviceCategory WHERE FK_DeviceCategory_Parent = $FK_DeviceCategory_Parent")
  139. for PK_DeviceCategory in $R ;do
  140. PK_DeviceTemplate_List="$PK_DeviceTemplate_List $(ListTemplates_Category "$PK_DeviceCategory")"
  141. done
  142.  
  143. R=$(RunSQL "SELECT PK_DeviceTemplate FROM DeviceTemplate WHERE FK_DeviceCategory=$FK_DeviceCategory_Parent")
  144. for PK_DeviceTemplate in $R ;do
  145. PK_DeviceTemplate_List="$PK_DeviceTemplate_List $PK_DeviceTemplate"
  146. done
  147.  
  148. echo $PK_DeviceTemplate_List
  149. }
  150.  
  151.  
  152. FindDevice_Template()
  153. {
  154. local PK_Device_Parent="${1//\'}" FK_DeviceTemplate="${2//\'}" NoRecursion="$3" IncludeParent="$4" All="$5"
  155. local Limit Found=0
  156.  
  157. if [[ -z "$PK_Device_Parent" || -z "$FK_DeviceTemplate" ]]; then
  158. echo ""
  159. return 1
  160. fi
  161.  
  162. if [[ -z "$All" ]]; then
  163. Limit="LIMIT 1"
  164. fi
  165.  
  166. local i R Q
  167. if [[ "$PK_Device_Parent" == 0 ]]; then
  168. Q="
  169. SELECT PK_Device
  170. FROM Device
  171. WHERE FK_Device_ControlledVia IS NULL AND FK_DeviceTemplate IN ($FK_DeviceTemplate)
  172. $Limit
  173. "
  174. elif [[ -z "$IncludeParent" ]]; then
  175. Q="
  176. SELECT PK_Device
  177. FROM Device
  178. WHERE FK_Device_ControlledVia='$PK_Device_Parent' AND FK_DeviceTemplate IN ($FK_DeviceTemplate)
  179. $Limit
  180. "
  181. else
  182. Q="
  183. SELECT PK_Device
  184. FROM Device
  185. WHERE (FK_Device_ControlledVia='$PK_Device_Parent' OR PK_Device='$PK_Device_Parent') AND FK_DeviceTemplate IN ($FK_DeviceTemplate))
  186. $Limit
  187. "
  188. fi
  189. R="$(RunSQL "$Q")"
  190.  
  191. if [[ -n "$R" ]]; then
  192. echo "$R"
  193. fi
  194.  
  195. if [[ ( -z "$R" || -n "$All" ) && -z "$NoRecursion" ]]; then
  196. Q="SELECT PK_Device FROM Device WHERE FK_Device_ControlledVia='$PK_Device_Parent'"
  197. R="$(RunSQL "$Q")"
  198. for i in $R; do
  199. if FindDevice_Template "$i" "$FK_DeviceTemplate" "" "" "$All"; then
  200. if [[ -z "$All" ]]; then
  201. return 0
  202. else
  203. Found=1
  204. fi
  205. fi
  206. done
  207. else
  208. return 1
  209. fi
  210.  
  211. [[ "$Found" -eq 1 ]]
  212. return $?
  213. }
  214.  
  215. FindDevice_Category()
  216. {
  217. local PK_Device_Parent="${1//\'}" FK_DeviceCategory="${2//\'}" NoRecursion="$3" IncludeParent="$4" All="$5"
  218. local Limit Found=0
  219.  
  220. if [[ -z "$PK_Device_Parent" || -z "$FK_DeviceCategory" ]]; then
  221. echo ""
  222. return 1
  223. fi
  224.  
  225. if [[ -z "$All" ]]; then
  226. Limit="LIMIT 1"
  227. fi
  228.  
  229. local i R Q
  230. if [[ "$PK_Device_Parent" == 0 ]]; then
  231. Q="
  232. SELECT PK_Device
  233. FROM Device
  234. JOIN DeviceTemplate ON FK_DeviceTemplate=PK_DeviceTemplate
  235. WHERE FK_Device_ControlledVia IS NULL AND FK_DeviceCategory IN ($FK_DeviceCategory)
  236. $Limit
  237. "
  238. elif [[ -z "$IncludeParent" ]]; then
  239. Q="
  240. SELECT PK_Device
  241. FROM Device
  242. JOIN DeviceTemplate ON FK_DeviceTemplate=PK_DeviceTemplate
  243. WHERE FK_Device_ControlledVia='$PK_Device_Parent' AND FK_DeviceCategory IN ($FK_DeviceCategory)
  244. $Limit
  245. "
  246. else
  247. Q="
  248. SELECT PK_Device
  249. FROM Device
  250. JOIN DeviceTemplate ON FK_DeviceTemplate=PK_DeviceTemplate
  251. WHERE (FK_Device_ControlledVia='$PK_Device_Parent' OR PK_Device='$PK_Device_Parent') AND FK_DeviceCategory IN ($FK_DeviceCategory)
  252. $Limit
  253. "
  254. fi
  255. R="$(RunSQL "$Q")"
  256.  
  257. if [[ -n "$R" ]]; then
  258. echo "$R"
  259. fi
  260.  
  261. if [[ ( -z "$R" || -n "$All" ) && -z "$NoRecursion" ]]; then
  262. Q="SELECT PK_Device FROM Device WHERE FK_Device_ControlledVia='$PK_Device_Parent'"
  263. R="$(RunSQL "$Q")"
  264. for i in $R; do
  265. if FindDevice_Category "$i" "$FK_DeviceCategory" "" "" "$All"; then
  266. if [[ -z "$All" ]]; then
  267. return 0
  268. else
  269. Found=1
  270. fi
  271. fi
  272. done
  273. else
  274. return 1
  275. fi
  276.  
  277. [[ "$Found" -eq 1 ]]
  278. return $?
  279. }
  280.  
  281. # Get the device number for the parent of the given device
  282. # Returns: number or empty string
  283. GetDeviceParent()
  284. {
  285. local PK_Device="$1"
  286. Q="
  287. SELECT FK_Device_ControlledVia
  288. FROM Device
  289. WHERE PK_Device='$PK_Device'
  290. "
  291. local R=$(RunSQL "$Q")
  292.  
  293. if [[ "$R" == NULL ]]; then
  294. R=""
  295. fi
  296. echo "$R"
  297. }
  298.  
  299. # Delete a device and make its children top level
  300. # Does exactly the same thing as CMD_Delete_Device in General_Info_Plugin
  301. DeleteDevice()
  302. {
  303. local PK_Device="$1"
  304. local Q R
  305.  
  306. # Delete embedded devices
  307. Q="SELECT PK_Device FROM Device where FK_Device_RouteTo=$PK_Device"
  308. R=$(RunSQL "$Q")
  309. for Device in $R; do
  310. DeleteDevice "$Device"
  311. done
  312.  
  313. local -a Queries
  314. Queries=(
  315. "UPDATE Device SET FK_Device_ControlledVia=NULL WHERE FK_Device_ControlledVia=$PK_Device"
  316. "DELETE FROM Device WHERE PK_Device=$PK_Device"
  317. "DELETE FROM CommandGroup_Command WHERE FK_Device=$PK_Device"
  318. "DELETE FROM Device_Command WHERE FK_Device=$PK_Device"
  319. "DELETE FROM Device_CommandGroup WHERE FK_Device=$PK_Device"
  320. "DELETE FROM Device_DeviceData WHERE FK_Device=$PK_Device"
  321. "DELETE FROM Device_DeviceGroup WHERE FK_Device=$PK_Device"
  322. "DELETE FROM Device_Device_Related WHERE FK_Device=$PK_Device OR FK_Device_Related=$PK_Device"
  323. "DELETE FROM Device_EntertainArea WHERE FK_Device=$PK_Device"
  324. "DELETE FROM Device_HouseMode WHERE FK_Device=$PK_Device"
  325. "DELETE FROM Device_Orbiter WHERE FK_Device=$PK_Device"
  326. "DELETE FROM Device_StartupScript WHERE FK_Device=$PK_Device"
  327. "DELETE FROM Device_Users WHERE FK_Device=$PK_Device"
  328. "DELETE FROM Package_Device WHERE FK_Device=$PK_Device"
  329. "DELETE FROM PaidLicense WHERE FK_Device=$PK_Device"
  330. "DELETE FROM Device_Device_Pipe WHERE FK_Device_From=$PK_Device OR FK_Device_To=$PK_Device"
  331. "DELETE FROM PaidLicense WHERE FK_Device=$PK_Device"
  332. )
  333.  
  334. for Q in "${Queries[@]}"; do
  335. RunSQL "$Q"
  336. done
  337. }
  338.  
  339. XineConfSet()
  340. {
  341. local Setting="$1"
  342. local Value="$2"
  343. local XineConf="${3:-/etc/pluto/xine.conf}"
  344.  
  345. [[ -z "$Setting" || -z "$Value" ]] && return 1
  346.  
  347. if grep -qF "$Setting" "$XineConf"; then
  348. sed -i "s/^.*$Setting:.*$/$Setting:$Value/" "$XineConf"
  349. else
  350. echo "$Setting:$Value" >>"$XineConf"
  351. fi
  352. }
  353.  
  354. DeviceIsDisabled()
  355. {
  356. local PK_Device="$1"
  357. local R Q
  358.  
  359. [[ -z "$PK_Device" ]] && return 1
  360.  
  361. Q="SELECT COUNT(*) FROM Device WHERE PK_Device='$PK_Device' AND Disabled=0"
  362. R=$(RunSQL "$Q")
  363.  
  364. if [[ -n "$R" && "$R" -eq 0 ]]; then
  365. return 0 # Device is disabled or does not exist at all
  366. else
  367. return 1 # Device exists and is enabled
  368. fi
  369. }
  370.  
  371. FindInArray()
  372. {
  373. local Value="$1" Array i
  374. shift
  375. Array=("$@")
  376.  
  377. for ((i = 0; i < ${#Array[*]}; i++)); do
  378. if [[ "${Array[$i]}" == "$Value" ]]; then
  379. echo "$i"
  380. return 0
  381. fi
  382. done
  383. return 1
  384. }
  385.  
  386. FindInArray_Prefix()
  387. {
  388. local Value="$1" Array i
  389. shift
  390. Array=("$@")
  391.  
  392. for ((i = 0; i < ${#Array[*]}; i++)); do
  393. if [[ "${Array[$i]}" == "$Value"* ]]; then
  394. echo "$i"
  395. return 0
  396. fi
  397. done
  398. return 1
  399. }
  400.  
  401. # Verify that the given string is a valid IPv4
  402. ValidIP()
  403. {
  404. local IP="$1"
  405.  
  406. local IPn="[0-9]{1,3}"
  407. local IPpattern="^($IPn)\\.($IPn)\\.($IPn)\\.($IPn)$"
  408. local i Number
  409.  
  410. # Bash 3.1 requires $IPpattern to be quoted, otherwise it gives a syntax error
  411. # Bash 3.2 requires $IPpattern to be unquoted, otherwise it fails to match the pattern
  412. # Ubuntu has Bash 3.2
  413. if [[ ! "$IP" =~ $IPpattern ]]; then
  414. return 1
  415. fi
  416.  
  417. for ((i = 1; i <= 4; i++)); do
  418. Number="${BASH_REMATCH[$i]}"
  419. if ((Number < 0 || Number > 255)); then
  420. return 1
  421. fi
  422. done
  423.  
  424. return 0
  425. }
  426.  
  427. # Colors and bolds messages
  428. # '\E begin escape sequence
  429. # [XX; is the text color
  430. # XXm' is the background color
  431. # \033 is the an escape
  432. # [1m bold [0m unbold
  433. # "" around text '' around color
  434. # COLOR FOREGROUND BACKGROUND
  435. # black 30 40
  436. # red 31 41
  437. # green 32 42
  438. # yellow 33 43
  439. # blue 34 44
  440. # magenta 35 45
  441. # cyan 36 46
  442. # white 37 47
  443.  
  444. StatusMessage () {
  445. echo -e '\E[33;40m'"\033[1m $* \033[0m"
  446. }
  447. ErrorMessage () {
  448. echo -e '\E[33;41m'"\033[1m $* \033[0m"
  449. }
  450. NotifyMessage () {
  451. echo -e '\E[32;40m'"\033[1m $* \033[0m"
  452. }
  453.  
  454. confirmRoot () {
  455. testroot="`whoami`"
  456. if [ "$testroot" != "root" ]; then
  457. ErrorMessage "Need to be root to run. Exiting"
  458. exit 1
  459. fi
  460. }
  461.  
  462. StartService() {
  463. ServiceDescription="$1"
  464. ServiceCmd="$2"
  465. ServiceBkg="$3"
  466. if [[ -x $(echo $ServiceCmd | cut -d ' ' -f1) ]] ;then
  467. if [ -x /bin/plymouth ]; then
  468. /bin/plymouth update --status="$ServiceDescription ... "
  469. fi
  470. echo -n "$ServiceDescription ... "
  471. if [[ "$ServiceBkg" == "&" ]] ;then
  472. $ServiceCmd 1>/dev/null 2>/dev/null &
  473. else
  474. $ServiceCmd 1>/dev/null 2>/dev/null
  475. fi
  476. err=$?
  477. if [[ "$err" == "0" ]] ;then
  478. echo "ok"
  479. else
  480. echo "fail"
  481. fi
  482. fi
  483. return $err
  484. }
  485.  
  486. GetVideoDriver () {
  487. vga_pci=$(lspci -v | grep -i 'VGA')
  488. prop_driver="vesa"
  489. chip_man=$(echo "$vga_pci" | grep -Eo '(ATI|VIA|nVidia|Intel)')
  490. case $chip_man in
  491. nVidia)
  492. prop_driver="nvidia" ;;
  493. ATI)
  494. prop_driver="fglrx"
  495. if echo "$vga_pci" | grep -Ei '((r5|r6|r7)|(9|X|ES)(1|2?)([0-9])(5|0)0|Xpress)'; then
  496. prop_driver="radeon"; fi ;;
  497.  
  498. Intel)
  499. prop_driver="intel"
  500. if echo $vga_pci | grep "i740"; then
  501. prop_driver="i740"; fi
  502. if echo $vga_pci | grep "i128"; then
  503. prop_driver="i128"; fi ;;
  504.  
  505. VIA)
  506. prop_driver="openchrome" ;
  507. if echo $vga_pci | grep -i "Savage"; then
  508. prop_driver="savage"; fi
  509. #if echo $vga_pci | grep -i "s3"; then
  510. #prop_driver="via"; fi
  511. if echo $vga_pci | grep -i "virge"; then
  512. prop_driver="virge"; fi ;;
  513. *)
  514. prop_driver="vesa"
  515. esac
  516.  
  517. }
  518.  
  519. InstallVideoDriver () {
  520. case "$prop_driver" in
  521. nvidia)
  522. if ! PackageIsInstalled nvidia-glx && ! PackageIsInstalled nvidia-glx-new && ! PackageIsInstalled nvidia-glx-71 && ! PackageIsInstalled nvidia-glx-96 && ! PackageIsInstalled nvidia-glx-173 && ! PackageIsInstalled nvidia-glx-180 && ! PackageIsInstalled nvidia-glx-190 && ! PackageIsInstalled nvidia-glx-195 && ! PackageIsInstalled nvidia-glx-260 && ! PackageIsInstalled nvidia-glx-185 && ! PackageIsInstalled nvidia-current && ping -c 1 google.com; then
  523. apt-get -yf install pluto-nvidia-video-drivers
  524. VerifyExitCode "Install Pluto nVidia Driver"
  525. nv_pid=$(pidof nvidia-install.sh)
  526. if [[ -n $nv_pid ]] ; then
  527. StatusMessage "Installing nVidia driver this may take a few minutes"
  528. installCorrectNvidiaDriver
  529. else StartService "Installing nVidia driver this may take a few minutes" ". /usr/pluto/bin/nvidia-install.sh"
  530. installCorrectNvidiaDriver
  531. fi
  532. fi ;;
  533. nouveau)
  534. if ! PackageIsInstalled xserver-xorg-video-nouveau; then
  535. apt-get -yf install xserver-xorg-video-nouveau
  536. VerifyExitCode "Install nouveau Driver"
  537. fi ;;
  538. radeon)
  539. if ! PackageIsInstalled xserver-xorg-video-radeon; then
  540. apt-get -yf install xserver-xorg-video-radeon
  541. VerifyExitCode "Install radeon Driver"
  542. fi ;;
  543. fglrx)
  544. if ! PackageIsInstalled fglrx && ping -c 1 google.com; then
  545. apt-get -yf install fglrx
  546. VerifyExitCode "Install fglrx Driver"
  547. fi ;;
  548. intel)
  549. if ! PackageIsInstalled xserver-xorg-video-intel; then
  550. apt-get -yf install xserver-xorg-video-intel
  551. VerifyExitCode "Install Intel Driver"
  552. fi ;;
  553. i128)
  554. if ! PackageIsInstalled xserver-xorg-video-i128; then
  555. apt-get -yf install xserver-xorg-video-i128
  556. VerifyExitCode "Install i128 Driver"
  557. fi ;;
  558. i740)
  559. if ! PackageIsInstalled xserver-xorg-video-i740; then
  560. apt-get -yf install xserver-xorg-video-i740
  561. VerifyExitCode "Install i740 Driver"
  562. fi ;;
  563. openchrome)
  564. if ! PackageIsInstalled xserver-xorg-video-openchrome; then
  565. apt-get -yf install xserver-xorg-video-openchrome
  566. VerifyExitCode "Install opencrhome Driver"
  567. fi ;;
  568. savage)
  569. if ! PackageIsInstalled xserver-xorg-video-savage && ping -c 1 google.com; then
  570. apt-get -yf install xserver-xorg-video-savage
  571. VerifyExitCode "Install VIA Savage Driver"
  572. fi ;;
  573. via)
  574. if ! PackageIsInstalled xserver-xorg-video-s3 && ping -c 1 google.com; then
  575. apt-get -yf install xserver-xorg-video-s3
  576. VerifyExitCode "Install VIA S3 Driver"
  577. fi ;;
  578. virge)
  579. if ! PackageIsInstalled xserver-xorg-video-s3virge && ping -c 1 google.com; then
  580. apt-get -yf install xserver-xorg-video-s3virge
  581. VerifyExitCode "Install VIA S3 Virge Driver"
  582. fi ;;
  583. esac
  584. if [[ "$chip_man" == "Intel" ]] && [[ -z $online ]]; then
  585. if ! PackageIsInstalled "libva-driver-i965"; then
  586. apt-get -yf install libva-driver-i965
  587. VerifyExitCode "Install Intel Graphics Accelerator"
  588. fi
  589. fi
  590. VideoDriver="$prop_driver"
  591. }
  592.  
  593. CheckVideoDriver () {
  594. GetVideoDriver
  595. online=$(ping -c 2 google.com)
  596. card_detail=$(lspci | grep 'VGA' | cut -d':' -f3)
  597. if [[ -f /etc/X11/xorg.conf ]]; then
  598. # TODO figure out a better way to isolate the video driver in the xorg.conf list of "Driver" options
  599. cur_driver=$(grep "Driver" /etc/X11/xorg.conf | grep -Eo '(nvidia|nouveau|radeon|fglrx|savage|openchrome|via|virge|intel|i740|i128|vesa)')
  600. offline_missmatch=""
  601. if [[ "$prop_driver" != "$cur_driver" ]] && [[ -n $online ]]; then
  602. offline_mismatch="true"
  603. elif [[ "$prop_driver" != "$cur_driver" ]] && [[ -z $online ]]; then
  604. offline_mismatch="false"
  605. fi
  606. # Check to see that the appropriate driver is installed by type
  607. # If current driver is nvidia, check that it is the correct one
  608.  
  609. if [[ "$offline_mismatch" == "false" ]] && [[ "$cur_driver" == "nvidia" ]]; then
  610. StartService "Checking nVidia driver" ". /usr/pluto/bin/nvidia-install.sh"
  611. current_nvidia=$(getInstalledNvidiaDriver)
  612. preferred_nvidia=$(getPreferredNvidiaDriver)
  613. fi
  614.  
  615. if [[ "$cur_driver" == "$prop_driver" ]]; then
  616. StatusMessage "Correct driver '$prop_driver' already loaded"
  617. # Remove fglrx or nVidia drivers if they are installed, but do not match current requirements
  618. elif ([[ "$offline_mismatch" == "false" ]]) || ([[ "$offine_missmatch" == "true" ]] && echo "$prop_driver" | grep -Eq '(nouveau|radeon|openchrome)'); then
  619. ErrorMessage "Video chipset change detected !!!"
  620. if [[ "$cur_driver" == "fglrx" ]]; then
  621. echo ""
  622. echo ""
  623. echo ""
  624. ErrorMessage "Purging fglrx driver due to multiple conflicts"
  625. apt-get -y remove --purge xorg-driver-fglrx fglrx* --force-yes
  626. apt-get -y install --reinstall libgl1-mesa-glx libgl1-mesa-dri fglrx-modaliases --force-yes
  627. dpkg-reconfigure xserver-xorg
  628. apt-get -y install --reinstall xserver-xorg-core --force-yes
  629. rm /etc/X11/xorg.conf
  630. reboot
  631. exit 0
  632. elif [[ $cur_driver == "nvidia" ]]; then
  633. StatusMessage "Removing old nVidia driver"
  634. apt-get -yf remove $current_driver --force-yes
  635. fi
  636.  
  637. # If there is an xorg, but the driver does not match best selection, install driver and run AVWizard
  638. StatusMessage "Installing video driver '$prop_driver' for $card_detail"
  639. InstallVideoDriver
  640. sleep 3
  641. ConfSet "AVWizardOverride" "1"
  642. elif [[ "$offine_missmatch" == "true" ]]; then
  643. case $prop_driver in
  644. nvidia)
  645. prop_driver="nouveau" ;;
  646. fglrx)
  647. prop_driver="radeon" ;;
  648. savage)
  649. prop_driver="openchrome" ;;
  650. via)
  651. prop_driver="openchrome" ;;
  652. virge)
  653. prop_driver="openchrome" ;;
  654. esac
  655. if [[ "$prop_driver" != "$cur_driver" ]]; then
  656. StatusMessage "Installing video driver '$prop_driver' for $card_detail"
  657. InstallVideoDriver
  658. sleep 3
  659. ConfSet "AVWizardOverride" "1"
  660. fi
  661. fi
  662. else
  663. # If there is no xorg.conf, install driver and run AVWizard
  664. if [[ -n $online ]]; then
  665. case $prop_driver in
  666. nvidia)
  667. prop_driver="nouveau" ;;
  668. fglrx)
  669. prop_driver="radeon" ;;
  670. savage)
  671. prop_driver="openchrome" ;;
  672. via)
  673. prop_driver="openchrome" ;;
  674. virge)
  675. prop_driver="openchrome" ;;
  676. esac
  677. fi
  678.  
  679. StatusMessage "/etc/X11/xorg.conf is missing. Installing video driver '$prop_driver' for $card_detail"
  680. InstallVideoDriver
  681. ConfSet "AVWizardOverride" "1"
  682. fi
  683. fi
  684. }
  685.  
  686. ReloadDevicesOnThisMachine()
  687. {
  688. for Dev in $(cat /usr/pluto/locks/pluto_spawned_local_devices.txt); do
  689. /usr/pluto/bin/MessageSend "$DCERouter" 0 "$Dev" 7 1 163 "Utils.sh ReloadDevicesOnThisMachine"
  690. done
  691. }
  692.  
  693. OpenGLeffects()
  694. {
  695. local Q
  696.  
  697. Q="
  698. SELECT IK_DeviceData
  699. FROM Device
  700. LEFT JOIN Device AS Parent ON Parent.PK_Device=Device.FK_Device_ControlledVia
  701. JOIN Device_DeviceData ON Device.PK_Device=FK_Device
  702. WHERE
  703. Device.FK_DeviceTemplate='$DEVICETEMPLATE_OnScreen_Orbiter'
  704. AND (
  705. Device.FK_Device_ControlledVia='$PK_Device'
  706. OR Parent.FK_Device_ControlledVia='$PK_Device'
  707. )
  708. AND FK_DeviceData='$DEVICEDATA_Use_OpenGL_effects'
  709. "
  710. RunSQL "$Q"
  711. }
  712.  
  713. AlphaBlendingEnabled()
  714. {
  715. local Q
  716.  
  717. Q="
  718. SELECT IK_DeviceData
  719. FROM Device
  720. LEFT JOIN Device AS Parent ON Parent.PK_Device=Device.FK_Device_ControlledVia
  721. JOIN Device_DeviceData ON Device.PK_Device=FK_Device
  722. WHERE
  723. Device.FK_DeviceTemplate='$DEVICETEMPLATE_OnScreen_Orbiter'
  724. AND (
  725. Device.FK_Device_ControlledVia='$PK_Device'
  726. OR Parent.FK_Device_ControlledVia='$PK_Device'
  727. )
  728. AND FK_DeviceData='$DEVICEDATA_Use_alpha_blended_UI'
  729. "
  730. RunSQL "$Q"
  731. }
  732.  
  733. GetDeviceData()
  734. {
  735. local Q
  736. local Device="$1" DeviceData="$2"
  737.  
  738. Q="
  739. SELECT IK_DeviceData
  740. FROM Device_DeviceData
  741. WHERE FK_Device='$Device' AND FK_DeviceData='$DeviceData'
  742. "
  743. Field 1 "$(RunSQL "$Q")"
  744. }
  745.  
  746. SetDeviceData()
  747. {
  748. local Q
  749. local Device="$1" DeviceData="$2" Value="$3"
  750.  
  751. Q="
  752. UPDATE Device_DeviceData
  753. SET IK_DeviceData='$Value'
  754. WHERE FK_Device=$Device AND FK_DeviceData=$DeviceData
  755. "
  756. RunSQL "$Q"
  757. }
  758.  
  759. UI_SetOptions()
  760. {
  761. local OrbiterDev="$1"
  762. local OpenGLeffects="$2"
  763. local AlphaBlending="$3"
  764. local UI_Version="$4"
  765.  
  766. # disable OpenGL effects
  767. Q="
  768. REPLACE INTO Device_DeviceData(FK_Device, FK_DeviceData, IK_DeviceData)
  769. VALUES('$OrbiterDev', '$DEVICEDATA_Use_OpenGL_effects', '$OpenGLeffects')
  770. "
  771. RunSQL "$Q"
  772. # disable alpha blending
  773. Q="
  774. REPLACE INTO Device_DeviceData(FK_Device, FK_DeviceData, IK_DeviceData)
  775. VALUES('$OrbiterDev', '$DEVICEDATA_Use_alpha_blended_UI', '$AlphaBlending')
  776. "
  777. RunSQL "$Q"
  778. # select UI
  779. Q="
  780. REPLACE INTO Device_DeviceData(FK_Device, FK_DeviceData, IK_DeviceData)
  781. VALUES('$OrbiterDev', '$DEVICEDATA_PK_UI', '$UI_Version')
  782. "
  783. RunSQL "$Q"
  784. }
  785.  
  786. function GeneratePassword() {
  787. #TODO: Replace with this ---> </dev/urandom tr -dc A-Za-z0-9_ | head -c8
  788. local -a alpha1=(Q W E R T Y U I O P A S D F G H J K L Z X C V B N M)
  789. local -a alpha2=(q w e r t y u i o p a s d f g h j k l z x c v b n m)
  790. local -a alpha3=(1 2 3 4 5 6 7 8 9 0)
  791.  
  792. local pass=""
  793. pass=$pass"${alpha1[$(($RANDOM%26))]}${alpha1[$(($RANDOM%26))]}${alpha1[$(($RANDOM%26))]}"
  794. pass=$pass"${alpha2[$(($RANDOM%26))]}${alpha2[$(($RANDOM%26))]}${alpha2[$(($RANDOM%26))]}"
  795. pass=$pass"${alpha3[$(($RANDOM%10))]}${alpha3[$(($RANDOM%10))]}"
  796.  
  797. local fromwhere=$(( $RANDOM % 3 + 1 ))
  798. [[ $fromwhere == 1 ]] && pass=$pass"${alpha1[$(($RANDOM%26))]}"
  799. [[ $fromwhere == 2 ]] && pass=$pass"${alpha2[$(($RANDOM%26))]}"
  800. [[ $fromwhere == 3 ]] && pass=$pass"${alpha3[$(($RANDOM%10))]}"
  801.  
  802.  
  803. for i in `seq 1 100` ;do
  804. local split=$(( $RANDOM % ${#pass} + 1 ))
  805. pass1=${pass:$split}
  806. pass2=${pass:0:$split}
  807. pass="${pass1}${pass2}"
  808. done
  809.  
  810. echo $pass
  811. }
  812.  
  813. function GeneratePasswordOf6Digits()
  814. {
  815. local pass
  816. for ((i = 0; i < 6; i++)); do
  817. pass="${pass}$((RANDOM % 10))"
  818. done
  819. echo "$pass"
  820. }
  821.  
  822. Log()
  823. {
  824. local File="$1"; shift
  825. local Msg="$*"
  826.  
  827. echo "LOG: $Msg"
  828. echo "$Msg" >>"$File"
  829. }
  830.  
  831.  
  832. function BlacklistConfFiles()
  833. {
  834. local file=$1
  835.  
  836. if [[ -e /etc/confblacklist ]] ;then
  837. while read line; do
  838. if [[ "$line" == "$file" ]] ;then
  839. return 0
  840. fi
  841. done < /etc/confblacklist
  842. fi
  843.  
  844. return 1
  845. }
  846.  
  847. function VDRInstalled() {
  848. # Return true if VDR is installed
  849. DEVICETEMPLATE_VDR_Plugin="1704"
  850. Q="SELECT PK_Device FROM Device Where FK_DeviceTemplate = $DEVICETEMPLATE_VDR_Plugin"
  851. VDRDevice=$(RunSQL "$Q")
  852. if [ "$VDRDevice" == "" ] ; then
  853. RETURNVALUE=1
  854. else
  855. RETURNVALUE=0
  856. fi
  857. return $RETURNVALUE
  858. }
Add Comment
Please, Sign In to add comment