#!/bin/sh
|
|
# --- SDE-COPYRIGHT-NOTE-BEGIN ---
|
|
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
|
|
#
|
|
# Filename: bin/sde-create-package
|
|
# Copyright (C) 2008 - 2009 The OpenSDE Project
|
|
#
|
|
# More information can be found in the files COPYING and README.
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; version 2 of the License. A copy of the
|
|
# GNU General Public License can be found in the file COPYING.
|
|
# --- SDE-COPYRIGHT-NOTE-END ---
|
|
|
|
#Description: Creates a new package
|
|
#Alias: pkg
|
|
|
|
[ -n "$SDEROOT" ] ||
|
|
export SDEROOT=$( cd "${0%/*}/.."; pwd -P )
|
|
|
|
. "$SDEROOT/lib/libsde.in"
|
|
. "$SDEROOT/lib/sde-package.in"
|
|
. "$SDEROOT/lib/sde-package/hives.in"
|
|
|
|
create_usage() {
|
|
local progname="$(echo "$0" | sed -e 's,.*/,,' -e 's,-, ,g')" hive=
|
|
cat <<EOT
|
|
Usage: $progname [--hive <hive>[:<index>]] [<repository>/][<package>] [hive arguments]
|
|
|
|
Available Hives (--hivelist):
|
|
EOT
|
|
for hive in $( package_hives_list ); do
|
|
desc=$( package_hive_desc "$hive" )
|
|
aliases=$(package_hive_aliases "$hive" | tr ' ' ',')
|
|
if [ "$hive" = 'download' ]; then
|
|
default=yes
|
|
else
|
|
default=
|
|
fi
|
|
|
|
printf "%15s %s%s\n" "$hive" "${desc:-...}" "${aliases:+ (Alias: $aliases)}${default:+ (default)}"
|
|
done
|
|
}
|
|
|
|
shortopts=
|
|
longopts='help,hive:,hivelist'
|
|
options=$( getopt -o "$shortopts" -l "$longopts" -- "$@" )
|
|
if [ $? -ne 0 ]; then
|
|
create_usage
|
|
exit -1
|
|
fi
|
|
|
|
# load new arguments list
|
|
eval set -- "$options"
|
|
|
|
hive=
|
|
hiveindex=
|
|
hivelist=
|
|
|
|
while [ $# -gt 0 ]; do
|
|
case "$1" in
|
|
--help)
|
|
create_usage
|
|
exit 0 ;;
|
|
|
|
--hive)
|
|
hive=$2; shift
|
|
;;
|
|
--hivelist)
|
|
hivelist=yes
|
|
;;
|
|
|
|
--) shift; break ;;
|
|
*) echo_abort 1 "$1: Unknown argument, aborting."
|
|
esac
|
|
shift
|
|
done
|
|
|
|
# just list know hives
|
|
#
|
|
if [ -n "$hivelist" ]; then
|
|
for x in $( package_hives_list ); do
|
|
echo $x
|
|
done
|
|
exit 0
|
|
fi
|
|
|
|
# validate the choosen hive
|
|
#
|
|
if [ -n "$hive" ]; then
|
|
# split hive and hiveindex
|
|
if expr "$hive" : ".*:.*" > /dev/null; then
|
|
hiveindex="${hive#*:}"
|
|
hive="${hive%%:*}"
|
|
fi
|
|
|
|
# translate into the real name of the hive, in the case the alias was gives
|
|
x=$( package_hive_alias "$hive" )
|
|
if [ -z "$x" ]; then
|
|
echo_abort 1 "$hive: Invalid hive."
|
|
else
|
|
hive="$x"
|
|
fi
|
|
else
|
|
# assume download hive of none is given
|
|
hive='download'
|
|
fi
|
|
|
|
# $repo/$pkg
|
|
#
|
|
if [ $# -gt 0 ]; then
|
|
pkg="$1"; shift
|
|
else
|
|
pkg=
|
|
fi
|
|
|
|
if [ -z "$pkg" ]; then
|
|
echo_error "no package name given."
|
|
create_usage
|
|
exit 1
|
|
elif expr "$pkg" : ".*/.*" > /dev/null; then
|
|
# repository given
|
|
repo="${pkg%/*}"
|
|
pkg="${pkg##*/}"
|
|
|
|
# sanitize $repo if needed
|
|
if [ "$repo" = "." ]; then
|
|
# detect repo based on $PWD
|
|
repo=$( package_autodetect_repo )
|
|
elif expr "$repo" : ".*/.*" > /dev/null; then
|
|
# longer path
|
|
if [ -d "$repo" ]; then
|
|
# exists, go there and find out
|
|
repo=$( cd "$repo"; package_autodetect_repo )
|
|
else
|
|
# doesn't exist
|
|
repo="$PWD/$repo"
|
|
if [ -d "${repo%/*}" ]; then
|
|
repo=$( cd "$repo"; package_autodetect_repo )
|
|
else
|
|
echo_error "${repo#$PWD/}: Invalid repository"
|
|
repo=
|
|
fi
|
|
fi
|
|
fi
|
|
else
|
|
# detect repo based on $PWD
|
|
repo=$( package_autodetect_repo )
|
|
fi
|
|
# base use wip/ if the detection failed
|
|
repo="${repo:-wip}"
|
|
|
|
# validate $pkg
|
|
#
|
|
confdir=$( package_confdir "$pkg" )
|
|
[ -z "$confdir" ] || echo_abort 2 "$pkg: package already exists (${confdir#$SDEROOT/})."
|
|
|
|
echo_info "Creating package/$repo/$pkg from $hive:${hiveindex:-$pkg}"
|
|
|
|
# get info form the hive
|
|
output=$( "$SDEROOT/lib/sde-package/hives/$hive" "${hiveindex:-$pkg}" "$@" )
|
|
[ -n "$output" ] || echo_abort 1 "$hive failed to fetch ${hiveindex:-$pkg} information"
|
|
|
|
# do we have content for the $1 tag?
|
|
output_has_tag()
|
|
{
|
|
echo "$output" | grep -q "^\[$1\]"
|
|
}
|
|
|
|
# what do we know for the $1 tag?
|
|
output_tag()
|
|
{
|
|
echo "$output" | grep "^\[$1\]" | sed -e 's,^\[[^]]\+\][ \t]*,,' -e 's,[ \t]*\$,,'
|
|
}
|
|
|
|
# checks if output has $1, and return $2 if not
|
|
output_parse()
|
|
{
|
|
if output_has_tag "$1"; then
|
|
output_tag "$1"
|
|
else
|
|
echo "$2"
|
|
fi
|
|
}
|
|
|
|
# parse the output of the hive
|
|
#
|
|
|
|
# title
|
|
title=$( output_parse I 'TODO: Short Information' )
|
|
# desc
|
|
desc=$( output_parse T 'TODO: Long Expanation
|
|
TODO: Long Expanation
|
|
TODO: Long Expanation
|
|
TODO: Long Expanation
|
|
TODO: Long Expanation' )
|
|
# url
|
|
url=$( output_parse U 'TODO: URL' )
|
|
# author
|
|
author=$( output_parse A 'TODO: Author' )
|
|
# category
|
|
category=$( output_parse C 'TODO: Category' )
|
|
# license
|
|
license=$( output_parse L 'TODO: License' )
|
|
# status
|
|
status=$( output_parse S 'TODO: Status' )
|
|
# version
|
|
version=$( output_parse V 'TODO: Version' )
|
|
# download
|
|
download=$( output_parse D '' )
|
|
|
|
# create the confdir
|
|
mkdir -p "$SDEROOT/package/$repo/$pkg"
|
|
|
|
# create $confdir/$pkg.desc
|
|
TAG=SDE-COPYRIGHT-NOTE
|
|
(
|
|
cat <<EOT
|
|
[COPY] --- $TAG-BEGIN ---
|
|
[COPY] This copyright note is auto-generated by ./scripts/Create-CopyPatch.
|
|
[COPY]
|
|
[COPY] Filename: package/.../$pkg/$pkg.desc
|
|
[COPY] Copyright (C) $( date +%Y ) The OpenSDE Project
|
|
[COPY]
|
|
[COPY] More information can be found in the files COPYING and README.
|
|
[COPY]
|
|
[COPY] This program is free software; you can redistribute it and/or modify
|
|
[COPY] it under the terms of the GNU General Public License as published by
|
|
[COPY] the Free Software Foundation; version 2 of the License. A copy of the
|
|
[COPY] GNU General Public License can be found in the file COPYING.
|
|
[COPY] --- $TAG-END ---
|
|
|
|
[I] $title
|
|
|
|
$( echo "$desc" | sed -e 's,^,[T] ,' )
|
|
|
|
[U] $url
|
|
|
|
[A] $author
|
|
[M] The OpenSDE Community <list@opensde.org>
|
|
|
|
[C] $category
|
|
|
|
[L] $license
|
|
[S] $status
|
|
[V] $version
|
|
[P] X -----5---9 800.000
|
|
|
|
EOT
|
|
echo "$download" | while read l; do
|
|
"$SDEROOT/lib/sde-package/url2d.sh" "$l"
|
|
done
|
|
) | tee "$SDEROOT/package/$repo/$pkg/$pkg.desc"
|
|
|