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