summaryrefslogtreecommitdiff
path: root/lxc/lxc-users-setup
blob: 1fc2486771f486f4c8abb27971f7d60f14ee048f (plain)
    1 #!/bin/sh
    2 
    3 if test $(id -u) -ne 0
    4 then
    5     echo 'This must be run as root.'
    6     exit 1
    7 fi
    8 
    9 write_profile() {
   10     test -f $1 || touch $1 && chown $uid:$gid $1
   11     if ! grep -q '# lxc-users-setup' $1
   12     then
   13         echo 'for i in /sys/fs/cgroup/*/$USER/tasks; do test -w $i && echo $$ > $i; done # lxc-users-setup' >> $1
   14     fi
   15 }
   16 
   17 for i in $(awk '!/^#/{if($1!~"@"){print$1}}' /etc/lxc/lxc-usernet)
   18 do
   19     passwd=$(getent passwd $i)
   20     user=$(echo $passwd | cut -d : -f 1)
   21     uid=$(echo $passwd | cut -d : -f 3)
   22     gid=$(echo $passwd | cut -d : -f 4)
   23     home=$(echo $passwd | cut -d : -f 6)
   24     test -f '/etc/subuid' || touch '/etc/subuid'
   25     if ! grep -qE "^($user|$uid):100000:65536\$" '/etc/subuid'
   26     then
   27         usermod -V 0-4294967295 -v 100000-165535 $user
   28     fi
   29     test -f '/etc/subgid' || touch '/etc/subgid'
   30     if ! grep -qE "^($user|$uid):100000:65536\$" '/etc/subgid'
   31     then
   32         usermod -W 0-4294967295 -w 100000-165535 $user
   33     fi
   34     write_profile $home/.bash_profile
   35     write_profile $home/.zprofile
   36     if ! test -f $home/.config/lxc/default.conf
   37     then
   38         mkdir -p $home/.config/lxc
   39         echo 'lxc.include = /etc/lxc/default.conf' > $home/.config/lxc/default.conf
   40         chown $uid:$gid $home/.config $home/.config/lxc $home/.config/lxc/default.conf
   41     fi
   42 done

Generated by cgit