pupcamera 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. #!/bin/sh
  2. #(c) Copyright Barry Kauler, Oct. 2011, bkhome.org
  3. #2011 license GPL3 (see /usr/share/doc/legal)
  4. #called via menu or autodetected when camera plugged in (via /usr/sbin/pupautodetect).
  5. #usbutils optionally used if installed, lsusb accesses usb.ids to obtain device description.
  6. #pupcamera is not a separate application, it is builtin to Woof so is in all builds
  7. # -- it detects if gphoto (and deps) not installed and informs the user.
  8. #111010 first release.
  9. #111015 detect if gphotofs not installed.
  10. #120202 BK: internationalized.
  11. #130208 rodin.s: missing translation.
  12. #130326 note: DEVICE variable no longer in 3.5+ kernel, as /proc/bus/usb removed.
  13. #131128 zigbert: gui (gtkdialog) improvements.
  14. #140128 01micko, bugfix "Open" button and tame 88-puppy-autodetect.rules
  15. PIDOFMTP=`pidof mtpdevice`
  16. [ "$PIDOFMTP" ] && exit # exits if mtpdevice process starts to tame udev rule 88-puppy-autodetect.rules
  17. export TEXTDOMAIN=pupcamera
  18. export OUTPUT_CHARSET=UTF-8
  19. mkdir -p /mnt/camera1
  20. mkdir -p /mnt/camera2
  21. umount /mnt/camera1 2>/dev/null #precaution.
  22. umount /mnt/camera2 2>/dev/null #precaution.
  23. #as this app can be run from both menu and auto-detect plugging-in, kill any previous...
  24. ALLPS="`ps`"
  25. OLDPIDS="`echo "$ALLPS" | grep 'gtkdialog' | grep 'PUPCAMERA_DLG' | tr -s ' ' | sed -e 's%^ %%' | cut -f 1 -d ' ' | tr '\n' ' '`"
  26. kill $OLDPIDS 2>/dev/null
  27. #find BUSNUM, DEVNUM...
  28. BUSNUM=""; DEVNUM=""; PRODUCTDESC=""
  29. if [ "$DEVPATH" ];then
  30. [ -e /sys${DEVPATH}/product ] && PRODUCTDESC="`cat /sys${DEVPATH}/product`"
  31. if [ "$DEVTYPE" = "usb_interface" ];then
  32. UPDEVPATH=$DEVPATH
  33. while [ "$UPDEVPATH" != "/" ];do
  34. UPDEVPATH="`dirname $UPDEVPATH`"
  35. case $UPDEVPATH in
  36. *usb*) #this is to avoid going too high.
  37. [ ! -e /sys${UPDEVPATH}/busnum ] && continue
  38. [ ! -e /sys${UPDEVPATH}/devnum ] && continue
  39. BUSNUM="00`cat /sys${UPDEVPATH}/busnum`"
  40. DEVNUM="00`cat /sys${UPDEVPATH}/devnum`"
  41. BUSNUM="`echo -n "$BUSNUM" | rev | cut -c 1,2,3 | rev`" #must be in 3-digit format, ex: 002
  42. DEVNUM="`echo -n "$DEVNUM" | rev | cut -c 1,2,3 | rev`" #must be in 3-digit format, ex: 012
  43. [ ! "$PRODUCTDESC" ] && [ -e /sys${UPDEVPATH}/product ] && PRODUCTDESC="`cat /sys${UPDEVPATH}/product`"
  44. break
  45. ;;
  46. *)
  47. break
  48. ;;
  49. esac
  50. done
  51. fi
  52. fi
  53. echo -n "" > /tmp/pupcamera_ports
  54. CAMERAINFO=""
  55. if [ "$BUSNUM" ];then
  56. #get product description from lsusb (usbutils pkg)...
  57. VENDORINSERT=""
  58. if which lsusb;then
  59. if [ "`lsusb --help 2>&1 | grep -i 'busybox'`" = "" ];then #want the full lsusb
  60. VENDORDESC="`lsusb -s ${BUSNUM}:${DEVNUM} | tr -s ' ' | cut -f 3-9 -d ':' | cut -f 2-99 -d ' '`"
  61. if [ "$VENDORDESC" ];then
  62. VENDORINSERT="$(gettext 'The camera has identified itself as:')
  63. <b>${VENDORDESC}</b>
  64. "
  65. fi
  66. fi
  67. fi
  68. CAMERAINFO="$(gettext 'A camera is detected connected via USB.')
  69. $(gettext 'The Linux kernel has identified it as:')
  70. $(gettext 'Type:') <b>${PRODUCTDESC}</b>
  71. $(gettext 'Connected on port: usb:')${BUSNUM},${DEVNUM}
  72. ${VENDORINSERT}"
  73. echo "usb:${BUSNUM},${DEVNUM}" >> /tmp/pupcamera_ports
  74. fi
  75. PROBEINFO=""
  76. if [ "`which gphoto2`" ];then
  77. GPHOTOPROBE="`gphoto2 --auto-detect | tr -s ' ' | tail -n +3`"
  78. if [ "$GPHOTOPROBE" ];then
  79. PROBEINFO="$(gettext "A probe by the 'gphoto2' utility has detected a camera, so it is likely that this camera will be accessable. Results of probe:")
  80. <b>${GPHOTOPROBE}</b>"
  81. PROBEPORTS="`echo "$GPHOTOPROBE" | sed -e 's% *$%%' | rev | cut -f 1 -d ' ' | rev`"
  82. echo "$PROBEPORTS" >> /tmp/pupcamera_ports
  83. else
  84. if [ -s /tmp/pupcamera_ports ];then
  85. PROBEINFO="<b>$(gettext "No camera is detected.")</b>
  86. $(gettext "It means that the Gphoto software in puppy does not recognise the camera. (But, you can try, click the 'Open' button)")"
  87. else
  88. PROBEINFO="<b>$(gettext "No camera is detected.")</b>
  89. $(gettext "It means that the Gphoto software in puppy does not recognise the camera.")"
  90. fi
  91. fi
  92. else
  93. #gphoto (and deps) not installed...
  94. PROBEINFO="<b>$(gettext "The 'gphoto' application is not installed.")</b>
  95. $(gettext "That means PupCamera cannot access the photos on a digital camera. Please run the Puppy Package Manager (see 'install' icon on desktop) to install 'gphotofs' and it's dependencies.")"
  96. echo -n "" > /tmp/pupcamera_ports #remove button.
  97. fi
  98. if [ "`which gphotofs`" = "" ]; then #111015
  99. PROBEINFO="<b>$(gettext "The 'gphotofs' application is not installed.")</b>
  100. $(gettext "That means PupCamera cannot access the photos on a digital camera. Please run the Puppy Package Manager (see 'install' icon on desktop) to install 'gphotofs' and it's dependencies.")"
  101. fi
  102. func_splash(){
  103. /usr/lib/gtkdialog/box_splash -placement center -timeout 5 -fontsize large -text "$(gettext 'Please wait...')" &
  104. }
  105. export -f func_splash
  106. if [ -s /tmp/pupcamera_ports ];then
  107. CAMCNT=1
  108. for ONEPORT in `cat /tmp/pupcamera_ports | sort -u | tr '\n' ' '`
  109. do
  110. mkdir -p /mnt/camera${CAMCNT} #"${OPENBUTTON}"
  111. OPENBUTTON="${OPENBUTTON}"'
  112. <button space-expand="false" space-fill="false">
  113. '"`/usr/lib/gtkdialog/xml_button-icon open`"'
  114. <label>'$(gettext 'Open')' '${ONEPORT}'</label>
  115. <action>gphotofs --port='${ONEPORT}' /mnt/camera'${CAMCNT}'</action>
  116. <action>func_splash</action>
  117. <action>rox -x /mnt/camera'${CAMCNT}' -d /mnt/camera'${CAMCNT}' & </action>
  118. <action>enable:BTN_CLOSE</action>
  119. </button>'
  120. CAMCNT=$(($CAMCNT + 1))
  121. done
  122. ICON=photocamera_yes.svg
  123. else
  124. OPENBUTTON='<button space-expand="false" space-fill="false">'"`/usr/lib/gtkdialog/xml_button-icon open`"'<label>'$(gettext 'Open camera')'</label><sensitive>falsw</sensitive></button>'
  125. ICON=photocamera_no.svg
  126. fi
  127. [ -s /tmp/pupcamera_ports ] && MSG2="$(gettext "click 'Open' button to access photos on your camera. A ROX-Filer window will pop up, and if you are then able to see your photos, it worked.")" || MSG=""
  128. #main gui
  129. S='
  130. <window title="PupCamera - '$(gettext 'Access digital camera')'" icon-name="gtk-orientation-landscape">
  131. <vbox>
  132. <frame '$(gettext 'Detected camera')'>
  133. '"`/usr/lib/gtkdialog/xml_info scale "$ICON" 60 "${CAMERAINFO}" "${PROBEINFO}" " " "$MSG2" "$(gettext "Please click the 'Close camera' button when you have finished accessing your camera...")"`"'
  134. <text height-request="20"><label>""</label></text>
  135. <hbox homogeneous="true">
  136. <hbox space-expand="false" space-fill="false">
  137. '${OPENBUTTON}'
  138. <button space-expand="false" space-fill="false">
  139. '"`/usr/lib/gtkdialog/xml_button-icon close`"'
  140. <label>'$(gettext 'Close camera')'</label>
  141. <variable>BTN_CLOSE</variable>
  142. <action>rox -D /mnt/camera1</action>
  143. <action>umount /mnt/camera1</action>
  144. <action>rox -D /mnt/camera2</action>
  145. <action>umount /mnt/camera2</action>
  146. <sensitive>false</sensitive>
  147. </button>
  148. </hbox>
  149. </hbox>
  150. <text height-request="5"><label>""</label></text>
  151. </frame>
  152. <hbox space-expand="false" space-fill="false">
  153. <button>
  154. '"`/usr/lib/gtkdialog/xml_button-icon refresh`"'
  155. <label>'$(gettext 'Rescan')'</label>
  156. <action>EXIT:rescan</action>
  157. </button>
  158. <button>
  159. '"`/usr/lib/gtkdialog/xml_button-icon quit`"'
  160. <label>'$(gettext 'Quit')'</label>
  161. <action>EXIT:finished</action>
  162. </button>
  163. </hbox>
  164. </vbox>
  165. </window>'
  166. . /usr/lib/gtkdialog/xml_info gtk #build bg_pixmap for gtk-theme
  167. export PupCamera="$S"
  168. RETVALS="`gtkdialog -p PupCamera`"
  169. umount /mnt/camera1 2>/dev/null #precaution.
  170. umount /mnt/camera2 2>/dev/null #precaution.
  171. [ "`echo "$RETVALS" | grep 'rescan'`" != "" ] && exec pupcamera #reenter.
  172. ###END###