OpenSDE Framework (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

255 lines
5.6 KiB

  1. #!/bin/sh
  2. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. #
  5. # Filename: bin/sde-create-package
  6. # Copyright (C) 2008 - 2009 The OpenSDE Project
  7. #
  8. # More information can be found in the files COPYING and README.
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; version 2 of the License. A copy of the
  13. # GNU General Public License can be found in the file COPYING.
  14. # --- SDE-COPYRIGHT-NOTE-END ---
  15. #Description: Creates a new package
  16. #Alias: pkg
  17. [ -n "$SDEROOT" ] ||
  18. export SDEROOT=$( cd "${0%/*}/.."; pwd -P )
  19. . "$SDEROOT/lib/libsde.in"
  20. . "$SDEROOT/lib/sde-package.in"
  21. . "$SDEROOT/lib/sde-package/hives.in"
  22. create_usage() {
  23. local progname="$(echo "$0" | sed -e 's,.*/,,' -e 's,-, ,g')" hive=
  24. cat <<EOT
  25. Usage: $progname [--hive <hive>[:<index>]] [<repository>/][<package>] [hive arguments]
  26. Available Hives (--hivelist):
  27. EOT
  28. for hive in $( package_hives_list ); do
  29. desc=$( package_hive_desc "$hive" )
  30. aliases=$(package_hive_aliases "$hive" | tr ' ' ',')
  31. if [ "$hive" = 'download' ]; then
  32. default=yes
  33. else
  34. default=
  35. fi
  36. printf "%15s %s%s\n" "$hive" "${desc:-...}" "${aliases:+ (Alias: $aliases)}${default:+ (default)}"
  37. done
  38. }
  39. shortopts=
  40. longopts='help,hive:,hivelist'
  41. options=$( getopt -o "$shortopts" -l "$longopts" -- "$@" )
  42. if [ $? -ne 0 ]; then
  43. create_usage
  44. exit -1
  45. fi
  46. # load new arguments list
  47. eval set -- "$options"
  48. hive=
  49. hiveindex=
  50. hivelist=
  51. while [ $# -gt 0 ]; do
  52. case "$1" in
  53. --help)
  54. create_usage
  55. exit 0 ;;
  56. --hive)
  57. hive=$2; shift
  58. ;;
  59. --hivelist)
  60. hivelist=yes
  61. ;;
  62. --) shift; break ;;
  63. *) echo_abort 1 "$1: Unknown argument, aborting."
  64. esac
  65. shift
  66. done
  67. # just list know hives
  68. #
  69. if [ -n "$hivelist" ]; then
  70. for x in $( package_hives_list ); do
  71. echo $x
  72. done
  73. exit 0
  74. fi
  75. # validate the choosen hive
  76. #
  77. if [ -n "$hive" ]; then
  78. # split hive and hiveindex
  79. if expr "$hive" : ".*:.*" > /dev/null; then
  80. hiveindex="${hive#*:}"
  81. hive="${hive%%:*}"
  82. fi
  83. # translate into the real name of the hive, in the case the alias was gives
  84. x=$( package_hive_alias "$hive" )
  85. if [ -z "$x" ]; then
  86. echo_abort 1 "$hive: Invalid hive."
  87. else
  88. hive="$x"
  89. fi
  90. else
  91. # assume download hive of none is given
  92. hive='download'
  93. fi
  94. # $repo/$pkg
  95. #
  96. if [ $# -gt 0 ]; then
  97. pkg="$1"; shift
  98. else
  99. pkg=
  100. fi
  101. if [ -z "$pkg" ]; then
  102. echo_error "no package name given."
  103. create_usage
  104. exit 1
  105. elif expr "$pkg" : ".*/.*" > /dev/null; then
  106. # repository given
  107. repo="${pkg%/*}"
  108. pkg="${pkg##*/}"
  109. # sanitize $repo if needed
  110. if [ "$repo" = "." ]; then
  111. # detect repo based on $PWD
  112. repo=$( package_autodetect_repo )
  113. elif expr "$repo" : ".*/.*" > /dev/null; then
  114. # longer path
  115. if [ -d "$repo" ]; then
  116. # exists, go there and find out
  117. repo=$( cd "$repo"; package_autodetect_repo )
  118. else
  119. # doesn't exist
  120. repo="$PWD/$repo"
  121. if [ -d "${repo%/*}" ]; then
  122. repo=$( cd "$repo"; package_autodetect_repo )
  123. else
  124. echo_error "${repo#$PWD/}: Invalid repository"
  125. repo=
  126. fi
  127. fi
  128. fi
  129. else
  130. # detect repo based on $PWD
  131. repo=$( package_autodetect_repo )
  132. fi
  133. # base use wip/ if the detection failed
  134. repo="${repo:-wip}"
  135. # validate $pkg
  136. #
  137. confdir=$( package_confdir "$pkg" )
  138. [ -z "$confdir" ] || echo_abort 2 "$pkg: package already exists (${confdir#$SDEROOT/})."
  139. echo_info "Creating package/$repo/$pkg from $hive:${hiveindex:-$pkg}"
  140. # get info form the hive
  141. output=$( "$SDEROOT/lib/sde-package/hives/$hive" "${hiveindex:-$pkg}" "$@" )
  142. [ -n "$output" ] || echo_abort 1 "$hive failed to fetch ${hiveindex:-$pkg} information"
  143. # do we have content for the $1 tag?
  144. output_has_tag()
  145. {
  146. echo "$output" | grep -q "^\[$1\]"
  147. }
  148. # what do we know for the $1 tag?
  149. output_tag()
  150. {
  151. echo "$output" | grep "^\[$1\]" | sed -e 's,^\[[^]]\+\][ \t]*,,' -e 's,[ \t]*\$,,'
  152. }
  153. # checks if output has $1, and return $2 if not
  154. output_parse()
  155. {
  156. if output_has_tag "$1"; then
  157. output_tag "$1"
  158. else
  159. echo "$2"
  160. fi
  161. }
  162. # parse the output of the hive
  163. #
  164. # title
  165. title=$( output_parse I 'TODO: Short Information' )
  166. # desc
  167. desc=$( output_parse T 'TODO: Long Expanation
  168. TODO: Long Expanation
  169. TODO: Long Expanation
  170. TODO: Long Expanation
  171. TODO: Long Expanation' )
  172. # url
  173. url=$( output_parse U 'TODO: URL' )
  174. # author
  175. author=$( output_parse A 'TODO: Author' )
  176. # category
  177. category=$( output_parse C 'TODO: Category' )
  178. # license
  179. license=$( output_parse L 'TODO: License' )
  180. # status
  181. status=$( output_parse S 'TODO: Status' )
  182. # version
  183. version=$( output_parse V 'TODO: Version' )
  184. # download
  185. download=$( output_parse D '' )
  186. # create the confdir
  187. mkdir -p "$SDEROOT/package/$repo/$pkg"
  188. # create $confdir/$pkg.desc
  189. TAG=SDE-COPYRIGHT-NOTE
  190. (
  191. cat <<EOT
  192. [COPY] --- $TAG-BEGIN ---
  193. [COPY] This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  194. [COPY]
  195. [COPY] Filename: package/.../$pkg/$pkg.desc
  196. [COPY] Copyright (C) $( date +%Y ) The OpenSDE Project
  197. [COPY]
  198. [COPY] More information can be found in the files COPYING and README.
  199. [COPY]
  200. [COPY] This program is free software; you can redistribute it and/or modify
  201. [COPY] it under the terms of the GNU General Public License as published by
  202. [COPY] the Free Software Foundation; version 2 of the License. A copy of the
  203. [COPY] GNU General Public License can be found in the file COPYING.
  204. [COPY] --- $TAG-END ---
  205. [I] $title
  206. $( echo "$desc" | sed -e 's,^,[T] ,' )
  207. [U] $url
  208. [A] $author
  209. [M] The OpenSDE Community <list@opensde.org>
  210. [C] $category
  211. [L] $license
  212. [S] $status
  213. [V] $version
  214. [P] X -----5---9 800.000
  215. EOT
  216. echo "$download" | while read l; do
  217. "$SDEROOT/lib/sde-package/url2d.sh" "$l"
  218. done
  219. ) | tee "$SDEROOT/package/$repo/$pkg/$pkg.desc"