summaryrefslogtreecommitdiff
path: root/deploy.sh
blob: 4d9df969d33f7150e444df8bfac2a28aebf6eb6a (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/run/current-system/profile/bin/bash

gather_env() {
    # Gather needed information
    echo -n "Type 'e' for encrypted or 'd' for decrypted install: "
    read install_type

    echo -n "Type system hostname: "
    read install_hostname

    echo -n "Type device file for ROOT data: "
    read root_dev

    echo -n "Type device file for BOOT data: "
    read boot_dev

    echo -n "Type device file for SWAP: "
    read swap_dev

}

copy_and_prepare() {
    # Associate devs with uuids
    root_uuid=`blkid $root_dev | awk -F\" '{print $2}'`
    boot_uuid=`blkid $boot_dev | awk -F\" '{print $2}'`
    swap_uuid=`blkid $swap_dev | awk -F\" '{print $2}'`
    # Let's a go!
    echo "Information gathered. Deploying Guix on $root_dev ($root_uuid) with boot on $boot_dev ($boot_uuid) and swap on $swap_dev ($swap_uuid)"
    echo -n "Proceed? (y/n): "
    read install_choice

    if [ "$install_choice" != "y" ]
    then
        echo "Bailing!"
        exit 1
    fi

    # We are installing!
    # Copy template to root of repo
    if [ "$install_type" == "e" ]
    then
        cp ./modules/ryan-config/deploy-templates/HostTemplateEncrypted ./$install_hostname.scm
    elif [ "$install_type" == "d" ]
    then
        cp ./modules/ryan-config/deploy-templates/HostTemplate ./$install_hostname.scm
    else
        echo "Invalid install type (not d or e), bailing!"
        exit 1
    fi

    # Correct the information
    sed -i "s/ChangeMe_ROOT/$root_uuid/" ./$install_hostname.scm
    sed -i "s/ChangeMe_BOOTEFI/$boot_uuid/" ./$install_hostname.scm
    sed -i "s/ChangeMe_SWAP/$swap_uuid/" ./$install_hostname.scm
    sed -i "s/ChangeMe_HOST/$install_hostname/" ./$install_hostname.scm

    # Install!
    echo "Mounting /gnu/store to destination disk..."
    herd start cow-store /mnt

    # Install the non-guix signing keys
    echo "Installing non-guix signing keys for substitutes..."
    curl -o sign-key.pub https://substitutes.nonguix.org/signing-key.pub
    curl -o sign-key-r.pub http://129.21.94.53:8000/signing-key.pub
    guix archive --authorize < sign-key.pub
    guix archive --authorize < sign-key-r.pub
}

install_system() {
    echo "Beginning install!"
    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
}

install_user_env() {
    # System should be installed now, we can chroot in and configure the user profile now
    # NOTE: This assumes the user "ryan" for things, so change the USER var if you change your username

    # Copy some files over to prepare for reboot
    USER=ryan
    guix shell git -- git clone https://git.stationery.faith/ryan77627/guix-dotfiles /mnt/home/$USER/.config/guix

    cp ~/guix-dotfiles/$install_hostname.scm /mnt/home/$USER/.config/guix/$install_hostname.scm
    cp ~/guix-dotfiles/modules/ryan-config/user_first_run.sh /mnt/home/$USER/.bashrc

    chown 1000:1000 -R /mnt/home/ryan

}

if [[ $* == *-p ]]
then
    echo "Installing non-guix signing keys for substitutes..."
    curl -o sign-key.pub https://substitutes.nonguix.org/signing-key.pub
    curl -o sign-key-r.pub http://129.21.94.53:8000/signing-key.pub
    guix archive --authorize < sign-key.pub
    guix archive --authorize < sign-key-r.pub
    guix time-machine -C ./channels.scm -- pull
    exit 0
elif [[ $* == *-i ]]
then
    gather_env
    # Associate devs with uuids
    root_uuid=`blkid $root_dev | awk -F\" '{print $2}'`
    boot_uuid=`blkid $boot_dev | awk -F\" '{print $2}'`
    swap_uuid=`blkid $swap_dev | awk -F\" '{print $2}'`
    # Let's a go!
    echo "Information gathered. Deploying Guix on $root_dev ($root_uuid) with boot on $boot_dev ($boot_uuid) and swap on $swap_dev ($swap_uuid)"
    echo -n "Proceed? (y/n): "
    read install_choice

    if [ "$install_choice" != "y" ]
    then
        echo "Bailing!"
        exit 1
    fi

    # We are installing!
    # Copy template to root of repo
    if [ "$install_type" == "e" ]
    then
        cp ./modules/ryan-config/deploy-templates/HostTemplateEncrypted ./$install_hostname.scm
    elif [ "$install_type" == "d" ]
    then
        cp ./modules/ryan-config/deploy-templates/HostTemplate ./$install_hostname.scm
    else
        echo "Invalid install type (not d or e), bailing!"
        exit 1
    fi

    # Correct the information
    sed -i "s/ChangeMe_ROOT/$root_uuid/" ./$install_hostname.scm
    sed -i "s/ChangeMe_BOOTEFI/$boot_uuid/" ./$install_hostname.scm
    sed -i "s/ChangeMe_SWAP/$swap_uuid/" ./$install_hostname.scm
    sed -i "s/ChangeMe_HOST/$install_hostname/" ./$install_hostname.scm

    # Install!
    echo "Mounting /gnu/store to destination disk..."
    herd start cow-store /mnt
    install_system
    install_user_env
    exit 0
fi

gather_env
copy_and_prepare
install_system
install_user_env

# Reboot the machine at this point!
#reboot