tMerge branch 'master' of z3bra.org:scripts - scripts - various script and utils
 (HTM) git clone git://z3bra.org/scripts
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
 (DIR) commit 06ff094435e432b33190d4f687f80a39f0744a26
 (DIR) parent 61e9c18d8595efd7b99b503d1100f048a233f429
 (HTM) Author: z3bra <willy@mailoo.org>
       Date:   Fri, 27 Jun 2014 14:21:30 +0200
       
       Merge branch 'master' of z3bra.org:scripts
       
       Diffstat:
         M prtmk                               |      11 +++++++----
         A prtup                               |      70 +++++++++++++++++++++++++++++++
       
       2 files changed, 77 insertions(+), 4 deletions(-)
       ---
 (DIR) diff --git a/prtmk b/prtmk
       t@@ -1,8 +1,11 @@
        #!/bin/sh
       +#
       +# z3bra - (c) wtfpl 2014
       +# Create a Pkgfile from simple templates and user input
        
        PKGFILE=~/src/ports/Pkgfile
        PORTDIR=~/usr/ports
       -test -z $EDITOR && EDITOR=vim
       +EDITOR=${EDITOR:vim}
        
        echo_color () {
            tput bold
       t@@ -20,9 +23,6 @@ read -p 'URL : ' url
        read -p 'Source : ' sources
        read -p 'Depends on : ' depends
        
       -source=${source//$name/\$name}
       -source=${source/$version/\$version}
       -
        PORTDIR=$PORTDIR/$name
        
        if test "$version" = "git"; then
       t@@ -31,6 +31,9 @@ if test "$version" = "git"; then
        
            PKGFILE=${PKGFILE}-git
            PORTDIR=${PORTDIR}-git
       +else
       +    sources=${sources//$name/\$name}
       +    sources=${sources/$version/\$version}
        fi
        
        echo -n "creating port $name .. "
 (DIR) diff --git a/prtup b/prtup
       t@@ -0,0 +1,70 @@
       +#!/bin/sh
       +#
       +# z3bra - (c) wtfpl 2014
       +# Update git hashes in a Pkgfile
       +
       +PKGMK_ARCH=64 source /etc/pkgmk.conf
       +
       +echo_color () {
       +    tput bold
       +    tput setaf $1
       +    shift
       +
       +    echo "$@"
       +
       +    tput sgr0
       +}
       +
       +# check wether we're in a port directory or not
       +if [ ! -f Pkgfile ]; then
       +    echo_color 1 "Not in a port directory"
       +    exit 1
       +fi
       +
       +port_dir=$PWD
       +
       +get_version() {
       +    cd $PKGMK_SOURCE_DIR
       +
       +    # enter the git directory
       +    if cd $name; then
       +
       +        # get the git hash and its minimized version
       +        version=$(git log --oneline --format="git-%h" | sed 1q)
       +        sversion=$(git log --oneline --format="%H" | sed 1q)
       +    else
       +        echo_color 1 'Cannot check git sources'
       +        exit 1
       +    fi
       +}
       +
       +update_pkgfile() {
       +    cd $port_dir
       +
       +    # update version
       +    sed -i "s/^version=.*$/version=$version/" Pkgfile
       +
       +    # update sversion if it exists
       +    if grep 'sversion' Pkgfile; then
       +        sed -i "s/^sversion=.*$/sversion=$sversion/" Pkgfile
       +
       +    # create it otherwise
       +    else
       +        sed -i "/version/a\
       +        sversion=$sversion" Pkgfile
       +    fi
       +}
       +
       +main() {
       +
       +    # we'll need the $name var later
       +    source Pkgfile
       +
       +    # get the git hashes
       +    get_version
       +
       +    # update Pkgfile accordingly
       +    update_pkgfile
       +}
       +
       +main