From 5c7d3944cda03a29ae6349ec4bd058e405c3b8f4 Mon Sep 17 00:00:00 2001 From: rhatto Date: Tue, 23 Dec 2008 21:24:11 +0000 Subject: mkbuild: adding --update-manifest and other changes (see CHANGELOG) git-svn-id: svn+slack://slack.fluxo.info/var/svn/simplepkg@707 04377dda-e619-0410-9926-eae83683ac58 --- trunk/src/mkbuild | 187 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 162 insertions(+), 25 deletions(-) (limited to 'trunk/src/mkbuild') diff --git a/trunk/src/mkbuild b/trunk/src/mkbuild index 84120ff..f7566f5 100755 --- a/trunk/src/mkbuild +++ b/trunk/src/mkbuild @@ -164,6 +164,12 @@ function set_parameters { ACTION="commit_all" shift ;; + '-um'|'--update-manifest') + ACTION="update_manifest" + MKBUILD_NAME="${2//.mkbuild}.mkbuild" + SOURCE_FILE="$3" + shift 2 + ;; '-n'|'--new') # New mkbuild configure file MKBUILD_NAME="${2//.mkbuild}.mkbuild" @@ -729,6 +735,7 @@ function file_metainfo { local sum="" file="$1" file_type="`echo $2 | tr '[:lower:]' '[:upper:]'`" local size algo candidate folders path manifest_file="$3" + local dist_name="`basename $file`" if [ -d "$file" ]; then return @@ -741,30 +748,28 @@ function file_metainfo { if [ ! -e "$file" ]; then if [ "$file_type" == "DIST" ]; then - folders="$WORK $TMP $SOURCE_DIR" - if ! is_the_same /tmp $TMP; then - folders="$folders /tmp" + # Add DIST information only if source is not under revision control + if [ $SVN_MOD -eq $on -o $GIT_MOD -eq $on ]; then + return fi - echo "Trying to find $(basename $file)) at $folders..." + # Force DIST file name at Manifest + dist_name="$DIST_SRC_NAME" - for path in $folders; do - candidate="$(find $path -name $(basename $file))" - if [ ! -z "$candidate" ]; then - break - fi - done + # Determine file location + get_dist_file - if [ ! -z "$candidate" ]; then - echo "Using $(basename $file) found at $(dirname $candidate) to hash at the Manifest." - file="$candidate" + # Update Manifest metadata + if [ -e "$DIST_SRC_LOCATION" ]; then + file="$DIST_SRC_LOCATION" + echo "Using $(basename $file) found at $(dirname $file) to hash at the Manifest." else - echo "$file_type `basename $file` " >> $manifest_file # end space is important + echo "$file_type $dist_name " >> $manifest_file # end space is important return 1 fi else - echo "$file_type `basename $file` " >> $manifest_file # end space is important + echo "$file_type $dist_name " >> $manifest_file # end space is important return 1 fi fi @@ -773,7 +778,7 @@ function file_metainfo { sum="$sum `echo $algo | tr '[:lower:]' '[:upper:]'` `gethash $algo $file`" done - echo $file_type `basename $file` `file_size $file` $sum >> $manifest_file + echo $file_type $dist_name `file_size $file` $sum >> $manifest_file } @@ -789,7 +794,7 @@ function update_manifest_info { fi # Update Manifest file - if [ ! -e "`dirname $file`/Manifest" ]; then + if [ ! -e "$WORK/Manifest" ]; then touch $WORK/Manifest fi @@ -797,7 +802,7 @@ function update_manifest_info { tmpfile="`mktemp $TMP/mkbuild_manifest.XXXXXX`" # Update metadata - sed -e "/^$file_type `basename $file` /d" `dirname $file`/Manifest > $tmpfile + sed -e "/^$file_type `basename $file` /d" $WORK/Manifest > $tmpfile file_metainfo $file $file_type $tmpfile if [ "$?" != "0" ]; then @@ -806,13 +811,13 @@ function update_manifest_info { fi # Save Manifest changes - sort $tmpfile > `dirname $file`/Manifest + sort $tmpfile > $WORK/Manifest rm -f $tmpfile } -function update_manifest { +function edit_manifest { # Update Manifest file verbose "Updating Manifest..." @@ -849,6 +854,127 @@ function update_manifest { } +function get_dist_file { + + # get package source code + # usage: get_dist_file [file] + + local folders path candidate file="$1" + local protocol="`echo $URL | cut -d : -f 1 | tr '[:upper:]' '[:lower:]'`" + + # Determine file location + if [ -d "$file" ]; then + + file="$DIST_SRC_NAME" + for candidate in $(find $SOURCE_FILE -name $(basename $file)); do + if [ ! -z "$candidate" ]; then + break 2 + fi + done + + if [ ! -z "$candidate" ]; then + echo "Using $(basename $candidate) found at $(dirname $candidate) to hash at the Manifest." + file="$candidate" + else + echo "Can't find $file at $DIST_SRC_NAME." + return 1 + fi + + elif [ -z "$file" ]; then + + file="$DIST_SRC_NAME" + folders="$WORK $TMP $SOURCE_DIR" + if ! is_the_same /tmp $TMP; then + folders="$folders /tmp" + fi + + echo "Trying to find $(basename $file) at $folders..." + + for path in $folders; do + for candidate in $(find $path -name $(basename $file)); do + if [ ! -z "$candidate" ]; then + break 2 + fi + done + done + + if [ ! -z "$candidate" ]; then + + echo "Using $(basename $candidate) found at $(dirname $candidate) to hash at the Manifest." + file="$candidate" + + elif [ "$protocol" == "https" ] || \ + [ "$protocol" == "http" ] || \ + [ "$protocol" == "ftp" ]; then + + # TODO: config file parameter should control whether to donwload + # Try to donwload the file + if [ ! -e "$file" ]; then + if is_writable_folder $SOURCE_DIR/$PKG_NAME; then + file="$SOURCE_DIR/$PKG_NAME/`basename $DIST_SRC_NAME`" + wget "$URL" -O "$file" + if [ "$?" != "0" ]; then + echo "Could not download $file" + return 1 + fi + elif is_writable_folder $TMP; then + file="$TMP/`basename $DIST_SRC_NAME`" + if [ ! -e "$file" ]; then + wget "$URL" -O "$file" + if [ "$?" != "0" ]; then + echo "Could not download $file" + return 1 + fi + fi + elif ! is_the_same /tmp $TMP; then + file="/tmp/`basename $DIST_SRC_NAME`" + if [ ! -e "$file" ]; then + wget "$URL" -O "$file" + if [ "$?" != "0" ]; then + echo "Could not download $file" + return 1 + fi + fi + else + echo "Could not download $file" + return 1 + fi + fi + fi + fi + + DIST_SRC_LOCATION="$file" + +} + +function update_manifest { + + # Get mkbuild values + get_mkbuild_values + + # Add DIST information only if source is not under revision control + if [ $SVN_MOD -eq $on -o $GIT_MOD -eq $on ]; then + echo "Source is under version control system, can't add hashes to Manifest." + return + fi + + echo "Updating DIST information at $MKBUILD_NAME Manifest..." + + # Determine file location + get_dist_file + + # Update Manifest metadata + if [ -e "$DIST_SRC_LOCATION" ]; then + update_manifest_info $DIST_SRC_LOCATION dist + # TODO: that should appear also when adding DIST information at edit_manifest + echo "Please make sure that the following hashes are correct:" + grep -e "^DIST $DIST_SRC_NAME " $WORK/Manifest + else + echo "Can't get $DIST_SRC_NAME." + fi + +} + function if_previous_error { if [ "$?" != "0" ]; then @@ -859,13 +985,13 @@ function if_previous_error { function verbose { - if [ $VERBOSE -eq $on ]; then - echo $* - fi + if [ $VERBOSE -eq $on ]; then + echo $* + fi } -function make_slackbuild { +function get_mkbuild_values { # Get values # Author name @@ -1016,9 +1142,17 @@ function make_slackbuild { SLACKBUILD_PATH=`get_slackbuild_path` verbose "[[SLACKBUILD PATH]]=\"$SLACKBUILD_PATH\"" +} + +function make_slackbuild { + #-------------------------------------------------------------- #- Start build SlackBuild - #-------------------------------------------------------------- + + # Get mkbuild values + get_mkbuild_values + verbose -e "\nStart SlackBuild make" SLACKBUILD_TEMP=$SLACKBUILD.tmp cp $MODEL_DIR/$MODEL $SLACKBUILD_TEMP @@ -1059,7 +1193,7 @@ function make_slackbuild { change_other_parameters # Update Manifest file - update_manifest + edit_manifest # Commit SlackBuild [ $SUBMIT_SLACKBUILD -eq $on ] && submit_slackbuild @@ -1151,6 +1285,9 @@ set_parameters "$@" verbose -e "$BASENAME version $PROG_VERSION\n" if [ ! -z $MKBUILD_NAME ]; then case $ACTION in + 'update_manifest') + update_manifest $* + ;; 'commit_slackbuild') commit_changes $SLACKBUILDS_DIR $* ;; -- cgit v1.2.3