1#!/bin/sh
2# Helper script which will create the port / distfiles
3# from a checked out git repo
4
5# Set the port
6dfile="lumina"
7VERSION="1.5.0"
8
9massage_subdir() {
10  cd "$1"
11  if [ $? -ne 0 ] ; then
12     echo "SKIPPING $i"
13     continue
14  fi
15
16comment="`cat Makefile | grep 'COMMENT ='`"
17
18  echo "# \$FreeBSD\$
19#
20
21$comment
22" > Makefile.tmp
23
24  for d in `ls`
25  do
26    if [ "$d" = ".." ]; then continue ; fi
27    if [ "$d" = "." ]; then continue ; fi
28    if [ "$d" = "Makefile" ]; then continue ; fi
29    if [ ! -f "$d/Makefile" ]; then continue ; fi
30    echo "    SUBDIR += $d" >> Makefile.tmp
31  done
32  echo "" >> Makefile.tmp
33  echo ".include <bsd.port.subdir.mk>" >> Makefile.tmp
34  mv Makefile.tmp Makefile
35
36}
37
38if [ -z "$1" ] ; then
39   echo "Usage: ./mkports.sh <portstree> <distfiles>"
40   exit 1
41fi
42
43if [ ! -d "${1}/Mk" ] ; then
44   echo "Invalid directory: $1"
45   exit 1
46fi
47
48portsdir="${1}"
49if [ -z "$portsdir" -o "${portsdir}" = "/" ] ; then
50  portsdir="/usr/ports"
51fi
52
53if [ -z "$2" ] ; then
54  distdir="${portsdir}/distfiles"
55else
56  distdir="${2}"
57fi
58if [ ! -d "$distdir" ] ; then
59  mkdir -p ${distdir}
60fi
61
62# Get the GIT tag
63ghtag=`git log -n 1 . | grep '^commit ' | awk '{print $2}'`
64
65# Get the version
66verTag="${VERSION}"
67dateTag=$(date '+%Y%m%d%H%M')
68
69# Cleanup old distfiles
70rm ${distdir}/${dfile}-* 2>/dev/null
71
72# Copy ports files
73orig_dir=`pwd`
74allports=""
75for port in `find port-files/FreeBSD | grep Makefile | cut -d / -f 3-4`
76do
77  cd ${orig_dir}
78  echo "Updating port: ${port}"
79  allports="${allports} ${port}" #add this port to the list
80  if [ -d "${portsdir}/${port}" ] ; then
81    rm -rf ${portsdir}/${port} 2>/dev/null
82  fi
83  cp -r port-files/FreeBSD/${port} ${portsdir}/${port}
84
85  # Set the version numbers
86  sed -i '' "s|%%CHGVERSION%%|${verTag}|g" ${portsdir}/${port}/Makefile
87  sed -i '' "s|%%CHGREVISION%%|${dateTag}|g" ${portsdir}/${port}/Makefile
88  sed -i '' "s|%%GHTAG%%|${ghtag}|g" ${portsdir}/${port}/Makefile
89
90  # Create the makesums / distinfo file
91  cd "${portsdir}/${port}"
92  make makesum
93  if [ $? -ne 0 ] ; then
94    echo "Failed makesum"
95    exit 1
96  fi
97
98  # Update port cat Makefile
99  tcat=$(echo $port | cut -d '/' -f 1)
100  massage_subdir ${portsdir}/${tcat}
101done
102echo "All ports updated: ${allports}"
103#Set a couple variables for the TrueOS build cluster to know which is the "overall" port
104bPort="${allports}" #reset this variable in case something else needs it
105port="x11/lumina-core x11/lumina-coreutils deskutils/lumina-archiver deskutils/lumina-mediaplayer deskutils/lumina-fm deskutils/lumina-textedit deskutils/lumina-screenshot deskutils/lumina-fileinfo x11/lumina"
106export bPort
107