summaryrefslogtreecommitdiff
path: root/guix-strap/guix-partition
blob: 6669129a46269ec35099e8f6d553bab1a5d64a8f (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
#!/run/current-system/profile/bin/bash

set -o emacs;

CONFIRM=""
DISK=""

source ./guix-log
source ./guix-env

EVENT "Partitioning disks"

confirm() {
    if [ "$CONFIRM" == "y" ]; then
        exit 0
    fi
    read -p "Are you sure: ($1)? [y/N] " CONFIRM
    if [ "$CONFIRM" == "y" ]; then
        exit 0
    else
        exit 1
    fi
}

check_disk() {
    lsblk $1 &> /dev/null || exit 1
    FS=$(df $1 | tail -n 1 | awk '{print $1}')
    if [ "$FS" == "none" ]; then
        exit 0
    else
        exit 1
    fi
}

get_disk() {
    CONFIRM=""
    read -ep "Enter disk (e.g. /dev/sda): " DISK
    if [ ! -b "$DISK" ]; then
        ERROR "$DISK: file does not exist"
        get_disk
        return
    fi
    (check_disk "$DISK");
    if [ "$?" -ne 0 ]; then
        ERROR "$DISK: not a valid disk"
        get_disk
        return
    fi
    (confirm "$DISK");
    if [ "$?" -ne 0 ]; then
        get_disk
    fi
}

get_disk

EVENT "Partitioning disks with fdisk..."

fdisk "$DISK" <<EOF
g
n


+1GiB
t
EFI System
n



t
2
Linux Filesystem
w
EOF

echo "DISK=\"$DISK\"" >> ./guix-env

EVENT "Disks have been successfully partitioned on $DISK"