summarylogtreecommitdiffstats
path: root/gg-cap
blob: 0fb899030adadd99da154ab0145723a1abf554ae (plain)
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
#!/bin/sh

set -e

YELLOW="$(tput setaf 3 2>/dev/null || printf '')"
RED="$(tput setaf 1 2>/dev/null || printf '')"
NO_COLOR="$(tput sgr0 2>/dev/null || printf '')"

warn() {
  printf '%s\n' "${YELLOW}! $*${NO_COLOR}"
}

error() {
  printf '%s\n' "${RED}! $*${NO_COLOR}"
  exit 1
}

if [[ -f /proc/sys/kernel/yama/ptrace_scope ]]; then
  ptrace_scope=$(cat /proc/sys/kernel/yama/ptrace_scope)
  case $ptrace_scope in
    2)
      warn "Your ptrace_scope is 2, give the correct capability to
gg."
      /usr/bin/setcap cap_net_raw,cap_sys_ptrace+ep /usr/bin/gg
      ;;
    3)
      error "Your kernel does not allow ptrace permission, gg may not
work."
      ;;
    *)
      echo "No need to setcap."
  esac
else
  warn "YAMA support is not enabled in the kernel, still setting
capabilities..."
  /usr/bin/setcap cap_net_raw,cap_sys_ptrace+ep /usr/bin/gg
fi