aboutsummaryrefslogtreecommitdiff
path: root/Keywords/shell.ucl
blob: 4993d2fd93845d45c3b534fe95288dfb426d58aa (plain) (blame)
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
# MAINTAINER: portmgr@FreeBSD.org
#
# @shell bin/shell
#
# Handle adding and remove a path to a shell binary into /etc/shells
#

actions: [file]
post-install-lua: <<EOD
  shell_path = pkg.prefixed_path("%@")
  shell = assert(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
  assert(shell:write(shell_path .. "\n"))
  assert(shell:close())
EOD
pre-deinstall-lua: <<EOD
  shell_path = pkg.prefixed_path("%@")
  shellsbuf = ""
  shells_path = "/etc/shells"
  shell = assert(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
  assert(shell:close())
  if found then
    shell = assert(io.open(shells_path, "w+"))
    assert(shell:write(shellsbuf))
    assert(shell:close())
  end
EOD