functions4puppy4 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #some more functions called from boot scripts in Puppy4...
  2. #v411 moved choosemousefunc() out of /usr/sbin/xorgwizard, want call from rc.sysinit.
  3. #w468 not using set_mixers() anymore, it's done in /etc/init.d/alsa.
  4. #w468 choosemousefunc() simplified.
  5. #101120 new firmware_tarball_func, as /sbin/pup_event_backend_modprobe rewritten.
  6. #110722 usb drive, LED light briefly flashes after unmounted, so wait a bit. 110828 remove.
  7. #120209 slight changes so that SSS mechanism can substitute translations. (see /usr/share/sss/script_strings)
  8. #120828 rerwin: record firmware installed in /etc/modules/firmware.dep.inst.${KERNVER}
  9. #120828 grep needs -E option, as expression is extended regular expression.
  10. #120831 rerwin: Obtain firmware from all-firmware directories as well as tarballs.
  11. #121004 rerwin: /etc/modules/firmware.dep.inst.${KERNVER} now has names of firmware tarballs, not modules.
  12. #101119 called from rc.sysinit...
  13. #global $MODULE is name of module, global $KERNVER.
  14. firmware_tarball_func() {
  15. MODULEx="`echo -n "$MODULE" | tr '_' '-'`"
  16. #121004 ...
  17. fPATTERN='[:,]'"${MODULE}"'\.ko|[:,]'"${MODULEx}"'\.ko'
  18. FIRMPKG="`cat /etc/modules/firmware.dep.${KERNVER} | grep -v '^#' | grep ':' | grep -E "$fPATTERN" | cut -f 1 -d ':' | head -n 1`"
  19. if [ "$FIRMPKG" != "" ];then
  20. iPATTERN='^'"${FIRMPKG}"'$'
  21. if [ "`grep "$iPATTERN" /etc/modules/firmware.dep.inst.${KERNVER}`" = "" ];then
  22. #120831 rerwin: ...
  23. FLAGFIRM='no'
  24. if [ -d /lib/modules/all-firmware/${FIRMPKG} ];then #support firmware directories.
  25. cp -a -f --remove-destination /lib/modules/all-firmware/${FIRMPKG}/* /
  26. FLAGFIRM='yes'
  27. else
  28. if [ -f /lib/modules/all-firmware/${FIRMPKG}.tar.gz ];then
  29. tar -z -x --strip=1 --directory=/ -f /lib/modules/all-firmware/${FIRMPKG}.tar.gz > /dev/null 2>&1
  30. FLAGFIRM='yes'
  31. fi
  32. fi
  33. if [ "$FLAGFIRM" = "yes" ];then #120831 end
  34. #execute any post-install script...
  35. if [ -f /pinstall.${FIRMPKG}.sh ];then
  36. BRKCNT=0; SLEEPU=$((${$} * 10))
  37. while [ 1 ];do #serialise execution of pinstall scripts...
  38. PINSTALLCNT=`find / -maxdepth 1 -type f -name 'pinstall.*.sh' | wc -l`
  39. [ $PINSTALLCNT -eq 1 ] && break
  40. usleep $SLEEPU
  41. BRKCNT=$(($BRKCNT + 1))
  42. [ $BRKCNT -gt 5 ] && break
  43. done
  44. #120828 remove...
  45. #echo "$MODULE" >> /etc/modules/firmware.dep.inst.${KERNVER}
  46. cd /
  47. /pinstall.${FIRMPKG}.sh >/dev/null 2>&1
  48. rm -f /pinstall.${FIRMPKG}.sh >/dev/null 2>&1
  49. fi
  50. echo "$FIRMPKG" >> /etc/modules/firmware.dep.inst.${KERNVER} #120828
  51. fi
  52. fi
  53. fi
  54. }
  55. #v403 change desktop icon to unmounted status, called from pup_event_frontend_d, pmount...
  56. icon_unmounted_func() {
  57. #passed params: drivename category ex: sda usbdrv
  58. DRVICON="drive48.png" #default.
  59. [ "$2" = "usbdrv" ] && DRVICON="usbdrv48.png"
  60. [ "$2" = "card" ] && DRVICON="card48.png"
  61. [ "$2" = "floppy" ] && DRVICON="floppy48.png"
  62. [ "$2" = "optical" ] && DRVICON="optical48.png"
  63. #find out if already done...
  64. if [ -f /root/.config/rox.sourceforge.net/ROX-Filer/globicons ];then
  65. GLOBLINES="`cat /root/.config/rox.sourceforge.net/ROX-Filer/globicons | tr '\n' '|' | sed -e 's%</rule>|%\n%g'`"
  66. diPATTERN='/root/.pup_event/drive_'"${1}"'"'
  67. [ "`echo "$GLOBLINES" | grep "$diPATTERN" | grep "$DRVICON"`" != "" ] && return
  68. fi
  69. #[ "`echo "${ATADRIVES}" | grep "${1}"`" = "" ] && sleep 1 #110722 usb drive, LED light briefly flashes after unmounted, so wait a bit. ATADRIVES is in /etc/rc.d/PUPSTATE.
  70. echo "<?xml version=\"1.0\"?>
  71. <env:Envelope xmlns:env=\"http://www.w3.org/2001/12/soap-envelope\">
  72. <env:Body xmlns=\"http://rox.sourceforge.net/SOAP/ROX-Filer\">
  73. <SetIcon>
  74. <Path>/root/.pup_event/drive_${1}</Path>
  75. <Icon>/usr/local/lib/X11/pixmaps/${DRVICON}</Icon>
  76. </SetIcon>
  77. </env:Body>
  78. </env:Envelope>" | rox -R
  79. }
  80. icon_mounted_func() {
  81. #passed params: drivename category ex: sda usbdrv
  82. DRVICON="drive_mntd48.png" #default.
  83. [ "$2" = "usbdrv" ] && DRVICON="usbdrv_mntd48.png"
  84. [ "$2" = "card" ] && DRVICON="card_mntd48.png"
  85. [ "$2" = "floppy" ] && DRVICON="floppy_mntd48.png"
  86. [ "$2" = "optical" ] && DRVICON="optical_mntd48.png"
  87. imPATTERN='^/dev/'"${1}" #important, no space on end.
  88. # if [ "`mount | cut -f 1,3 -d ' ' | grep "$imPATTERN" | grep -v ' /initrd/' | grep -v ' /$'`" = "" ];then
  89. if [ "`df | tr -s ' ' | cut -f 1,6 -d ' ' | grep "$imPATTERN" | grep -v ' /initrd/' | grep -v ' /$'`" = "" ];then
  90. #only partitions mntd on /initrd/* then must be mntd at boot. cannot unmount.
  91. #also, full hd install has partition mntd on '/'.
  92. DRVICON="drive_mntd_boot48.png" #default.
  93. [ "$2" = "usbdrv" ] && DRVICON="usbdrv_mntd_boot48.png"
  94. [ "$2" = "card" ] && DRVICON="card_mntd_boot48.png"
  95. [ "$2" = "floppy" ] && DRVICON="floppy_mntd_boot48.png"
  96. [ "$2" = "optical" ] && DRVICON="optical_mntd_boot48.png"
  97. fi
  98. #find out if already done...
  99. if [ -f /root/.config/rox.sourceforge.net/ROX-Filer/globicons ];then
  100. GLOBLINES="`cat /root/.config/rox.sourceforge.net/ROX-Filer/globicons | tr '\n' '|' | sed -e 's%</rule>|%\n%g'`"
  101. diPATTERN='/root/.pup_event/drive_'"${1}"'"'
  102. [ "`echo "$GLOBLINES" | grep "$diPATTERN" | grep "$DRVICON"`" != "" ] && return
  103. fi
  104. echo "<?xml version=\"1.0\"?>
  105. <env:Envelope xmlns:env=\"http://www.w3.org/2001/12/soap-envelope\">
  106. <env:Body xmlns=\"http://rox.sourceforge.net/SOAP/ROX-Filer\">
  107. <SetIcon>
  108. <Path>/root/.pup_event/drive_${1}</Path>
  109. <Icon>/usr/local/lib/X11/pixmaps/${DRVICON}</Icon>
  110. </SetIcon>
  111. </env:Body>
  112. </env:Envelope>" | rox -R
  113. }
  114. icon_remove_func() {
  115. #passed param is drive icon to remove from desktop. ex: sda
  116. echo "<?xml version=\"1.0\"?>
  117. <env:Envelope xmlns:env=\"http://www.w3.org/2001/12/soap-envelope\">
  118. <env:Body xmlns=\"http://rox.sourceforge.net/SOAP/ROX-Filer\">
  119. <UnsetIcon>
  120. <Path>/root/.pup_event/drive_${1}</Path>
  121. </UnsetIcon>
  122. </env:Body>
  123. </env:Envelope>" | rox -R
  124. }
  125. choosemousefunc() { #w468 called from xorgwizard.
  126. MOUSEINTRO="Only very old PCs may have a serial mouse. These are recognised by the fairly large rectangular plug, technically known as a DB9 or the even larger DB25 (where the 9 or 25 refers to the number of pins in the plug). Press the UP and DOWN arrow keys to choose your mouse type, then press the ENTER key:"
  127. DETECTEDMOUSEDEV="`cat /etc/mousedevice`"
  128. case $DETECTEDMOUSEDEV in
  129. ttyS*)
  130. MOUSEMENU1a='serial'; MOUSEMENU1b='(mouse in very old computers)' #ttyS leave this comment, needed by SSS
  131. MOUSEMENU2a='usb/ps-2'; MOUSEMENU2b='(mouse or touchpad in all modern computers)' #ttyS comment needed by SSS
  132. ;;
  133. *)
  134. MOUSEMENU1a='usb/ps-2'; MOUSEMENU1b='(mouse or touchpad in all modern computers)' #usb-ps2 comment needed by SSS
  135. MOUSEMENU2a='serial'; MOUSEMENU2b='(mouse in very old computers)' #usb-ps2 comment needed by SSS
  136. ;;
  137. esac
  138. dialog --no-cancel --menu "${MOUSEINTRO}\n\n
  139. Please choose mouse type..." 0 0 0 "$MOUSEMENU1a" "$MOUSEMENU1b" "$MOUSEMENU2a" "$MOUSEMENU2b" 2> /tmp/testmsx
  140. [ $? -ne 0 ] && return 1
  141. CHOSENMOUSETYPE="`cat /tmp/testmsx`"
  142. case $CHOSENMOUSETYPE in
  143. serial)
  144. dialog --no-cancel --menu "Serial port mouse plugged into...\nUse UP/DOWN ARROW keys, ENTER key to finish" 0 0 0 ttyS0 "COM1 (most likely)" ttyS1 COM2 ttyS2 COM3 ttyS3 COM4 2> /tmp/testmsx
  145. [ $? -ne 0 ] && return 1
  146. MOUSEDEV="`cat /tmp/testmsx`"
  147. modprobe sermouse
  148. ln -snf $MOUSEDEV /dev/mouse
  149. echo -n "$MOUSEDEV" > /etc/mousedevice
  150. cat /etc/X11/xorg.conf | sed -e 's/\W\+Option\W\+"Protocol"\W\+"\(\(\w\+\/\w\+\)\|\(\w\+\)\)\W\+#mouse0protocol/ Option "Protocol" "Microsoft" #mouse0protocol/' > /tmp/xorg.conf.tmp2
  151. ;;
  152. *)
  153. echo -n "input/mice" > /etc/mousedevice
  154. ln -snf input/mice /dev/mouse
  155. cat /etc/X11/xorg.conf | sed -e 's/\W\+Option\W\+"Protocol"\W\+"\(\(\w\+\/\w\+\)\|\(\w\+\)\)\W\+#mouse0protocol/ Option "Protocol" "IMPS\/2" #mouse0protocol/' > /tmp/xorg.conf.tmp2
  156. ;;
  157. esac
  158. sync
  159. cp -f /tmp/xorg.conf.tmp2 /etc/X11/xorg.conf
  160. rm -f /tmp/xorg.conf.tmp2
  161. } #choosemousefunc()
  162. ###END###