github.com/wlan0/docker@v1.5.0/contrib/check-config.sh (about)

     1  #!/usr/bin/env bash
     2  set -e
     3  
     4  # bits of this were adapted from lxc-checkconfig
     5  # see also https://github.com/lxc/lxc/blob/lxc-1.0.2/src/lxc/lxc-checkconfig.in
     6  
     7  possibleConfigs=(
     8  	'/proc/config.gz'
     9  	"/boot/config-$(uname -r)"
    10  	"/usr/src/linux-$(uname -r)/.config"
    11  	'/usr/src/linux/.config'
    12  )
    13  : ${CONFIG:="${possibleConfigs[0]}"}
    14  
    15  if ! command -v zgrep &> /dev/null; then
    16  	zgrep() {
    17  		zcat "$2" | grep "$1"
    18  	}
    19  fi
    20  
    21  is_set() {
    22  	zgrep "CONFIG_$1=[y|m]" "$CONFIG" > /dev/null
    23  }
    24  
    25  # see http://en.wikipedia.org/wiki/ANSI_escape_code#Colors
    26  declare -A colors=(
    27  	[black]=30
    28  	[red]=31
    29  	[green]=32
    30  	[yellow]=33
    31  	[blue]=34
    32  	[magenta]=35
    33  	[cyan]=36
    34  	[white]=37
    35  )
    36  color() {
    37  	color=()
    38  	if [ "$1" = 'bold' ]; then
    39  		color+=( '1' )
    40  		shift
    41  	fi
    42  	if [ $# -gt 0 ] && [ "${colors[$1]}" ]; then
    43  		color+=( "${colors[$1]}" )
    44  	fi
    45  	local IFS=';'
    46  	echo -en '\033['"${color[*]}"m
    47  }
    48  wrap_color() {
    49  	text="$1"
    50  	shift
    51  	color "$@"
    52  	echo -n "$text"
    53  	color reset
    54  	echo
    55  }
    56  
    57  wrap_good() {
    58  	echo "$(wrap_color "$1" white): $(wrap_color "$2" green)"
    59  }
    60  wrap_bad() {
    61  	echo "$(wrap_color "$1" bold): $(wrap_color "$2" bold red)"
    62  }
    63  wrap_warning() {
    64  	wrap_color >&2 "$*" red
    65  }
    66  
    67  check_flag() {
    68  	if is_set "$1"; then
    69  		wrap_good "CONFIG_$1" 'enabled'
    70  	else
    71  		wrap_bad "CONFIG_$1" 'missing'
    72  	fi
    73  }
    74  
    75  check_flags() {
    76  	for flag in "$@"; do
    77  		echo "- $(check_flag "$flag")"
    78  	done
    79  }
    80  
    81  if [ ! -e "$CONFIG" ]; then
    82  	wrap_warning "warning: $CONFIG does not exist, searching other paths for kernel config..."
    83  	for tryConfig in "${possibleConfigs[@]}"; do
    84  		if [ -e "$tryConfig" ]; then
    85  			CONFIG="$tryConfig"
    86  			break
    87  		fi
    88  	done
    89  	if [ ! -e "$CONFIG" ]; then
    90  		wrap_warning "error: cannot find kernel config"
    91  		wrap_warning "  try running this script again, specifying the kernel config:"
    92  		wrap_warning "    CONFIG=/path/to/kernel/.config $0"
    93  		exit 1
    94  	fi
    95  fi
    96  
    97  wrap_color "info: reading kernel config from $CONFIG ..." white
    98  echo
    99  
   100  echo 'Generally Necessary:'
   101  
   102  echo -n '- '
   103  cgroupSubsystemDir="$(awk '/[, ](cpu|cpuacct|cpuset|devices|freezer|memory)[, ]/ && $3 == "cgroup" { print $2 }' /proc/mounts | head -n1)"
   104  cgroupDir="$(dirname "$cgroupSubsystemDir")"
   105  if [ -d "$cgroupDir/cpu" -o -d "$cgroupDir/cpuacct" -o -d "$cgroupDir/cpuset" -o -d "$cgroupDir/devices" -o -d "$cgroupDir/freezer" -o -d "$cgroupDir/memory" ]; then
   106  	echo "$(wrap_good 'cgroup hierarchy' 'properly mounted') [$cgroupDir]"
   107  else
   108  	if [ "$cgroupSubsystemDir" ]; then
   109  		echo "$(wrap_bad 'cgroup hierarchy' 'single mountpoint!') [$cgroupSubsystemDir]"
   110  	else
   111  		echo "$(wrap_bad 'cgroup hierarchy' 'nonexistent??')"
   112  	fi
   113  	echo "    $(wrap_color '(see https://github.com/tianon/cgroupfs-mount)' yellow)"
   114  fi
   115  
   116  if [ "$(cat /sys/module/apparmor/parameters/enabled 2>/dev/null)" = 'Y' ]; then
   117  	echo -n '- '
   118  	if command -v apparmor_parser &> /dev/null; then
   119  		echo "$(wrap_good 'apparmor' 'enabled and tools installed')"
   120  	else
   121  		echo "$(wrap_bad 'apparmor' 'enabled, but apparmor_parser missing')"
   122  		echo -n '    '
   123  		if command -v apt-get &> /dev/null; then
   124  			echo "$(wrap_color '(use "apt-get install apparmor" to fix this)')"
   125  		elif command -v yum &> /dev/null; then
   126  			echo "$(wrap_color '(your best bet is "yum install apparmor-parser")')"
   127  		else
   128  			echo "$(wrap_color '(look for an "apparmor" package for your distribution)')"
   129  		fi
   130  	fi
   131  fi
   132  
   133  flags=(
   134  	NAMESPACES {NET,PID,IPC,UTS}_NS
   135  	DEVPTS_MULTIPLE_INSTANCES
   136  	CGROUPS CGROUP_CPUACCT CGROUP_DEVICE CGROUP_FREEZER CGROUP_SCHED
   137  	MACVLAN VETH BRIDGE
   138  	NF_NAT_IPV4 IP_NF_FILTER IP_NF_TARGET_MASQUERADE
   139  	NETFILTER_XT_MATCH_{ADDRTYPE,CONNTRACK}
   140  	NF_NAT NF_NAT_NEEDED
   141  
   142  	# required for bind-mounting /dev/mqueue into containers
   143  	POSIX_MQUEUE
   144  )
   145  check_flags "${flags[@]}"
   146  echo
   147  
   148  echo 'Optional Features:'
   149  flags=(
   150  	MEMCG_SWAP
   151  	RESOURCE_COUNTERS
   152  	CGROUP_PERF
   153  )
   154  check_flags "${flags[@]}"
   155  
   156  echo '- Storage Drivers:'
   157  {
   158  	echo '- "'$(wrap_color 'aufs' blue)'":'
   159  	check_flags AUFS_FS | sed 's/^/  /'
   160  	if ! is_set AUFS_FS && grep -q aufs /proc/filesystems; then
   161  		echo "    $(wrap_color '(note that some kernels include AUFS patches but not the AUFS_FS flag)' bold black)"
   162  	fi
   163  	check_flags EXT4_FS_POSIX_ACL EXT4_FS_SECURITY | sed 's/^/  /'
   164  
   165  	echo '- "'$(wrap_color 'btrfs' blue)'":'
   166  	check_flags BTRFS_FS | sed 's/^/  /'
   167  
   168  	echo '- "'$(wrap_color 'devicemapper' blue)'":'
   169  	check_flags BLK_DEV_DM DM_THIN_PROVISIONING EXT4_FS EXT4_FS_POSIX_ACL EXT4_FS_SECURITY | sed 's/^/  /'
   170  
   171  	echo '- "'$(wrap_color 'overlay' blue)'":'
   172  	check_flags OVERLAY_FS | sed 's/^/  /'
   173  } | sed 's/^/  /'
   174  echo
   175  
   176  #echo 'Potential Future Features:'
   177  #check_flags USER_NS
   178  #echo