tprtup - scripts - various script and utils
HTML git clone git://z3bra.org/scripts
DIR Log
DIR Files
DIR Refs
---
tprtup (1506B)
---
1 #!/bin/bash
2 #
3 # z3bra - (c) wtfpl 2014
4 # Update git hashes in a Pkgfile
5
6 PKGMK_ARCH=64 . /etc/pkgmk.conf
7
8 echo_color() {
9 tput bold
10 tput setaf $1
11 shift
12
13 echo "$@"
14
15 tput sgr0
16 }
17
18 # check wether we're in a port directory or not
19 if [ ! -f Pkgfile ]; then
20 echo_color 1 "Not in a port directory"
21 exit 1
22 fi
23
24 port_dir=$PWD
25
26 get_version() {
27 cd $PKGMK_SOURCE_DIR
28
29 # enter the git directory
30 if cd $name 2>/dev/null; then
31 git reset --hard
32 git pull origin master
33
34 elif test -n "$gitsource"; then
35 git clone $gitsource $name
36 cd $name
37
38 else
39 echo_color 1 "not a git-based port"
40 exit 1
41 fi
42
43 # get the git hash and its minimized version
44 version=$(git log --oneline --format="git-%h" | sed 1q)
45 sversion=$(git log --oneline --format="%H" | sed 1q)
46 }
47
48 update_pkgfile() {
49 cd $port_dir
50
51 # update version
52 sed -i "s/^version=.*$/version=$version/" Pkgfile
53
54 # update sversion if it exists
55 if grep -q 'sversion' Pkgfile; then
56 sed -i "s/^sversion=.*$/sversion=$sversion/" Pkgfile
57
58 # create it otherwise
59 else
60 sed -i "/^version=/a\
61 sversion=$sversion" Pkgfile
62 fi
63 }
64
65 main() {
66
67 # we'll need the $name var later
68 . ./Pkgfile
69
70 # get the git hashes
71 get_version
72
73 # update Pkgfile accordingly
74 update_pkgfile
75
76 if [ ! "$1" = "-q" ]; then
77 echo "port : $name"
78 echo "version: $version"
79 echo "commit : $sversion"
80 fi
81 }
82
83 main $@