pupzip 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. #!/bin/bash
  2. #Barry Kauler 2005 www.puppylinux.com
  3. #frontend for XArchive.
  4. #well, i want this to be a universal archiver frontend for puppy.
  5. #v4.00 25apr2008 BK: now have full dpkg-deb in Puppy.
  6. #w474 support .delta, .bfe files.
  7. #100616 support .xz files. support slackware and arch pkgs.
  8. #110620 busybox rpm2cpio does not work with mageia rpms, use 'exploderpm' instead (in /usr/sbin, permanent builtin).
  9. #120203 rodin.s: internationalized.
  10. #120512 added support for .rar (needs unrar or rar pkg installed).
  11. #131224 SFR: huge rewrite + added support for a few more common formats/extensions
  12. export TEXTDOMAIN=pupzip
  13. export TEXTDOMAINDIR=/usr/share/locale
  14. export OUTPUT_CHARSET=UTF-8
  15. # -----------------------------------------------------------------------------
  16. eval_gettext () {
  17. local myMESSAGE=$(gettext "$1")
  18. eval echo \"$myMESSAGE\"
  19. }
  20. error_msg () {
  21. xmessage -bg red -center -title "$(gettext 'PupZip: ERROR')" "$1"
  22. }
  23. request_msg () {
  24. xmessage -bg yellow -buttons "$(gettext 'Yes'):100,$(gettext 'No'):101" -center -title "PupZip" "$1"
  25. }
  26. check_xarchive () {
  27. if [ ! "$XARCHIVE" ]; then
  28. xmessage -bg "orange red" -center -title "$(gettext 'PupZip: ERROR')" "$(gettext 'No archive GUI program found.
  29. Please install XArchive.')"
  30. exit 1
  31. fi
  32. }
  33. add_to_xarchive () {
  34. check_xarchive
  35. if [ "$XARCHIVE" = "xarchive" ];then
  36. exec $XARCHIVE --add=ask "$@"
  37. else
  38. error_msg "$(gettext 'Not an archive file')"
  39. exit 1
  40. fi
  41. }
  42. # -----------------------------------------------------------------------------
  43. CDIR="`pwd`"
  44. EXTENSION="`echo "$1" | tr [:upper:] [:lower:]`"
  45. UNPACK_CMD=
  46. # SFR: dunno if that TkZip/guitar stuff is still really needed, but let it be, whatever...
  47. XARCHIVE=
  48. for i in xarchive TkZip guitar; do
  49. [ "`which $i 2>/dev/null`" ] && { XARCHIVE="$i"; break; }
  50. done
  51. # -----------------------------------------------------------------------------
  52. if [ "$1" = "" ];then
  53. #just start xarchive...
  54. check_xarchive
  55. exec $XARCHIVE
  56. elif [ "$1" = "--help" ];then
  57. if [ "$XARCHIVE" = "xarchive" ];then
  58. MSGE="$(gettext 'Drag and drop invocation of XArchive is achieved by dragging any file or
  59. directory to the "pupzip" icon on the desktop. If you drag one of the
  60. recognised archived files, such as .tar.gz, .rpm, .deb, .zip, .tar.bz2,
  61. it will open in XArchive and you will be given the opportunity to extract
  62. it. If you drag an ordinary file to the desktop icon, such as for example
  63. "myfile.txt", a XArchive will popup a dialog asking if you want to add
  64. it to an existing archive or create a new one.')"
  65. else
  66. MSGE="$(gettext 'There is support for drag-and-drop of archive files to the desktop icon,
  67. however not for files and directories -- for that you need to have
  68. XArchive installed, the preferred archiver program for Puppy.')"
  69. fi
  70. xmessage -bg "orange" -center -title "$(gettext 'PupZip: help')" "
  71. `eval_gettext \"This is a frontend to \\\$XARCHIVE, which in turn is a frontend to the\"`
  72. $(gettext 'archiver utilities in Puppy (such as gzip, bzip2, dpkg, rpm, zip).')
  73. `eval_gettext \"Note: \\\$XARCHIVE can be started in the conventional way via the menu.\"`
  74. $MSGE
  75. $(gettext 'PupZip can also be invoked from Rox by the "Open With..." menu,
  76. by right-clicking on a file or directory.')"
  77. exit
  78. fi
  79. # -----------------------------------------------------------------------------
  80. # if multiple input files/dirs or directory itself - always add to xarchive!
  81. if [ "$#" -gt 1 ] || [ -d "$1" ]; then
  82. add_to_xarchive "$@"
  83. fi
  84. # -----------------------------------------------------------------------------
  85. case "$EXTENSION" in
  86. *.bfe)
  87. exec bcrypt_gui "$1"
  88. ;;
  89. # -----------
  90. *.delta)
  91. exec xdelta_gui "$1"
  92. ;;
  93. # -----------
  94. *.rpm)
  95. #busybox applets are not adequate for handling rpm, deb...
  96. #get absolute path of file...
  97. if [ "`echo -n "$1" | cut -b 1`" = "/" ];then
  98. FULLSPEC="$1"
  99. else
  100. #relative path...
  101. if [ "$CDIR" = "/" ];then
  102. FULLSPEC="/$1"
  103. else
  104. FULLSPEC="$CDIR/$1"
  105. fi
  106. fi
  107. TMPARCH=/tmp/temprpm_${RANDOM}_${$}
  108. mkdir $TMPARCH
  109. cd $TMPARCH
  110. #110620 rpm2cpio does not always work, use exploderpm...geany
  111. #exploderpm -x "$FULLSPEC" #a script in /usr/sbin, uses cpio.
  112. # SFR: hack - exploderpm can handle extensions only in lower-case
  113. # so let's call appropriate function directly
  114. . exploderpm
  115. OPT='-x'; explode_rpm "$FULLSPEC"
  116. if [ $? -ne 0 ];then
  117. error_msg "$(gettext 'An error has occurred opening the RPM file.')"
  118. exit 1
  119. fi
  120. sync
  121. tar -c -f $TMPARCH.tar .
  122. rm -rf $TMPARCH
  123. cd /
  124. $XARCHIVE $TMPARCH.tar
  125. rm -f $TMPARCH.tar
  126. cd $CDIR
  127. exit
  128. ;;
  129. # -----------
  130. *.7z|*.arj|*.deb|*.rar|*.tar|*.tar.bz|*.tar.bz2|*.tar.gz|*.tar.lzma|*.tar.xz|*.tbz|*.tbz2|*.tgz|*.tlz|*.txz|*.zip)
  131. #ask if this is a slackware or arch binary pkg...
  132. case "$EXTENSION" in
  133. *.tgz|*.txz|*.pkg.tar.gz)
  134. request_msg "$(gettext 'Is this a Slackware or Arch package, that you want to install?')
  135. $(gettext 'If you answer Yes, the Package Manager application will run...')
  136. $(gettext 'If you answer No, the XArchive application will run...')"
  137. [ $? -eq 100 ] && exec petget "$1"
  138. ;;
  139. esac
  140. check_xarchive
  141. exec $XARCHIVE "$1"
  142. ;;
  143. # -----------
  144. *.gz) UNPACK_CMD=gzip ;;
  145. *.bz|*.bz2) UNPACK_CMD=bzip2 ;;
  146. *.lzma|*.xz) UNPACK_CMD=xz ;;
  147. # -----------
  148. *) add_to_xarchive "$1" ;;
  149. esac
  150. # handle gz|bz(2)|lzma|xz internally
  151. [ "`which $UNPACK_CMD 2>/dev/null`" ] || { error_msg "`gettext \"ERROR: '$UNPACK_CMD' utility not installed\"`"; exit 1; }
  152. request_msg "$(gettext 'Do you want to decompress') ${1}?
  153. ($(gettext 'it will decompress in current location
  154. and the original file will be deleted'))"
  155. [ $? -ne 100 ] && exit
  156. yaf-splash -bg orange -text "$(gettext 'Uncompressing, please wait...')" &
  157. UPID=$!
  158. # busybox applets, as well as full bzip2, don't support '--suffix' option
  159. if [ "$UNPACK_CMD" = "bzip2" ] || [ "`readlink -e \`which $UNPACK_CMD\` | grep 'busybox'`" ]; then
  160. $UNPACK_CMD -d "$1"
  161. else
  162. $UNPACK_CMD --suffix=".${1##*.}" -d "$1" # in case if extension is in upper-case
  163. fi
  164. sync
  165. kill $UPID
  166. exit
  167. ###END###