Advertisement
Pointman87

SetupAudioVideo.sh the script

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