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.

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