Last active
August 29, 2015 14:13
-
-
Save jelu/24740ae085f50d0520f0 to your computer and use it in GitHub Desktop.
lxc unprivileged development tricks
This file contains 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
sudo vi /etc/apparmor.d/lxc/lxc-default | |
mount options=(ro, rw, bind), | |
sudo service apparmor reload | |
lxc-create -t download -n ubuntu-lucid-amd64 -- -d ubuntu -r lucid -a amd64 | |
lxc-create -t download -n ubuntu-precise-amd64 -- -d ubuntu -r precise -a amd64 | |
lxc-create -t download -n ubuntu-trusty-amd64 -- -d ubuntu -r trusty -a amd64 | |
lxc-create -t download -n centos-6-amd64 -- -d centos -r 6 -a amd64 | |
lxc-create -t download -n debian-wheezy-amd64 -- -d debian -r wheezy -a amd64 | |
cd .local/share/lxc | |
lxc-usernsexec -- /bin/bash | |
sed -i -e 's%archive.ubuntu.com%ftp.sunet.se/pub/os/Linux/distributions/ubuntu%g' */*/etc/apt/sources.list | |
sed -i -e 's%security.ubuntu.com%ftp.sunet.se/pub/os/Linux/distributions/ubuntu%g' */*/etc/apt/sources.list | |
lxc-clone -s -B overlayfs ubuntu-precise-amd64 prj | |
echo "lxc.mount.entry = /home/$USER/src/prj mnt/prj none bind,create=dir 0 0" | tee -a .local/share/lxc/prj/config | |
lxc-start -n prj -d | |
lxc-attach -n prj -- su - | |
apt-get update | |
apt-get dist-upgrade | |
apt-get install inotify-tools rsync | |
exit | |
lxc-attach -n prj -- su - ubuntu | |
tee sync <<EOS | |
#!/bin/sh | |
if [ -z "$1" ]; then | |
echo "usage: sync <directory>" | |
exit 1 | |
fi | |
if [ ! -d "$1" ]; then | |
mkdir -p -- "$1" | |
fi | |
dirname=`dirname -- "$1"` | |
basename=`basename -- "$1"` | |
if [ ! -d "/mnt/$basename" ]; then | |
echo "ERROR: Directory /mnt/$basename missing" | |
exit 2 | |
fi | |
rsync -aC -- "/mnt/$basename" "$dirname/." | |
( | |
cd -- "/mnt" | |
inotifywait -m -e modify -e create -e delete --exclude '(\.git|\.swx$|\.swp$|\.swpx$|~$)' -r -- "$basename" | |
) | while read dir action file; do | |
if [ "$action" = "DELETE" ]; then | |
rm -f -- "$dirname/$dir$file" >/dev/null 2>/dev/null | |
continue | |
fi | |
if [ "$action" = "DELETE,ISDIR" ]; then | |
rm -rf -- "$dirname/$dir$file" >/dev/null 2>/dev/null | |
continue | |
fi | |
if [ "$action" = "CREATE,ISDIR" ]; then | |
rsync -aC -- "/mnt/$dir$file" "$dirname/$dir" >/dev/null 2>/dev/null | |
continue | |
fi | |
rsync -aC -- "/mnt/$dir$file" "$dirname/$dir$file" >/dev/null 2>/dev/null | |
done | |
EOS | |
chmod +x sync | |
./sync prj & |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment