Guest User

Untitled

a guest
Jan 21st, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.00 KB | None | 0 0
  1. #!/bin/bash
  2. . /usr/pluto/bin/pluto.func
  3. . /usr/pluto/bin/Config_Ops.sh
  4. . /usr/pluto/bin/Utils.sh
  5. . /usr/pluto/bin/SQL_Ops.sh
  6.  
  7. DEVICECATEGORY_Media_Director="8"
  8. DEVICECATEGORY_Video_Cards="125"
  9. DEVICECATEGORY_Sound_Cards="124"
  10. DEVICETEMPLATE_OnScreen_Orbiter="62"
  11. DEVICEDATA_Video_settings="89"
  12. DEVICEDATA_Audio_settings="88"
  13. DEVICEDATA_Reboot="236"
  14. DEVICEDATA_Connector="68"
  15. DEVICEDATA_TV_Standard="229"
  16. DEVICEDATA_Setup_Script="189"
  17. DEVICEDATA_Sound_Card="288"
  18. SettingsFile="/etc/pluto/lastaudiovideo.conf"
  19.  
  20. # don't let KDE override xorg.conf
  21. rm -f {/home/*,/root}/.kde/share/config/displayconfigrc
  22.  
  23. Reboot="NoReboot"
  24. ReloadX="NoReloadX"
  25. AudioSetting_Override="$1"
  26. SoundCard_Override="$2"
  27. XineConf_Override="$3"
  28. ComputerDev=$(FindDevice_Category "$PK_Device" "$DEVICECATEGORY_Media_Director" '' 'include-parent')
  29. OrbiterDev=$(FindDevice_Template "$ComputerDev" "$DEVICETEMPLATE_OnScreen_Orbiter")
  30. VideoCardDev=$(FindDevice_Category "$ComputerDev" "$DEVICECATEGORY_Video_Cards")
  31. Yalpa=$(aplay -l)
  32.  
  33. if [[ -z "$VideoCardDev" ]]; then
  34. VideoCardDev=$(FindDevice_Category "$PK_Device" "$DEVICECATEGORY_Video_Cards")
  35. fi
  36.  
  37. SoundCardDev=$(FindDevice_Category "$ComputerDev" "$DEVICECATEGORY_Sound_Cards")
  38.  
  39. if [[ -z "$SoundCardDev" ]]; then
  40. SoundCardDev=$(FindDevice_Category "$PK_Device" "$DEVICECATEGORY_Sound_Cards")
  41. fi
  42.  
  43. ReadConf()
  44. {
  45. ## config file format (direcly parsable by bash):
  46. # name=value
  47. if [[ -f "$SettingsFile" ]]; then
  48. while read line; do
  49. eval "OldSetting_$line"
  50. done <"$SettingsFile"
  51. fi
  52. }
  53.  
  54. GetVideoSetting()
  55. {
  56. local Q
  57. local VideoSetting
  58.  
  59. VideoSetting=$(GetDeviceData "$ComputerDev" "$DEVICEDATA_Video_settings")
  60.  
  61. if [[ -n "$VideoSetting" ]]; then
  62. Refresh=$(echo "$VideoSetting" | cut -d '/' -f2)
  63. ResolutionInfo=$(echo "$VideoSetting" | cut -d '/' -f1)
  64. ResX=$(echo "$ResolutionInfo" | cut -d' ' -f1)
  65. ResY=$(echo "$ResolutionInfo" | cut -d' ' -f2)
  66. if [[ -z "$Refresh" || -z "$ResX" || -z "$ResY" ]]; then
  67. Logging "$TYPE" "$SEVERITY_CRITICAL" "SetupAudioVideo.sh" "Malformed DeviceData: VideoSetting='${VideoSetting}'"
  68. MalformedVideoSetting='Malformed VideoSetting'
  69. fi
  70. fi
  71.  
  72. if [[ -z "$MalformedVideoSetting" ]]; then
  73. echo "$VideoSetting"
  74. fi
  75. }
  76.  
  77. SaveSettings()
  78. {
  79. local Var VarName
  80.  
  81. for Var in ${!OldSetting_*}; do
  82. VarName="${Var#OldSetting_}"
  83. eval "Save_$VarName=\"${!Var}\""
  84. done
  85.  
  86. for Var in ${!NewSetting_*}; do
  87. VarName="${Var#NewSetting_}"
  88. eval "Save_$VarName=\"${!Var}\""
  89. done
  90.  
  91. for Var in ${!Save_*}; do
  92. VarName="${Var#Save_}"
  93. echo "$VarName=\"${!Var}\""
  94. done >"$SettingsFile"
  95. }
  96.  
  97. Setup_AsoundConf()
  98. {
  99. local AudioSetting="$1"
  100. local SoundCard="0"
  101. local HDMIDevice="3"
  102. local HWOnlyCard="0"
  103. local AnalogPlaybackCard="plug:dmix:${SoundCard}"
  104.  
  105. # Do not mess with asound.conf if Audio Setting is set to Manual. This will only happen after the asound.conf has been generated at least once.
  106. if [[ "$AudioSetting" == "M" ]]; then
  107. return
  108. fi
  109.  
  110. local Q R
  111. local MD_Device="$PK_Device"
  112.  
  113. Q="SELECT FK_DeviceTemplate FROM Device WHERE PK_Device=$PK_Device"
  114. R=$(RunSQL "$Q")
  115.  
  116. if [[ "$R" == "7" ]]; then
  117. Q="SELECT PK_Device FROM Device WHERE FK_DeviceTemplate=28 AND FK_Device_ControlledVia=$PK_Device"
  118. R=$(RunSQL "$Q")
  119. MD_Device=$(Field 1 "$R")
  120. fi
  121.  
  122. if [[ -n "$SoundCard_Override" ]]; then
  123. SoundCard="$SoundCard_Override"
  124. else
  125. SoundCard=$(GetDeviceData "$MD_Device" "$DEVICEDATA_Sound_Card")
  126. fi
  127.  
  128. SoundCard=$(TranslateSoundCard "$SoundCard")
  129. HWOnlyCard="$SoundCard"
  130. Yalpa=$(aplay -l)
  131. HDMIDevice=$(grep -i "hdmi" <<< "$Yalpa" | grep -wo "device ." | awk '{print $2}')
  132.  
  133. # Handle nVidia GT card types
  134. case "$AudioSetting" in
  135. *H*)
  136. if [[ $(wc -l <<< "$HDMIDevice") -gt "3" ]]; then
  137. if grep "7" <<< "$HDMIDevice"; then
  138. HDMIDevice="7"
  139. fi
  140. SoundCard="${SoundCard},${HDMIDevice}"
  141. fi
  142. ;;
  143. esac
  144.  
  145. sed -r "s,%MAIN_CARD%,$SoundCard,g; s,%HWONLY_CARD%,$HWOnlyCard,; s,%SOUND_DEVICE%,$HDMIDevice,; s,%ANALOG_PLAYBACK_CARD%,$AnalogPlaybackCard,g" /usr/pluto/templates/asound.conf >/etc/asound.conf
  146. case "$AudioSetting" in
  147. *[CO]*)
  148. # audio setting is Coaxial or Optical, i.e. S/PDIF
  149. echo 'pcm.!default asym_spdif' >>/etc/asound.conf
  150. ;;
  151. *H*)
  152. # audio setting is HDMI
  153. echo 'pcm.!default asym_hdmi' >>/etc/asound.conf
  154. ;;
  155. *)
  156. # audio setting is Stereo or something unknown
  157. echo 'pcm.!default asym_analog' >>/etc/asound.conf
  158. ;;
  159. esac
  160.  
  161. Setup_XineConf "$AudioSetting" "$SoundCard" "$HDMIDevice" "$AnalogPlaybackCard"
  162. alsa force-reload
  163. }
  164.  
  165. Setup_XineConf()
  166. {
  167. local AudioSetting="$1" SoundCard="$2" HDMIDevice="$3" AnalogPlaybackCard="$4"
  168. local XineConf=/etc/pluto/xine.conf
  169.  
  170. if [[ -n "$XineConf_Override" ]]; then
  171. XineConf="$XineConf_Override"
  172. fi
  173.  
  174. case "$AudioSetting" in
  175. *[CO]*)
  176. XineConfSet audio.device.alsa_front_device asym_spdif "$XineConf"
  177. XineConfSet audio.device.alsa_default_device asym_spdif "$XineConf"
  178. ;;
  179. *H*)
  180. XineConfSet audio.device.alsa_front_device:plughw "$SoundCard,$HDMIDevice" "$XineConf"
  181. XineConfSet audio.device.alsa_default_device:plughw "$SoundCard,$HDMIDevice" "$XineConf"
  182. XineConfSet audio.device.alsa_passthrough_device:plughw "$SoundCard,$HDMIDevice" "$XineConf"
  183. ;;
  184. *)
  185. XineConfSet audio.device.alsa_front_device "$AnalogPlaybackCard" "$XineConf"
  186. XineConfSet audio.device.alsa_default_device "$AnalogPlaybackCard" "$XineConf"
  187. ;;
  188. esac
  189.  
  190. case "$AudioSetting" in
  191. *3*)
  192. XineConfSet audio.output.speaker_arrangement 'Pass Through' "$SoundCard,$HDMIDevice"
  193. ;;
  194. *)
  195. XineConfSet audio.output.speaker_arrangement 'Stereo 2.0' "$SoundCard,$HDMIDevice"
  196. sed -i 's/audio\.device\.alsa_passthrough_device.*//' /etc/pluto/xine.conf
  197. ;;
  198. esac
  199. }
  200.  
  201. VideoSettings_Check()
  202. {
  203. local Update_XorgConf="NoXorgConf"
  204. local DB_VideoSetting DB_OpenGL DB_AlphaBlending DB_Connector DB_TVStandard DB_Reboot
  205.  
  206. DB_VideoSetting=$(GetVideoSetting)
  207. DB_OpenGL=$(OpenGLeffects)
  208. DB_AlphaBlending=$(AlphaBlendingEnabled)
  209. DB_Connector=$(GetDeviceData "$ComputerDev" "$DEVICEDATA_Connector")
  210. DB_TVStandard=$(GetDeviceData "$ComputerDev" "$DEVICEDATA_TV_Standard")
  211. DB_Reboot=$(GetDeviceData "$VideoCardDev" "$DEVICEDATA_Reboot")
  212.  
  213. if [[ -n "$DB_VideoSetting" && "$DB_VideoSetting" != "$OldSetting_VideoSetting" ]]; then
  214. Update_XorgConf="XorgConf"
  215. NewSetting_VideoSetting="$DB_VideoSetting"
  216. fi
  217.  
  218. if [[ -n "$DB_OpenGL" && "$DB_OpenGL" != "$OldSetting_OpenGL" ]]; then
  219. Update_XorgConf="XorgConf"
  220. NewSetting_OpenGL="$DB_OpenGL"
  221. fi
  222.  
  223. if [[ -n "$DB_AlphaBlending" && "$DB_AlphaBlending" != "$OldSetting_AlphaBlending" ]]; then
  224. Update_XorgConf="XorgConf"
  225. NewSetting_AlphaBlending="$DB_AlphaBlending"
  226. fi
  227.  
  228. if [[ -n "$DB_Connector" && "$DB_Connector" != "$OldSetting_Connector" ]]; then
  229. Update_XorgConf="XorgConf"
  230. NewSetting_Connector="$DB_Connector"
  231. fi
  232.  
  233. if [[ -n "$DB_TVStandard" && "$DB_TVStandard" != "$OldSetting_TVStandard" ]]; then
  234. Update_XorgConf="XorgConf"
  235. NewSetting_TVStandard="$DB_TVStandard"
  236. fi
  237.  
  238. if [[ "$Update_XorgConf" == "XorgConf" ]]; then
  239. /usr/pluto/bin/Xconfigure.sh
  240. if [[ "$DB_Reboot" == 1 ]]; then
  241. Reboot="Reboot"
  242. else
  243. ReloadX="ReloadX"
  244. fi
  245.  
  246. # Orbiter Regen
  247. Q="
  248. UPDATE Orbiter
  249. SET Regen=1
  250. WHERE PK_Orbiter='$OrbiterDev'
  251. "
  252. RunSQL "$Q"
  253. fi
  254. }
  255.  
  256. AudioSettings_Check()
  257. {
  258. local DB_AudioSetting DB_AudioScript DB_Reboot
  259. local ScriptPath
  260.  
  261. if [[ -z "$AudioSetting_Override" ]]; then
  262. DB_AudioSetting=$(GetDeviceData "$ComputerDev" "$DEVICEDATA_Audio_settings")
  263. else
  264. DB_AudioSetting="$AudioSetting_Override"
  265. fi
  266.  
  267. DB_Reboot=$(GetDeviceData "$AudioCardDev" "$DEVICEDATA_Reboot")
  268. Logging "$TYPE" "$SEVERITY_NORMAL" "SetupAudioVideo" "'"
  269. DB_AudioScript=$(GetDeviceData "$SoundCardDev" "$DEVICEDATA_Setup_Script")
  270. ScriptPath="/usr/pluto/bin/$DB_AudioScript"
  271. Logging "$TYPE" "$SEVERITY_NORMAL" "SetupAudioVideo" "DBSetting: $DB_AudioSetting Reboot: $DB_Reboot Script Path: $ScriptPath"
  272.  
  273. if [[ -n "$DB_AudioSetting" && -f "$ScriptPath" ]]; then
  274. Logging "$TYPE" "$SEVERITY_NORMAL" "SetupAudioVideo" "Running: $ScriptPath $DB_AudioSetting"
  275. "$ScriptPath" "$DB_AudioSetting"
  276. fi
  277.  
  278. NewSetting_AudioSetting="$DB_AudioSetting"
  279.  
  280. if [[ "$NewSetting_AudioSetting" == *S* ]]; then
  281. # S3 is not a valid combination and will break things
  282. NewSetting_AudioSetting=${NewSetting_AudioSetting//3}
  283. fi
  284. echo "NewSetting = $NewSetting_AudioSetting"
  285. Setup_AsoundConf "$NewSetting_AudioSetting"
  286.  
  287. if [[ "$DB_Reboot" == "1" ]]; then
  288. Reboot="Reboot"
  289. fi
  290. }
  291.  
  292. Logging "$TYPE" "$SEVERITY_NORMAL" "SetupAudioVideo" "Starting"
  293. ReadConf
  294. VideoSettings_Check
  295. AudioSettings_Check
  296. SaveSettings
  297.  
  298. if [[ -z "$(pidof X)" ]]; then
  299. exit # no X is running
  300. fi
  301.  
  302. if [[ "$Reboot" == "Reboot" ]]; then
  303. reboot
  304. elif [[ "$ReloadX" == "ReloadX" ]]; then
  305. /usr/pluto/bin/RestartLocalX.sh &
  306. disown -a
  307. fi
Add Comment
Please, Sign In to add comment