dir2pet 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. #!/bin/sh
  2. #Barry Kauler (c) Copyight 2007,2009 www.puppylinux.com
  3. #2007 Lesser GPL licence v2 (http://www.fsf.org/licensing/licenses/lgpl.html)
  4. #This script will create a PET package.
  5. #Just create a directory with the name of the package, for example 'abiword-0.5.6'
  6. #and put what you want in it.
  7. #It should have abiword-0.5.6/usr/share/applications/abiword.desktop if the
  8. #application requires a menu entry, but if there isn't one this script will ask
  9. #some simple questions and create one.
  10. #This script will also create abiword-0.5.6/pet.specs, which has
  11. #some information useful to the Puppy Package Manager.
  12. #w476, w478 fixes to work with petspec.
  13. #w482 if preexisting pet.specs, read fields from it.
  14. #100201 improve reading of pet.specs
  15. #100303 fix bug detection arch-dependent pkg.
  16. #130305 rerwin: ensure package tmp directory, if any, has all permissions.
  17. #131122 support xz compressed pets (see installpkg.sh, pet2tgz)
  18. #131123 changed default to gzip, will change it back in a year or 2
  19. if [ ! $1 ];then
  20. echo "It is required to invoke this script like this:
  21. # dir2pet abiword-0.5.6
  22. where abiword-0.5.6 is a directory in the same directory
  23. in which this terminal window is open. 'abiword-0.5.6' is
  24. just an example, and contains subdirectories and files
  25. that will become the PET package."
  26. exit
  27. fi
  28. if [ ! -d $1 ];then
  29. echo "$1 must be a directory"
  30. exit
  31. fi
  32. ADIR=$1
  33. MYPID=${$}
  34. #split ADIR path/filename into components...
  35. BASEPKG="`basename $ADIR`"
  36. DIRPKG="`dirname $ADIR`"
  37. [ "$DIRPKG" = "/" ] && DIRPKG=""
  38. #w482 directory may already have a pet.specs, reuse it...
  39. NAMEONLY=""
  40. PUPMENUDESCR=""
  41. PUPOFFICIALDEPS=""
  42. PUPCATEGORY=""
  43. PUPPATH="" #100201
  44. ARCHDEPENDENT="yes" #100201
  45. DEFREPO="" #100201
  46. if [ -f ${1}/pet.specs ];then
  47. #new: pkgname|nameonly|version|pkgrelease|category|size|path|fullfilename|dependencies|description|
  48. #optionally on the end: compileddistro|compiledrelease|repo| (fields 11,12,13)
  49. PETSPECS="`cat ${1}/pet.specs | head -n 1`"
  50. DB_pkgname="`echo -n "$PETSPECS" | cut -f 1 -d '|'`"
  51. DB_nameonly="`echo -n "$PETSPECS" | cut -f 2 -d '|'`"
  52. NAMEONLY="$DB_nameonly"
  53. DB_version="`echo -n "$PETSPECS" | cut -f 3 -d '|'`"
  54. DB_pkgrelease="`echo -n "$PETSPECS" | cut -f 4 -d '|'`"
  55. DB_category="`echo -n "$PETSPECS" | cut -f 5 -d '|'`"
  56. PUPCATEGORY="$DB_category"
  57. DB_size="`echo -n "$PETSPECS" | cut -f 6 -d '|'`"
  58. DB_path="`echo -n "$PETSPECS" | cut -f 7 -d '|'`"
  59. PUPPATH="$DB_path" #100201
  60. DB_fullfilename="`echo -n "$PETSPECS" | cut -f 8 -d '|'`"
  61. DB_dependencies="`echo -n "$PETSPECS" | cut -f 9 -d '|'`"
  62. PUPOFFICIALDEPS="$DB_dependencies"
  63. DB_description="`echo -n "$PETSPECS" | cut -f 10 -d '|'`"
  64. PUPMENUDESCR="$DB_description"
  65. DB_compileddistro="`echo -n "$PETSPECS" | cut -f 11 -d '|'`"
  66. DB_compiledrelease="`echo -n "$PETSPECS" | cut -f 12 -d '|'`"
  67. ARCHDEPENDENT="${DB_compileddistro}|${DB_compiledrelease}"
  68. DB_repo="`echo -n "$PETSPECS" | cut -f 13 -d '|'`"
  69. DEFREPO="$DB_repo"
  70. fi
  71. #difficult task, separate package name from version part...
  72. #not perfect, some start with non-numeric version info...
  73. [ "$NAMEONLY" = "" ] && NAMEONLY="`echo -n "$BASEPKG" | sed -e 's/\-[0-9].*$//g'`"
  74. #...if that fails, do it the old way...
  75. [ "$NAMEONLY" = "$BASEPKG" ] && NAMEONLY="`echo "$BASEPKG" | cut -f 1 -d "-"`"
  76. clear
  77. echo "Welcome to the 'dir2pet' script."
  78. echo "This will convert a directory into a PET package. Example, you have a "
  79. echo "directory named 'abiword-0.5.6' and inside that you place whatever is"
  80. echo "needed for the package, for example usr/local/bin/abiword (the executable)"
  81. echo "and usr/share/applications/abiword.desktop (the XDG menu file)."
  82. echo "Whatever the packages needs, though don't worry if there is no .desktop"
  83. echo "file as this script will ask some simple questions and optionally create"
  84. echo "one. The package only needs a .desktop file if a menu entry is to be"
  85. echo "created, and also an icon is required for the menu."
  86. echo
  87. echo "The directory $BASEPKG must separate name of the package and"
  88. echo "version number with a dash. Ex: abiword-0.5.6"
  89. echo
  90. echo "The package may optionally have post-install and post-remove scripts,"
  91. echo "named 'pinstall.sh' and 'puninstall.sh' placed at the top directory."
  92. echo "(to create official PETs for the Unleashed suite, see its README file"
  93. echo " for more information how to create these scripts properly)"
  94. echo
  95. echo "If any of the above needs to be further sorted out, you can quit this"
  96. echo "script right now by pressing CTRL-C, otherwise just press ENTER"
  97. echo "to use the default \"gzip\" compression or \"x\" then ENTER for newer"
  98. echo "\"xz\" compression."
  99. echo -n "Press ENTER key or \"x\" and ENTER to continue: "
  100. read goforit
  101. case $goforit in
  102. x)EXT="xz"
  103. echo
  104. echo "Newer xz compression chosen."
  105. sleep 1;;
  106. *)EXT="gz" ;;
  107. esac #131122, 131123
  108. . /etc/xdg/menus/hierarchy #has PUPHIERARCHY variable.
  109. DESKTOPFILE=""
  110. ADESKTOPFILE="`find $ADIR -type f -name \*.desktop`"
  111. [ "$ADESKTOPFILE" != "" ] && DESKTOPFILE="yes"
  112. echo
  113. echo -en "\\033[1;31mStep 1" #red
  114. echo -e "\\033[0;39m"
  115. if [ "$DESKTOPFILE" = "" ];then
  116. echo "Currently there is no .desktop file (they are usually at usr/share/applications"
  117. echo "or usr/local/share/applications), so perhaps this package is not supposed to"
  118. echo "have a menu entry? You can optionally create one though..."
  119. echo "If you know that the ${BASEPKG} application does not require"
  120. echo "a menu entry, press the ENTER key only."
  121. echo "If a menu entry is required, type any printable character then ENTER."
  122. echo "(if in doubt, just press ENTER key)"
  123. echo -n "Type a printable character or just ENTER key: "
  124. read YESMENU
  125. [ "$YESMENU" = "" ] && DESKTOPFILE="ignore"
  126. else #w476
  127. echo "A .desktop file was found here:"
  128. echo "$ADESKTOPFILE"
  129. echo "So this application will have a menu entry."
  130. echo "If you want to change the .desktop file in any way, open it in a text editor"
  131. echo "right now, before proceeding and make any changes you want."
  132. echo "In particular, check that the icon exists, and that 'Category' entry fits"
  133. echo "into Puppy's menu hierarchy (see file /etc/xdg/menus/hierarchy)."
  134. echo "After satisfying yourself that the .desktop file is ok, press the ENTER key"
  135. echo "to continue this script."
  136. echo "Or, type 'ignore' to build pet pkg as if there is no .desktop file."
  137. echo "Or, type 'new' if you would like this script to ask a series of"
  138. echo -n "questions and rebuild the .desktop file from scratch: "
  139. read NEWMENU
  140. [ "$NEWMENU" = "ignore" ] && DESKTOPFILE="ignore" #w478
  141. if [ "$NEWMENU" = "new" ];then
  142. for ONEDESKTOP in $ADESKTOPFILE
  143. do
  144. BASEDESK="`basename $ONEDESKTOP .desktop`"
  145. DIRDESK="`dirname $ONEDESKTOP`"
  146. echo "Moving ${DIRDESK}/${BASEDESK}.desktop to /tmp"
  147. mv -f ${DIRDESK}/${BASEDESK}.desktop /tmp/
  148. done
  149. DESKTOPFILE=""
  150. fi
  151. fi
  152. PUPAPPLICATION=""
  153. PUPEXECUTABLE=""
  154. PUPICON16=""
  155. PUPAPPLICATION=""
  156. if [ "$DESKTOPFILE" = "yes" ];then #w476
  157. #get some info out of it...
  158. FIRSTDESKTOPFILE="`echo -n "$ADESKTOPFILE" | head -n 1`"
  159. PUPCATEGORY="`cat $FIRSTDESKTOPFILE | grep '^Categories=' | cut -f 2 -d '='`"
  160. PUPEXECUTABLE="`cat $FIRSTDESKTOPFILE | grep '^Exec=' | cut -f 2 -d '='`"
  161. PUPICON16="`cat $FIRSTDESKTOPFILE | grep '^Icon=' | cut -f 2 -d '='`"
  162. PUPMENUDESCR="`cat $FIRSTDESKTOPFILE | grep '^Comment=' | cut -f 2 -d '='`"
  163. [ "$PUPMENUDESCR" = "" ] && PUPMENUDESCR="`cat $FIRSTDESKTOPFILE | grep '^Name=' | cut -f 2 -d '='`"
  164. [ "$PUPMENUDESCR" = "" ] && PUPMENUDESCR="`cat $FIRSTDESKTOPFILE | grep '^GenericName=' | cut -f 2 -d '='`"
  165. fi
  166. if [ "$DESKTOPFILE" = "" ];then
  167. echo
  168. echo -en "\\033[1;31mStep 1B" #red
  169. echo -e "\\033[0;39m"
  170. echo "Please type the category in which you want the application"
  171. echo "to create a window manager menu entry. The official Puppy"
  172. echo "has a menu hierarchy as follows:"
  173. echo "('X-' categories are unofficial, Puppy-specific)"
  174. echo "$PUPHIERARCHY"
  175. echo
  176. echo -n "Type one word from the CATEGORIES column: "
  177. read PUPCATEGORY
  178. echo
  179. echo -en "\\033[1;31mStep 1C" #red
  180. echo -e "\\033[0;39m"
  181. echo "Please enter the name of the executable. If it is in the"
  182. echo "executable-search-path, namely /bin, /sbin, /usr/bin,"
  183. echo "/usr/sbin, /root/my-applications/bin or /usr/local/bin,"
  184. echo "then you only need to enter the name of the executable"
  185. echo "not the path. Example: mtpaint"
  186. echo "(of course, if you need to specify the path here, it is"
  187. echo " the path AFTER the package is installed)"
  188. echo
  189. echo -n "Enter [path]executable: "
  190. read PUPEXECUTABLE
  191. echo
  192. echo -en "\\033[1;31mStep 1D" #red
  193. echo -e "\\033[0;39m"
  194. echo "Please enter the name of the icon that is to be used in"
  195. echo "the window manager menu entry."
  196. echo "It is preferred that you specify the full path."
  197. echo
  198. echo -n "Please type [path]icon: "
  199. read PUPICON16
  200. echo
  201. echo -en "\\033[1;31mStep 1E" #red
  202. echo -e "\\033[0;39m"
  203. echo "Please enter the name of the application, as you wish it to"
  204. echo "appear in the menu. It will be the first word in the menu entry."
  205. echo "Example: Abiword"
  206. echo
  207. echo -n "Type application name: "
  208. read PUPAPPLICATION
  209. fi
  210. if [ "$PUPMENUDESCR" = "" ];then #w476
  211. echo
  212. echo -en "\\033[1;31mDescription" #red
  213. echo -e "\\033[0;39m"
  214. echo "Please enter a description of 1-3 words."
  215. if [ "$DESKTOPFILE" = "" ];then
  216. echo "This must be extremely short. as it will appear in the window"
  217. echo "manager menu entry immediately after the application name."
  218. fi
  219. echo "This may be used for various purposes, such by PETget for package"
  220. echo "management purposes."
  221. echo "Example for Abiword: powerful wordprocessor"
  222. echo
  223. echo -n "Type the VERY SHORT description (without quotes): "
  224. read PUPMENUDESCR
  225. #else
  226. # echo "A description of the package has been extracted:"
  227. # echo " '${PUPMENUDESCR}'"
  228. # echo "This will be placed in the package database entry. Press ENTER if ok,"
  229. # echo -n "or type an alternative very short description: "
  230. # read NEWDESCR
  231. # if [ "$NEWDESCR" != "" ];then
  232. # PUPMENUDESCR="$NEWDESCR"
  233. # fi
  234. fi
  235. echo
  236. #if pkg is a split-off, already has a known dependency...
  237. DEPBASE="";DEPNOTE=""
  238. [ ! "`echo -n "$NAMEONLY" | grep '_DEV'`" = "" ] && DEPBASE="+`echo -n "$NAMEONLY" | sed -e 's/_DEV//g'`"
  239. [ ! "`echo -n "$NAMEONLY" | grep '_DOC'`" = "" ] && DEPBASE="+`echo -n "$NAMEONLY" | sed -e 's/_DOC//g'`"
  240. [ ! "`echo -n "$NAMEONLY" | grep '_NLS'`" = "" ] && DEPBASE="+`echo -n "$NAMEONLY" | sed -e 's/_NLS//g'`"
  241. if [ ! "$DEPBASE" = "" ];then
  242. DEPNOTE="NOTE5: It is strongly suggested that you at least enter ${DEPBASE}
  243. the main package
  244. "
  245. fi
  246. if [ "$PUPOFFICIALDEPS" = "" ];then
  247. echo
  248. echo -en "\\033[1;31mDependencies" #red
  249. echo -e "\\033[0;39m"
  250. echo "Please enter a dependency-list for the PET package that is now being"
  251. echo "created. Packages already built-in to Puppy do not need to be"
  252. echo "explicitly named as dependencies (except a cut-down barebones version"
  253. echo "of Puppy may not have all of these built in, so you may have to"
  254. echo "think of the worst-case situation)."
  255. echo "How to enter this dependency-list is shown by an example: the package"
  256. echo "'pupdvdtool-0.5b' has the following dependency list:"
  257. echo "+vamps,+vobcopy,+ffmpeg,+dvdauthor,+gtkdialog3"
  258. echo "Each package name is preceded by a '+' and delimited by a ','."
  259. echo "NOTE1: that 'gtkdialog3' requires the GTK libraries, but it is not"
  260. echo " necessary to specify sub-dependencies, as if 'gtkdialog3'"
  261. echo " needs to be installed it has its own dependency list."
  262. echo "NOTE2: You can lookup the dependency-list of each package in the"
  263. echo " /root/.packages/Packages-* database files"
  264. echo "NOTE3: it is not required to specify package version numbers,"
  265. echo " VERSION NUMBERS NOT YET SUPPORTED BY PACKAGE MANAGER"
  266. echo "NOTE4: If you don't know what to specify, just press ENTER key"
  267. echo " (the package manager will still do some basic dependency checking)"
  268. echo "$DEPNOTE"
  269. echo -n "Type dependency-list: "
  270. read PUPOFFICIALDEPS
  271. fi
  272. echo
  273. echo -en "\\033[1;31mGUI window" #red
  274. echo -e "\\033[0;39m"
  275. #create tarball...
  276. rm -f $DIRPKG/${BASEPKG}.tar 2>/dev/null
  277. rm -f $DIRPKG/${BASEPKG}.tar.${EXT} 2>/dev/null
  278. rm -f $DIRPKG/${BASEPKG}.pet 2>/dev/null
  279. if [ "$DESKTOPFILE" = "" ];then
  280. mkdir -p $DIRPKG/$BASEPKG/usr/share/applications
  281. echo '[Desktop Entry]' > $DIRPKG/$BASEPKG/usr/share/applications/${NAMEONLY}.desktop
  282. echo 'Encoding=UTF-8' >> $DIRPKG/$BASEPKG/usr/share/applications/${NAMEONLY}.desktop
  283. echo "Name=${PUPAPPLICATION} ${PUPMENUDESCR}" >> $DIRPKG/$BASEPKG/usr/share/applications/${NAMEONLY}.desktop
  284. echo "Icon=${PUPICON16}" >> $DIRPKG/$BASEPKG/usr/share/applications/${NAMEONLY}.desktop
  285. echo "Comment=${PUPAPPLICATION} ${PUPMENUDESCR}" >> $DIRPKG/$BASEPKG/usr/share/applications/${NAMEONLY}.desktop
  286. echo "Exec=${PUPEXECUTABLE}" >> $DIRPKG/$BASEPKG/usr/share/applications/${NAMEONLY}.desktop
  287. echo "Terminal=false" >> $DIRPKG/$BASEPKG/usr/share/applications/${NAMEONLY}.desktop
  288. echo "Type=Application" >> $DIRPKG/$BASEPKG/usr/share/applications/${NAMEONLY}.desktop
  289. echo "Categories=${PUPCATEGORY}" >> $DIRPKG/$BASEPKG/usr/share/applications/${NAMEONLY}.desktop
  290. echo "GenericName=${PUPAPPLICATION} ${PUPMENUDESCR}" >> $DIRPKG/$BASEPKG/usr/share/applications/${NAMEONLY}.desktop
  291. echo
  292. echo "File $DIRPKG/$BASEPKG/usr/share/applications/${NAMEONLY}.desktop created."
  293. echo
  294. fi
  295. #100201 determine if pkg is ditro-independent (scripts only)...
  296. ARCHINDEPENDENT='yes'
  297. for ONEEXEC in `find $DIRPKG/$BASEPKG -maxdepth 6 -type f -perm -o+x`
  298. do
  299. [ -f $ONEEXEC ] && [ "`file $ONEEXEC | grep ' ELF '`" != "" ] && ARCHINDEPENDENT='no'
  300. done
  301. [ "`find $DIRPKG/$BASEPKG -maxdepth 6 -type f -name '*.a' -o -type f -name 'lib*.so*' -o -type f -name '*.la'`" != "" ] && ARCHINDEPENDENT='no' #100303
  302. #[ "`echo "${BASEPKG}" | grep '_DEV'`" != "" ] && ARCHINDEPENDENT='no' #100303
  303. [ "$ARCHINDEPENDENT" = "yes" ] && ARCHDEPENDENT='no'
  304. echo "Press ENTER key to bring up a GUI window that will help you to create"
  305. echo "a database entry for the package. This will be shown in a text editor"
  306. echo "for saving somewhere, also written to file 'pet.specs' inside the pkg."
  307. echo -n "Press ENTER: "
  308. read enternow
  309. SIZEK="`du -s -k $DIRPKG/$BASEPKG | cut -f 1`" #w476
  310. [ "${PUPCATEGORY}" = "" ] && PUPCATEGORY="EMPTY"
  311. #if PUPCATEGORY is in format 'entry1;entry2;' extract only 'entry2'...
  312. xPUPCATEGORY="`echo -n "$PUPCATEGORY" | tr ';' ' ' | tr -s ' ' | sed -e 's% $%%' | rev | cut -f 1 -d ' ' | rev`"
  313. TOPCAT="`echo "$PUPHIERARCHY" | grep "$xPUPCATEGORY" | cut -f 1 -d ' ' | head -n 1`"
  314. [ "${TOPCAT}" = "" ] && TOPCAT="EMPTY"
  315. [ "${PUPOFFICIALDEPS}" = "" ] && PUPOFFICIALDEPS="EMPTY"
  316. [ "${PUPMENUDESCR}" = "" ] && PUPMENUDESCR="EMPTY"
  317. [ "${PUPPATH}" = "" ] && PUPPATH="EMPTY" #100201
  318. [ "${DEFREPO}" = "" ] && DEFREPO="EMPTY" #100201
  319. petspec "${NAMEONLY}" "${TOPCAT}" "${PUPOFFICIALDEPS}" "${PUPMENUDESCR}" "$BASEPKG" "$SIZEK" "$PUPPATH" "$ARCHDEPENDENT" "$DEFREPO" #100201
  320. if [ $? -ne 0 ];then
  321. echo "Aborted creation of PET package."
  322. exit
  323. fi
  324. [ -d $DIRPKG/$BASEPKG/tmp ] && chmod 1777 $DIRPKG/$BASEPKG/tmp #130305 rerwin.
  325. cat /tmp/petspec_db_entry | tail -n 1 > $DIRPKG/$BASEPKG/pet.specs
  326. echo
  327. echo "Creating package..."
  328. tar -c -f $DIRPKG/${BASEPKG}.tar $DIRPKG/$BASEPKG/
  329. sync
  330. #gzip --best $DIRPKG/${BASEPKG}.tar #131122
  331. case $EXT in
  332. xz)xz -z -9 -e $DIRPKG/${BASEPKG}.tar ;;
  333. gz)gzip --best $DIRPKG/${BASEPKG}.tar ;;
  334. esac
  335. #rmdir $DIRPKG/$BASEPKG
  336. TARBALL="$DIRPKG/${BASEPKG}.tar.${EXT}"
  337. advdef="$(which advdef)"
  338. [ -n "$advdef" ] && "$advdef" -z4 "$TARBALL"
  339. echo
  340. echo "File $DIRPKG/${BASEPKG}.tar.${EXT} created. Now converting to .pet..."
  341. FULLSIZE="`stat --format=%s ${TARBALL}`"
  342. MD5SUM="`md5sum $TARBALL | cut -f 1 -d ' '`"
  343. echo -n "$MD5SUM" >> $TARBALL
  344. sync
  345. mv -f $TARBALL $DIRPKG/${BASEPKG}.pet
  346. sync
  347. echo
  348. echo "${BASEPKG}.pet has been created. Finished."
  349. echo
  350. echo "If you look in ${BASEPKG} you will see the new '.specs' file."
  351. if [ "$DESKTOPFILE" = "" ];then
  352. echo "And in $BASEPKG/usr/share/applications/ the new '.desktop' file."
  353. fi
  354. echo "Directory $BASEPKG is now configured correctly as a PET package"
  355. echo "and in future you do not need to go through this script again."
  356. echo "You could manually edit the files if required, and create another"
  357. echo ".pet package just by doing this:"
  358. echo "# tar -c -f ${BASEPKG}.tar ${BASEPKG}/"
  359. case $EXT in
  360. xz)echo "# xz -z -9 -e ${BASEPKG}.tar" ;;
  361. gz)echo "# gzip --best ${BASEPKG}.tar" ;;
  362. esac
  363. echo "# tgz2pet ${BASEPKG}.tar.${EXT}"
  364. echo
  365. echo "dir2pet exited."
  366. ###END###