deploy.sh

pres · 4.8 KB · 149 lines raw

1 #!/run/current-system/profile/bin/bash
2
3 gather_env() {
4 # Gather needed information
5 echo -n "Type 'e' for encrypted or 'd' for decrypted install: "
6 read install_type
7
8 echo -n "Type system hostname: "
9 read install_hostname
10
11 echo -n "Type device file for ROOT data: "
12 read root_dev
13
14 echo -n "Type device file for BOOT data: "
15 read boot_dev
16
17 echo -n "Type device file for SWAP: "
18 read swap_dev
19
20 }
21
22 copy_and_prepare() {
23 # Associate devs with uuids
24 root_uuid=`blkid $root_dev | awk -F\" '{print $2}'`
25 boot_uuid=`blkid $boot_dev | awk -F\" '{print $2}'`
26 swap_uuid=`blkid $swap_dev | awk -F\" '{print $2}'`
27 # Let's a go!
28 echo "Information gathered. Deploying Guix on $root_dev ($root_uuid) with boot on $boot_dev ($boot_uuid) and swap on $swap_dev ($swap_uuid)"
29 echo -n "Proceed? (y/n): "
30 read install_choice
31
32 if [ "$install_choice" != "y" ]
33 then
34 echo "Bailing!"
35 exit 1
36 fi
37
38 # We are installing!
39 # Copy template to root of repo
40 if [ "$install_type" == "e" ]
41 then
42 cp ./modules/ryan-config/deploy-templates/HostTemplateEncrypted ./$install_hostname.scm
43 elif [ "$install_type" == "d" ]
44 then
45 cp ./modules/ryan-config/deploy-templates/HostTemplate ./$install_hostname.scm
46 else
47 echo "Invalid install type (not d or e), bailing!"
48 exit 1
49 fi
50
51 # Correct the information
52 sed -i "s/ChangeMe_ROOT/$root_uuid/" ./$install_hostname.scm
53 sed -i "s/ChangeMe_BOOTEFI/$boot_uuid/" ./$install_hostname.scm
54 sed -i "s/ChangeMe_SWAP/$swap_uuid/" ./$install_hostname.scm
55 sed -i "s/ChangeMe_HOST/$install_hostname/" ./$install_hostname.scm
56
57 # Install!
58 echo "Mounting /gnu/store to destination disk..."
59 herd start cow-store /mnt
60
61 # Install the non-guix signing keys
62 echo "Installing non-guix signing keys for substitutes..."
63 curl -o sign-key.pub https://substitutes.nonguix.org/signing-key.pub
64 curl -o sign-key-r.pub http://129.21.94.53:8000/signing-key.pub
65 guix archive --authorize < sign-key.pub
66 guix archive --authorize < sign-key-r.pub
67 }
68
69 install_system() {
70 echo "Beginning install!"
71 guix time-machine -C ./channels.scm -- system -L ./modules --substitute-urls='http://129.21.94.53:8080/ https://substitutes.nonguix.org https://bordeaux.guix.gnu.org https://ci.guix.gnu.org' init $install_hostname.scm /mnt
72 }
73
74 install_user_env() {
75 # System should be installed now, we can chroot in and configure the user profile now
76 # NOTE: This assumes the user "ryan" for things, so change the USER var if you change your username
77
78 # Copy some files over to prepare for reboot
79 USER=ryan
80 guix shell git -- git clone https://git.stationery.faith/ryan77627/guix-dotfiles /mnt/home/$USER/.config/guix
81
82 cp ~/guix-dotfiles/$install_hostname.scm /mnt/home/$USER/.config/guix/$install_hostname.scm
83 cp ~/guix-dotfiles/modules/ryan-config/user_first_run.sh /mnt/home/$USER/.bashrc
84
85 chown 1000:1000 -R /mnt/home/ryan
86
87 }
88
89 if [[ $* == *-p ]]
90 then
91 echo "Installing non-guix signing keys for substitutes..."
92 curl -o sign-key.pub https://substitutes.nonguix.org/signing-key.pub
93 curl -o sign-key-r.pub http://129.21.94.53:8000/signing-key.pub
94 guix archive --authorize < sign-key.pub
95 guix archive --authorize < sign-key-r.pub
96 guix time-machine -C ./channels.scm -- pull
97 exit 0
98 elif [[ $* == *-i ]]
99 then
100 gather_env
101 # Associate devs with uuids
102 root_uuid=`blkid $root_dev | awk -F\" '{print $2}'`
103 boot_uuid=`blkid $boot_dev | awk -F\" '{print $2}'`
104 swap_uuid=`blkid $swap_dev | awk -F\" '{print $2}'`
105 # Let's a go!
106 echo "Information gathered. Deploying Guix on $root_dev ($root_uuid) with boot on $boot_dev ($boot_uuid) and swap on $swap_dev ($swap_uuid)"
107 echo -n "Proceed? (y/n): "
108 read install_choice
109
110 if [ "$install_choice" != "y" ]
111 then
112 echo "Bailing!"
113 exit 1
114 fi
115
116 # We are installing!
117 # Copy template to root of repo
118 if [ "$install_type" == "e" ]
119 then
120 cp ./modules/ryan-config/deploy-templates/HostTemplateEncrypted ./$install_hostname.scm
121 elif [ "$install_type" == "d" ]
122 then
123 cp ./modules/ryan-config/deploy-templates/HostTemplate ./$install_hostname.scm
124 else
125 echo "Invalid install type (not d or e), bailing!"
126 exit 1
127 fi
128
129 # Correct the information
130 sed -i "s/ChangeMe_ROOT/$root_uuid/" ./$install_hostname.scm
131 sed -i "s/ChangeMe_BOOTEFI/$boot_uuid/" ./$install_hostname.scm
132 sed -i "s/ChangeMe_SWAP/$swap_uuid/" ./$install_hostname.scm
133 sed -i "s/ChangeMe_HOST/$install_hostname/" ./$install_hostname.scm
134
135 # Install!
136 echo "Mounting /gnu/store to destination disk..."
137 herd start cow-store /mnt
138 install_system
139 install_user_env
140 exit 0
141 fi
142
143 gather_env
144 copy_and_prepare
145 install_system
146 install_user_env
147
148 # Reboot the machine at this point!
149 #reboot