setup_{RedHat,Debian}.sh, make more idempotent

Previously, when either setup_{RedHat,Debian}.sh was ran
multiple times a mess was created due to multiple loop
devices being setup.

This change now looks to see if '/docker' or '/swapfile'
already exist, and not re-create them if they do.

*However*, /var/lib/docker (/docker) is still wiped - but it
means that the script can run and bring the system into a
constant vanilla state.

Change-Id: I169662fa04c2bf644672ca75c3ee579795943727
Closes-Bug: #1586563
Signed-off-by: Dave Walker (Daviey) <email@daviey.com>
This commit is contained in:
Dave Walker (Daviey) 2016-06-07 10:49:19 +01:00
parent 0ac3719a17
commit 334ef7d540
2 changed files with 25 additions and 17 deletions

View File

@ -20,15 +20,19 @@ function add_key {
}
function setup_disk {
sudo swapoff -a
sudo dd if=/dev/zero of=/swapfile bs=1M count=4096
sudo chmod 0600 /swapfile
sudo mkswap /swapfile
sudo /sbin/swapon /swapfile
if [ ! -f /swapfile ]; then
sudo swapoff -a
sudo dd if=/dev/zero of=/swapfile bs=1M count=4096
sudo chmod 0600 /swapfile
sudo mkswap /swapfile
sudo /sbin/swapon /swapfile
fi
sudo dd if=/dev/zero of=/docker bs=1M count=10240
losetup -f /docker
DEV=$(losetup -a | awk -F: '/\/docker/ {print $1}')
if [ ! -f /docker ]; then
sudo dd if=/dev/zero of=/docker bs=1M count=10240
losetup -f /docker
DEV=$(losetup -a | awk -F: '/\/docker/ {print $1}')
fi
# Format Disks and setup Docker to use BTRFS
sudo parted ${DEV} -s -- mklabel msdos

View File

@ -4,15 +4,19 @@ set -o xtrace
set -o errexit
function setup_disk {
sudo swapoff -a
sudo dd if=/dev/zero of=/swapfile bs=1M count=4096
sudo chmod 0600 /swapfile
sudo mkswap /swapfile
sudo /sbin/swapon /swapfile
if [ ! -f /swapfile ]; then
sudo swapoff -a
sudo dd if=/dev/zero of=/swapfile bs=1M count=4096
sudo chmod 0600 /swapfile
sudo mkswap /swapfile
sudo /sbin/swapon /swapfile
fi
sudo dd if=/dev/zero of=/docker bs=1M count=20480
losetup -f /docker
DEV=$(losetup -a | awk -F: '/\/docker/ {print $1}')
if [ ! -f /docker ]; then
sudo dd if=/dev/zero of=/docker bs=1M count=20480
losetup -f /docker
DEV=$(losetup -a | awk -F: '/\/docker/ {print $1}')
fi
# Format Disks and setup Docker to use BTRFS
sudo parted ${DEV} -s -- mklabel msdos
@ -53,7 +57,7 @@ sudo systemctl start docker
sudo docker info
# disable ipv6 until we're sure routes to fedora mirrors work properly
sudo sh -c 'echo "net.ipv6.conf.all.disable_ipv6 = 1" >> /etc/sysctl.conf'
sudo sh -c 'echo "net.ipv6.conf.all.disable_ipv6 = 1" > /etc/sysctl.d/disable_ipv6.conf'
sudo /usr/sbin/sysctl -p
echo "Completed $0."