prepareEnv,checkEnv refactor; other tiny fixes

This commit is contained in:
Eric Litak 2017-02-13 17:30:42 -08:00
parent 7c2f3e8e2d
commit cad9b43b69

View file

@ -1,6 +1,6 @@
#! /usr/bin/env bash #! /usr/bin/env bash
# Use Digital Ocean Droplet image: # These are the only supported Digital Ocean images:
# #
# Fedora 24 x64 # Fedora 24 x64
# Ubuntu 16.04 x64 # Ubuntu 16.04 x64
@ -45,10 +45,7 @@
# simply didn't work for me! (old system was being because grub wasnt properly # simply didn't work for me! (old system was being because grub wasnt properly
# reinstalled) # reinstalled)
set -ex set -ex -o pipefail
export disk=$( (>/dev/null ls -l /dev/vda && echo vda) \
|| (>/dev/null ls -l /dev/sda && echo sda) )
makeConf() { makeConf() {
# NB <<"EOF" quotes / $ ` in heredocs, <<EOF does not # NB <<"EOF" quotes / $ ` in heredocs, <<EOF does not
@ -142,6 +139,7 @@ EOF
} }
makeSwap() { makeSwap() {
# TODO check currently available swapspace first
swapFile=`mktemp` swapFile=`mktemp`
dd if=/dev/zero of=$swapFile bs=1M count=$((1*1024)) dd if=/dev/zero of=$swapFile bs=1M count=$((1*1024))
chmod 0600 $swapFile chmod 0600 $swapFile
@ -149,18 +147,35 @@ makeSwap() {
swapon $swapFile swapon $swapFile
} }
makeConf prepareEnv() {
makeSwap # smallest (512MB) droplet needs extra memory!
which dnf && dnf install -y perl-Digest-SHA # Fedora 24 which dnf && dnf install -y perl-Digest-SHA # Fedora 24
which bzcat || (which yum && yum install -y bzip2) # CentOS which bzcat || (which yum && yum install -y bzip2) # CentOS
# $disk is used in makeConf()
disk=$( (test -e /dev/vda && echo vda)
|| (test -e /dev/sda && echo sda) )
# DigitalOcean doesn't seem to set USER while running user data # DigitalOcean doesn't seem to set USER while running user data
export USER="root" export USER="root"
export HOME="/root" export HOME="/root"
# FIXME run only if necessary
groupadd -r nixbld -g 30000 || true groupadd -r nixbld -g 30000 || true
seq 1 10 | xargs -I{} useradd -c "Nix build user {}" -d /var/empty -g nixbld -G nixbld -M -N -r -s `which nologin` nixbld{} || true seq 1 10 | xargs -I{} useradd -c "Nix build user {}" -d /var/empty -g nixbld -G nixbld -M -N -r -s `which nologin` nixbld{} || true
}
checkEnv() {
# TODO: use wget -O- if available instead of curl. This involves patching the
# /nix/install script to not check for curl and use `wget -O` instead of
# `curl -L # -o`
( which curl || echo "ERROR: Missing curl" ) && \
( which bzcat || echo "ERROR: Missing bzcat" ) && \
( which perl || echo "ERROR: Missing perl" )
}
infect() {
makeConf
makeSwap # smallest (512MB) droplet needs extra memory!
curl https://nixos.org/nix/install | sh curl https://nixos.org/nix/install | sh
@ -196,5 +211,7 @@ EOF
rm -rf /boot.bak && mv -v /boot /boot.bak && rm -rf /boot.bak && mv -v /boot /boot.bak &&
/nix/var/nix/profiles/system/bin/switch-to-configuration boot /nix/var/nix/profiles/system/bin/switch-to-configuration boot
}
reboot prepareEnv
checkEnv && infect && reboot