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