aboutsummaryrefslogtreecommitdiff
path: root/Keywords
diff options
context:
space:
mode:
authorBaptiste Daroussin <bapt@FreeBSD.org>2020-10-22 06:39:16 +0000
committerBaptiste Daroussin <bapt@FreeBSD.org>2020-10-22 06:39:16 +0000
commitd3e58fed8517d63bf0b925ea1cdec968cdd4517a (patch)
tree4586d045ae6de4109e4a9379a7b1e5f9a3cc9be6 /Keywords
parent090db4bd9225e9b07fee856a41ca566e3820a013 (diff)
downloadports-d3e58fed8517d63bf0b925ea1cdec968cdd4517a.tar.gz
ports-d3e58fed8517d63bf0b925ea1cdec968cdd4517a.zip
Convert @shell from shell script to lua script
This makes @shell rootdir friendly and cross install friendly as well as capsicumized. Bonus: the /etc/shells is now only touched when needed Reviewed by: manu, mat Approved by: portmgr (mat) Differential Revision: D26640
Notes
Notes: svn path=/head/; revision=552938
Diffstat (limited to 'Keywords')
-rw-r--r--Keywords/shell.ucl51
1 files changed, 35 insertions, 16 deletions
diff --git a/Keywords/shell.ucl b/Keywords/shell.ucl
index 269640f1d14d..27d0b460aeb3 100644
--- a/Keywords/shell.ucl
+++ b/Keywords/shell.ucl
@@ -8,21 +8,40 @@
#
actions: [file]
-post-install: <<EOD
- case "%@" in
- /*) file="%@" ;;
- *) file="%D/%@" ;;
- esac
- cp ${PKG_ROOTDIR}/etc/shells ${PKG_ROOTDIR}/etc/shells.bak
- (grep -v "^${file}$" ${PKG_ROOTDIR}/etc/shells.bak; echo ${file}) > ${PKG_ROOTDIR}/etc/shells
- rm -f ${PKG_ROOTDIR}/etc/shells.bak
+post-install-lua: <<EOD
+ shell_path = pkg.prefixed_path("%@")
+ shell = io.open("/etc/shells", "r+")
+ while true do
+ line = shell:read()
+ if line == nil then break end
+ if line == shell_path then
+ -- the shell path is already in the shell file
+ shell:close()
+ return
+ end
+ end
+ shell:write(shell_path .. "\n")
+ shell:close()
EOD
-pre-deinstall: <<EOD
- case "%@" in
- /*) file="%@" ;;
- *) file="%D/%@" ;;
- esac
- cp ${PKG_ROOTDIR}/etc/shells ${PKG_ROOTDIR}/etc/shells.bak
- grep -v "^${file}$" ${PKG_ROOTDIR}/etc/shells.bak > ${PKG_ROOTDIR}/etc/shells
- rm -f ${PKG_ROOTDIR}/etc/shells.bak
+pre-deinstall-lua: <<EOD
+ shell_path = pkg.prefixed_path("%@")
+ shellsbuf = ""
+ shells_path = "/etc/shells"
+ shell = io.open(shells_path, "r+")
+ found = false
+ while true do
+ line = shell:read()
+ if line == nil then break end
+ if line == shell_path then
+ found = true
+ else
+ shellsbuf = shellsbuf .. line .. "\n"
+ end
+ end
+ shell:close()
+ if found then
+ shell = io.open(shells_path, "w+")
+ shell:write(shellsbuf)
+ shell:close()
+ end
EOD