This repository has been archived by the owner on Dec 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
update-branch-os.sh
executable file
·84 lines (70 loc) · 2.42 KB
/
update-branch-os.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/sh
# Helper script to checkout OS ports to a specific
# Branch or tag for building
#
# List of ports to update
# Usage: <portname>::<project>::<repo>::<defaultbranch>
PLIST="${PLIST} sysutils/pc-sysinstall::trueos::pc-sysinstall::master"
PLIST="${PLIST} sysutils/pc-installdialog::trueos::pc-installdialog::master"
usage()
{
echo "Updates OS Ports to a requested GitHub branch or tag"
echo ""
echo "Usage: $0 port branch"
echo ""
echo "Example: $0 all"
echo "This will update *all* the ports to their latest versions"
echo ""
echo "Example: $0 sysutils/pc-installdialog 18.12"
echo "This will update the sysutils/pc-installdialog to the version in GitHub tagged 18.12"
exit 1
}
update_port()
{
local port="$(echo $1 | awk -F"::" '{print $1}')"
local project="$(echo $1 | awk -F"::" '{print $2}')"
local repo="$(echo $1 | awk -F"::" '{print $3}')"
local dbranch="$(echo $1 | awk -F"::" '{print $4}')"
# If no branch specified, use default
if [ -n "$BRANCH" ] ; then
dbranch="$BRANCH"
fi
GH_HASH=$(fetch -o - https://api.github.com/repos/$project/$repo/git/refs/heads/$dbranch 2>/dev/null | jq -r '."object"."sha"')
if [ -z "${GH_HASH}" ] ; then
#Not a branch or commit hash. Check to see if it is a version "tag" instead
GH_HASH=$(fetch -o - https://api.github.com/repos/$project/$repo/git/refs/tags/$dbranch 2>/dev/null | jq -r '."object"."sha"')
fi
GH_DATE=$(fetch -o - https://api.github.com/repos/$project/$repo/commits/$GH_HASH 2>/dev/null | jq -r '."commit"."author"."date"')
#echo "$GH_HASH"
#echo "$GH_DATE"
YEAR="$(echo $GH_DATE | cut -d '-' -f 1)"
MON="$(echo $GH_DATE | cut -d '-' -f 2)"
DAY="$(echo $GH_DATE | cut -d '-' -f 3 | cut -d 'T' -f 1)"
HOUR="$(echo $GH_DATE | cut -d 'T' -f 2 | cut -d ':' -f 1)"
MIN="$(echo $GH_DATE | cut -d 'T' -f 2 | cut -d ':' -f 2)"
SEC="$(echo $GH_DATE | cut -d 'T' -f 2 | cut -d ':' -f 3 | cut -d 'Z' -f 1)"
TSTAMP="$YEAR$MON$DAY$HOUR$MIN$SEC"
#echo "$TSTAMP"
sed -i '' "s/.*PORTVERSION=.*/PORTVERSION= $TSTAMP/" ${port}/Makefile
sed -i '' "s/.*GH_TAGNAME=.*/GH_TAGNAME= $GH_HASH/" ${port}/Makefile
make -C ${port} OSVERSION=1200000 makesum
}
if [ -z "$1" ] ; then
usage
fi
BRANCH="$2"
# Set the ports dir location
export PORTSDIR="$(pwd)"
if [ "$1" = "all" ] ; then
for p in $PLIST
do
update_port $p
done
else
port=$(echo $PLIST | tr ' ' '\n' | grep "^${1}::")
if [ -z "$port" ] ; then
echo "ERROR: Invalid port $1 specified"
exit 1
fi
update_port ${port}
fi