Skip to content

Instantly share code, notes, and snippets.

@3XX0
Last active May 3, 2018 16:17
Show Gist options
  • Save 3XX0/ef77403389ffa1ca85d4625878706c7d to your computer and use it in GitHub Desktop.
Save 3XX0/ef77403389ffa1ca85d4625878706c7d to your computer and use it in GitHub Desktop.
#! /bin/sh
# To allow users to setup their permissions:
# tee -a /etc/sudoers <<< "%lxc-users ALL=/usr/local/bin/generate-lxc-perms"
set -eu
USER="${SUDO_USER:-${1:?usage: $0 <user>}}"
UIDSPEC="$(getent passwd ${USER})"
GIDSPEC="$(getent group `id -g ${USER}`)"
VETHS=10
echo "Setting up subuids:"
echo ${UIDSPEC} | awk -F: '{print $1":"$3":1\n"$1":"$3"000:1000"}' | tee -a /etc/subuid
sort -u -o /etc/subuid /etc/subuid
echo "\nSetting up subgids:"
echo ${GIDSPEC} | awk -F: '{print $1":"$3":1\n"$1":"$3"000:1000"}' | tee -a /etc/subgid
sort -u -o /etc/subgid /etc/subgid
echo "\nSetting up usernet:"
echo "${USER} veth lxcbr0 ${VETHS}" | tee -a /etc/lxc/lxc-usernet
sort -u -o /etc/lxc/lxc-usernet /etc/lxc/lxc-usernet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment