summaryrefslogtreecommitdiffstats
path: root/old/infest.d
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2015-07-11 19:44:12 +0200
committertv <tv@krebsco.de>2015-07-11 19:44:12 +0200
commit153422f74b1ed5cae37c9424514a9e9d1f79acb4 (patch)
tree94cd29e6a98f1ce6228104055d0550e318242290 /old/infest.d
parente21f45386d7aeb3dd3e9d828e1702115f4ef2bce (diff)
move old stuff
Diffstat (limited to 'old/infest.d')
-rw-r--r--old/infest.d/cac-CentOS-7-64bit/finalize.sh66
-rw-r--r--old/infest.d/cac-CentOS-7-64bit/prepare.sh104
-rw-r--r--old/infest.d/nixos-install.sh8
3 files changed, 178 insertions, 0 deletions
diff --git a/old/infest.d/cac-CentOS-7-64bit/finalize.sh b/old/infest.d/cac-CentOS-7-64bit/finalize.sh
new file mode 100644
index 0000000..b70276b
--- /dev/null
+++ b/old/infest.d/cac-CentOS-7-64bit/finalize.sh
@@ -0,0 +1,66 @@
+#! /bin/sh
+set -eu
+{
+ umount /mnt2
+ umount /mnt/nix
+ umount /mnt/boot
+ umount /mnt
+ umount /boot
+
+ PATH=$(for i in /nix/store/*coreutils*/bin; do :; done; echo $i)
+ export PATH
+
+ mkdir /oldshit
+
+ mv /bin /oldshit/
+ mv /newshit/bin /
+
+ # TODO ensure /boot is empty
+ rmdir /newshit/boot
+
+ # skip /dev
+ rmdir /newshit/dev
+
+ mv /etc /oldshit/
+ mv /newshit/etc /
+
+ # TODO ensure /home is empty
+ rmdir /newshit/home
+
+ # skip /nix (it's already there)
+ rmdir /newshit/nix
+
+ # skip /proc
+ rmdir /newshit/proc
+
+ # skip /run
+ rmdir /newshit/run
+
+ # skip /sys
+ rmdir /newshit/sys
+
+ # skip /tmp
+ # TODO rmdir /newshit/tmp
+
+ mv /usr /oldshit/
+ mv /newshit/usr /
+
+ mv /var /oldshit/
+ mv /newshit/var /
+
+ mv /root /oldshit/
+ mv /newshit/root /
+
+ mv /lib /oldshit/
+ mv /lib64 /oldshit/
+ mv /sbin /oldshit/
+ mv /mnt2 /oldshit/
+ mv /srv /oldshit/
+ mv /opt /oldshit/
+
+
+ mv /newshit /root/ # TODO this one shoult be empty
+ mv /oldshit /root/
+
+ sync
+}
diff --git a/old/infest.d/cac-CentOS-7-64bit/prepare.sh b/old/infest.d/cac-CentOS-7-64bit/prepare.sh
new file mode 100644
index 0000000..f932e9c
--- /dev/null
+++ b/old/infest.d/cac-CentOS-7-64bit/prepare.sh
@@ -0,0 +1,104 @@
+#! /bin/sh
+set -euf
+
+: $nix_url
+: $nix_sha256
+
+{
+ #
+ # prepare host
+ #
+
+ type bzip2 2>/dev/null || yum install -y bzip2
+ type rsync 2>/dev/null || yum install -y rsync
+
+ if ! getent group nixbld >/dev/null; then
+ groupadd -g 30000 -r nixbld
+ fi
+ for i in `seq 1 10`; do
+ if ! getent passwd nixbld$i 2>/dev/null; then
+ useradd \
+ -c "CentOS Nix build user $i" \
+ -d /var/empty \
+ -g 30000 \
+ -G 30000 \
+ -l \
+ -M \
+ -s /sbin/nologin \
+ -u $(expr 30000 + $i) \
+ nixbld$i
+ rm -f /var/spool/mail/nixbld$i
+ fi
+ done
+
+ # generate fake sudo because
+ # sudo: sorry, you must have a tty to run sudo
+ mkdir -p bin
+ printf '#! /bin/sh\nexec env "$@"\n' > bin/sudo
+ chmod +x bin/sudo
+
+ PATH=$PWD/bin:$PATH
+ export PATH
+
+ # install nix on host (cf. https://nixos.org/nix/install)
+ if ! test -e /root/.nix-profile/etc/profile.d/nix.sh; then
+ (
+ verify() {
+ echo $nix_sha256 $(basename $nix_url) | sha256sum -c
+ }
+ if ! verify; then
+ curl -C - -O "$nix_url"
+ verify
+ fi
+ )
+ tar jxf $(basename $nix_url)
+ $(basename $nix_url .tar.bz2)/install
+ fi
+
+ MANPATH=/var/empty . /root/.nix-profile/etc/profile.d/nix.sh
+
+ if ! type nixos-install 2>/dev/null; then
+ nixpkgs_expr='import <nixpkgs> { system = builtins.currentSystem; }'
+ nixpkgs_path=$(find /nix/store -mindepth 1 -maxdepth 1 -name *-nixpkgs-* -type d)
+ nix-env \
+ --arg config "{ nix.package = ($nixpkgs_expr).nix; }" \
+ --arg pkgs "$nixpkgs_expr" \
+ --arg modulesPath 'throw "no modulesPath"' \
+ -f $nixpkgs_path/nixpkgs/nixos/modules/installer/tools/tools.nix \
+ -iA config.system.build.nixos-install
+ fi
+
+ #
+ # mount install directory
+ #
+
+ if ! mount | grep -Fq '/dev/mapper/centos-root on /mnt type xfs'; then
+ mkdir -p /newshit
+ mount --bind /newshit /mnt
+ fi
+
+ if ! mount | grep -Fq '/dev/sda1 on /mnt/boot type xfs'; then
+ mkdir -p /mnt/boot
+ mount /dev/sda1 /mnt/boot
+ fi
+
+ if ! mount | grep -Fq '/dev/mapper/centos-root on /mnt/nix type xfs'; then
+ mkdir -p /mnt/nix
+ mount --bind /nix /mnt/nix
+ fi
+
+ mount | grep 'on /mnt\>' >&2
+
+ #
+ # prepare install directory
+ #
+ # XXX This should be done by (?)
+ # remote_dir=/mnt ./cac pushconfig servername:c731445864-cloudpro-134581046 rmdir
+
+ mkdir -p /mnt/etc/nixos
+ mkdir -m 0555 -p /mnt/var/empty
+
+ # add eye candy
+ address=$(echo $SSH_CONNECTION | awk '{print$3}')
+ echo 'PS1='\''\[\e[1;31m\]\u@'"$address"'\[\e[m\] \[\e[1;32m\]\w\[\e[m\] '\' > .bashrc
+}
diff --git a/old/infest.d/nixos-install.sh b/old/infest.d/nixos-install.sh
new file mode 100644
index 0000000..df01a34
--- /dev/null
+++ b/old/infest.d/nixos-install.sh
@@ -0,0 +1,8 @@
+#! /bin/sh
+# usage: cat infest-nixos-install.sh | ./cac ssh ...
+set -euf
+nixos-install \
+ -I secrets=/etc/nixos/secrets \
+ -I retiolum-hosts=/etc/nixos/hosts \
+ -I pubkeys=/etc/nixos/pubkeys \
+ -I nixpkgs=/etc/nixos/nixpkgs