summaryrefslogtreecommitdiffstats
path: root/krebs/4lib/infest/finalize.sh
blob: 94b13e0becfe1b567b76d544b8474001eb60578f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#! /bin/sh
set -eux
{
  umount /mnt/nix
  umount /mnt/root
  umount /mnt/boot
  umount /boot || :
  umount /mnt

  coreutils_path=$(set +f; for i in /nix/store/*coreutils*/bin; do :; done; echo $i)
  sed_path=$(set +f; for i in /nix/store/*gnused*/bin; do :; done; echo $i)
  PATH="$coreutils_path:$sed_path"

  export PATH

  mkdir /oldshit

  #fix bug where grub install cant find the /nix/store because its under a bind mount
  if test -e /boot/grub/grub.cfg; then
    sed -i 's,//store,/nix/store,g' /boot/grub/grub.cfg
  fi;

  mv /bin /oldshit/
  mv /newshit/bin /

  # TODO ensure /boot is empty
  # skip boot
  rmdir /newshit/boot

  # skip /dev
  rmdir /newshit/dev

  mv /etc /oldshit/
  mv /newshit/etc /

  # 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 /root
  rmdir /newshit/root

  # skip /tmp
  # TODO rmdir /newshit/tmp

  mv /home /oldshit/
  mv /newshit/home /

  mv /usr /oldshit/
  mv /newshit/usr /

  mv /var /oldshit/
  mv /newshit/var /

  mv /lib /oldshit/
  mv /lib64 /oldshit/
  mv /sbin /oldshit/
  mv /srv /oldshit/
  mv /opt /oldshit/


  mv /newshit /root/  # TODO this one shoult be empty
  mv /oldshit /root/

  sync
}