Last active
July 4, 2019 13:07
-
-
Save leoh0/8711d3ee486220137a3cb0a8aedc80bf to your computer and use it in GitHub Desktop.
sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function ensure_privileged_or_exit() { | |
grep -xq $'CapBnd:\t0000003fffffffff' /proc/self/status || \ | |
(echo -e "[ERROR] Run with --privileged option." ; exit 1) | |
} | |
### Main | |
ensure_privileged_or_exit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
set -o pipefail | |
function ensure_privileged_or_exit() { | |
local i=0 | |
local n=0 | |
# make bitmask (1111...111) | |
s=$(printf "%-$(($(cat /proc/sys/kernel/cap_last_cap) + 1))s" "1") | |
str="${s// /1}" | |
# translate to decimal number (n) | |
while [ $i -lt ${#str} ]; do | |
n=$(( 2*n + ${str:$i:1} )) | |
i=$((i+1)) | |
done | |
# check process status | |
grep -xq "$(printf 'CapBnd:\t%.16x' $n)" /proc/self/status || \ | |
(echo -e "[ERROR] Run with --privileged option." ; exit 1) | |
} | |
### Main | |
ensure_privileged_or_exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
감사합니다. 덕분에 유용하게 쓰고있습니다