tNew script to update git hashes. Leave some work to it in prtmk - scripts - various script and utils
(HTM) git clone git://z3bra.org/scripts
(DIR) Log
(DIR) Files
(DIR) Refs
---
(DIR) commit 170a835303fea397221489ced2ddb663d7a94f87
(DIR) parent 8b9e3243d47c98a0cf7cdc504c4bcb435cd47c85
(HTM) Author: z3bra <willy@mailoo.org>
Date: Thu, 12 Jun 2014 10:05:30 +0200
New script to update git hashes. Leave some work to it in prtmk
Diffstat:
M prtmk | 10 ++++------
A prtup | 70 +++++++++++++++++++++++++++++++
2 files changed, 74 insertions(+), 6 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@@ -16,13 +19,10 @@ echo_color () {
test -n "$1" && name=$1 || read -p 'Name : ' name
read -p 'Description : ' description
read -p 'Version : ' version
-test "$version" = "git" && read -p 'Commit : ' sversion
read -p 'URL : ' url
read -p 'Source : ' sources
read -p 'Depends on : ' depends
-commit=`echo $sversion | cut -b 1-7`
-
PORTDIR=$PORTDIR/$name
if test "$version" = "git"; then
t@@ -64,8 +64,6 @@ sed \
-e "s__DEPENDENCIES__$depends" \
-e "s__NAME__$name" \
-e "s__VERSION__$version" \
- -e "s__COMMIT__$sversion" \
- -e "s__SHORT_COMMIT__$commit" \
-e "s__SOURCE__$sources" \
-e "s__GIT_URL__$git_url" \
-i $PORTDIR/Pkgfile
(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