Changeset View
Standalone View
Keywords/shell.ucl
# $FreeBSD$ | # $FreeBSD$ | ||||
# | # | ||||
# MAINTAINER: portmgr@FreeBSD.org | # MAINTAINER: portmgr@FreeBSD.org | ||||
# | # | ||||
# @shell bin/shell | # @shell bin/shell | ||||
# | # | ||||
# Handle adding and remove a path to a shell binary into /etc/shells | # Handle adding and remove a path to a shell binary into /etc/shells | ||||
# | # | ||||
actions: [file] | actions: [file] | ||||
post-install: <<EOD | post-install-lua: <<EOD | ||||
case "%@" in | shell_path = pkg.prefixed_path("%@") | ||||
/*) file="%@" ;; | shell = io.open("/etc/shells", "r+") | ||||
*) file="%D/%@" ;; | while true do | ||||
esac | line = shell:read() | ||||
cp ${PKG_ROOTDIR}/etc/shells ${PKG_ROOTDIR}/etc/shells.bak | if line == nil then break end | ||||
(grep -v "^${file}$" ${PKG_ROOTDIR}/etc/shells.bak; echo ${file}) > ${PKG_ROOTDIR}/etc/shells | if line == shell_path then | ||||
rm -f ${PKG_ROOTDIR}/etc/shells.bak | -- the shell path is already in the shell file | ||||
shell:close() | |||||
return | |||||
end | |||||
end | |||||
shell:write(shell_path .. "\n") | |||||
shell:close() | |||||
EOD | EOD | ||||
pre-deinstall: <<EOD | pre-deinstall-lua: <<EOD | ||||
case "%@" in | shell_path = pkg.prefixed_path("%@") | ||||
/*) file="%@" ;; | shellsbuf = "" | ||||
*) file="%D/%@" ;; | shells_path = "/etc/shells" | ||||
esac | shell = io.open(shells_path, "r+") | ||||
cp ${PKG_ROOTDIR}/etc/shells ${PKG_ROOTDIR}/etc/shells.bak | found = false | ||||
grep -v "^${file}$" ${PKG_ROOTDIR}/etc/shells.bak > ${PKG_ROOTDIR}/etc/shells | while true do | ||||
rm -f ${PKG_ROOTDIR}/etc/shells.bak | line = shell:read() | ||||
if line == nil then break end | |||||
if line == shell_path then | |||||
mat: Why `==` in the post-install and `~=` here? | |||||
Done Inline ActionsThis one is rewriting all the lines that arent' the shell_path, the other one is bailing out as soon as we find shell_path kevans: This one is rewriting all the lines that arent' the shell_path, the other one is bailing out as… | |||||
Done Inline ActionsMmmm, I fail to see where this answers my question. mat: Mmmm, I fail to see where this answers my question. | |||||
Done Inline ActionsSo on deinstall we bufferize the content of /etc/shells for all lines except the one we want to possibility remove. If the shell we are interested in is found we overwrite /etc/shells if not we just drop the buffer ;) on install this is this opposite we append our new shell only if we haven't already found it in existing /etc/shells bapt: So on deinstall we bufferize the content of /etc/shells for all lines except the one we want… | |||||
Done Inline ActionsNo, I get your point about what post-install and pre-deinstall do, I did the first time around. mat: No, I get your point about what post-install and pre-deinstall do, I did the first time around. | |||||
Done Inline ActionsMaybe I was not clear enough, doing if <not> ( sonething ) is ok, but doing if <not> (something) else (something else) is an anti-pattern, if there is an else, the test must be a positive thing and the clauses switched, otherwise it gets hard on the brain. mat: Maybe I was not clear enough, doing if <not> ( sonething ) is ok, but doing if <not>… | |||||
Done Inline ActionsRight ok, now I understand what you mean makes sense, let me fix that ;) bapt: Right ok, now I understand what you mean makes sense, let me fix that ;) | |||||
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 | EOD |
Why == in the post-install and ~= here?