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.

250 lines
5.5 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 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=${0##*/} 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" )
  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. pkg="$1"; shift
  97. if [ -z "$pkg" ]; then
  98. echo_error "no package name given."
  99. create_usage
  100. exit 1
  101. elif expr "$pkg" : ".*/.*" > /dev/null; then
  102. # repository given
  103. repo="${pkg%/*}"
  104. pkg="${pkg##*/}"
  105. # sanitize $repo if needed
  106. if [ "$repo" = "." ]; then
  107. # detect repo based on $PWD
  108. repo=$( package_autodetect_repo )
  109. elif expr "$repo" : ".*/.*" > /dev/null; then
  110. # longer path
  111. if [ -d "$repo" ]; then
  112. # exists, go there and find out
  113. repo=$( cd "$repo"; package_autodetect_repo )
  114. else
  115. # doesn't exist
  116. repo="$PWD/$repo"
  117. if [ -d "${repo%/*}" ]; then
  118. repo=$( cd "$repo"; package_autodetect_repo )
  119. else
  120. echo_error "${repo#$PWD/}: Invalid repository"
  121. repo=
  122. fi
  123. fi
  124. fi
  125. else
  126. # detect repo based on $PWD
  127. repo=$( package_autodetect_repo )
  128. fi
  129. # base use wip/ if the detection failed
  130. repo="${repo:-wip}"
  131. # validate $pkg
  132. #
  133. confdir=$( package_confdir "$pkg" )
  134. [ -z "$confdir" ] || echo_abort 2 "$pkg: package already exists (${confdir#$SDEROOT/})."
  135. echo_info "Creating package/$repo/$pkg from $hive:${hiveindex:-$pkg}"
  136. # get info form the hive
  137. output=$( "$SDEROOT/lib/sde-package/hives/$hive" "${hiveindex:-$pkg}" "$@" )
  138. [ -n "$output" ] || echo_abort 1 "$hive failed to fetch ${hiveindex:-$pkg} information"
  139. # do we have content for the $1 tag?
  140. output_has_tag()
  141. {
  142. echo "$output" | grep -q "^\[$1\]"
  143. }
  144. # what do we know for the $1 tag?
  145. output_tag()
  146. {
  147. echo "$output" | grep "^\[$1\]" | sed -e 's,^\[[^]]\+\][ \t]*,,' -e 's,[ \t]*\$,,'
  148. }
  149. # checks if output has $1, and return $2 if not
  150. output_parse()
  151. {
  152. if output_has_tag "$1"; then
  153. output_tag "$1"
  154. else
  155. echo "$2"
  156. fi
  157. }
  158. # parse the output of the hive
  159. #
  160. # title
  161. title=$( output_parse I 'TODO: Short Information' )
  162. # desc
  163. desc=$( output_parse T 'TODO: Long Expanation
  164. TODO: Long Expanation
  165. TODO: Long Expanation
  166. TODO: Long Expanation
  167. TODO: Long Expanation' )
  168. # url
  169. url=$( output_parse U 'TODO: URL' )
  170. # author
  171. author=$( output_parse A 'TODO: Author' )
  172. # category
  173. category=$( output_parse C 'TODO: Category' )
  174. # license
  175. license=$( output_parse L 'TODO: License' )
  176. # status
  177. status=$( output_parse S 'TODO: Status' )
  178. # version
  179. version=$( output_parse V 'TODO: Version' )
  180. # download
  181. download=$( output_parse D '' )
  182. # create the confdir
  183. mkdir -p "$SDEROOT/package/$repo/$pkg"
  184. # create $confdir/$pkg.desc
  185. TAG=SDE-COPYRIGHT-NOTE
  186. (
  187. cat <<EOT
  188. [COPY] --- $TAG-BEGIN ---
  189. [COPY] This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  190. [COPY]
  191. [COPY] Filename: package/.../$pkg/$pkg.desc
  192. [COPY] Copyright (C) $( date +%Y ) The OpenSDE Project
  193. [COPY]
  194. [COPY] More information can be found in the files COPYING and README.
  195. [COPY]
  196. [COPY] This program is free software; you can redistribute it and/or modify
  197. [COPY] it under the terms of the GNU General Public License as published by
  198. [COPY] the Free Software Foundation; version 2 of the License. A copy of the
  199. [COPY] GNU General Public License can be found in the file COPYING.
  200. [COPY] --- $TAG-END ---
  201. [I] $title
  202. $( echo "$desc" | sed -e 's,^,[T] ,' )
  203. [U] $url
  204. [A] $author
  205. [M] The OpenSDE Community <list@opensde.org>
  206. [C] $category
  207. [L] $license
  208. [S] $status
  209. [V] $version
  210. [P] X -----5---9 800.000
  211. EOT
  212. echo "$download" | while read l; do
  213. "$SDEROOT/lib/sde-package/url2d.sh" "$l"
  214. done
  215. ) | tee "$SDEROOT/package/$repo/$pkg/$pkg.desc"