aboutsummaryrefslogtreecommitdiffstats
path: root/freebsd.ports.sh
diff options
context:
space:
mode:
authorTing-Wei Lan <lantw44@gmail.com>2014-02-05 21:08:08 +0800
committerTing-Wei Lan <lantw44@gmail.com>2014-02-05 21:09:03 +0800
commitca3e25d5a7477b4963749e9919466d1719a0fa9b (patch)
tree52ddcb0295d442eb2adaf4f9cddb133c5e5ade6d /freebsd.ports.sh
parent8f1448124c4e80dd80bd05dd5d937c884431db28 (diff)
downloadwspkg-ca3e25d5a7477b4963749e9919466d1719a0fa9b.tar
wspkg-ca3e25d5a7477b4963749e9919466d1719a0fa9b.tar.gz
wspkg-ca3e25d5a7477b4963749e9919466d1719a0fa9b.tar.bz2
wspkg-ca3e25d5a7477b4963749e9919466d1719a0fa9b.tar.lz
wspkg-ca3e25d5a7477b4963749e9919466d1719a0fa9b.tar.xz
wspkg-ca3e25d5a7477b4963749e9919466d1719a0fa9b.tar.zst
wspkg-ca3e25d5a7477b4963749e9919466d1719a0fa9b.zip
完成自動產生 FreeBSD packages 至 ports 目錄對應表的 script (同時修正 bug)
Diffstat (limited to 'freebsd.ports.sh')
-rwxr-xr-xfreebsd.ports.sh52
1 files changed, 52 insertions, 0 deletions
diff --git a/freebsd.ports.sh b/freebsd.ports.sh
new file mode 100755
index 0000000..e748bdf
--- /dev/null
+++ b/freebsd.ports.sh
@@ -0,0 +1,52 @@
+#!/bin/sh
+
+msg () {
+ echo "$@" 1>&2
+}
+
+get_origin () {
+ grep "^$1" "${index}" | (
+ IFS="${IFS}|"
+ while read pkgnamever fullpath trash; do
+ pkgname="${pkgnamever%-*}"
+ if [ "${pkgname}" = "$1" ]; then
+ this_origin="${fullpath#${PORTSDIR}}"
+ this_origin="${this_origin#/}"
+ echo "${this_origin}"
+ break
+ fi
+ done
+ )
+}
+
+[ -z "$1" ] && msg "Usage: $0 list_file" && exit 1
+: ${FREEBSD_VERSION:="`uname -r | sed 's|^\([0-9]*\).*$|\1|'`"}
+: ${PORTSDIR:="/usr/ports"}
+index="${PORTSDIR}/INDEX-${FREEBSD_VERSION}"
+
+msg "==> FreeBSD version is ${FREEBSD_VERSION}"
+msg "==> FreeBSD ports tree is ${PORTSDIR}"
+msg "==> FreeBSD ports index file is ${index}"
+
+exec 3< "$1" # list file
+
+echo "// vim: ft=c: et"
+echo ""
+echo "// ====================================================================="
+echo "// This file maps FreeBSD packages to their ports directories"
+echo "// ====================================================================="
+echo ""
+
+while read pkgname 0<&3; do
+ msg "=> Processing package ${pkgname}"
+ origin="`get_origin ${pkgname}`"
+ [ -z "${origin}" ] && \
+ msg "==> Cannot find origin for ${pkgname} in your index file" && \
+ msg "==> Exit now!" && exit 1
+ msg "=> Processing package ${pkgname} - ${origin}"
+ printf "#define %-32s %s\n" "${pkgname}" "${origin}"
+done
+
+exec 3<&-
+
+msg "==> Done!"