DEVELOPMENT ENVIRONMENT

~liljamo/src.quest-anemos

src.quest-anemos/justfile -rw-r--r-- 2.7 KiB
1a58233cJonni Liljamo feat: persistent disk 7 days ago
                                                                                
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
# Alpine Linux setup
mod alpine "./just/alpine.just"

_default:
    just --list

# Check if host directory exists
[group("check")]
host-dir-exists host:
    #!/usr/bin/env sh
    if [ ! -d {{host}} ]; then
        echo "{{host}} does not exist"
        exit 1
    fi

# Check host reachability via ping
[group("check")]
host-reachable host: (host-dir-exists host)
    #!/usr/bin/env sh
    ping -w 1 -c 1 $(cat ./{{host}}/ADDRESS)
    if [ $? -ne 0 ]; then
        echo "{{host}} is not reachable"
        exit 1
    fi

# All checks
[group("check")]
check host: (host-dir-exists host) (host-reachable host)

# Remove common files from host
[group("cleanup")]
remove-common host: (host-dir-exists host)
    #!/usr/bin/env sh
    prefix="./common/"
    for file in $(find ./common/ -type f); do
        path=${file#$"$prefix"}
        rm -f "./{{host}}/files/$path"
    done

# Remove build artifacts
[group("cleanup")]
remove-artifacts host: (host-dir-exists host)
    rm -f "./{{host}}/{{host}}.img"
    rm -f "./{{host}}/{{host}}.packages"
    rm -f "./{{host}}/payload.tar.gz"

# All cleanups
[group("cleanup")]
cleanup host: (remove-common host) (remove-artifacts host)

# Merge common files into host directory
merge-with-common host: (host-dir-exists host)
    cp --archive --force ./common/. ./{{host}}/files/

# Make .makeimg.modes for host
make-modes host: (host-dir-exists host) (merge-with-common host) && (cleanup host)
    #!/usr/bin/env sh
    cd ./{{host}}
    makeimg --record-modes

# Test the IMGBUILD by building an image
test host: (host-dir-exists host) (merge-with-common host) && (cleanup host)
    #!/usr/bin/env sh
    cd ./{{host}}
    sudo makeimg --format "raw 4g msdos ext4"

# Download anemos to the host
get-anemos host: (host-reachable host)
    ssh root@$(cat ./{{host}}/ADDRESS) curl https://git.sr.ht/~bitfehler/anemos-cli/blob/master/anemos -o anemos
    ssh root@$(cat ./{{host}}/ADDRESS) chmod +x ./anemos

# Tar the payload for a host
payload host: (host-dir-exists host) (merge-with-common host)
    #!/usr/bin/env sh
    cd ./{{host}}
    makeimg -R anemos-secrets
    makeimg --apply-modes
    tar czf payload.tar.gz IMGBUILD files anemos-secrets keys repositories
    rm -rf anemos-secrets

# Initialize a new host
init host: (check host) (get-anemos host) (payload host) && (cleanup host)
    scp ./{{host}}/payload.tar.gz ./{{host}}/files/etc/anemos.conf root@$(cat ./{{host}}/ADDRESS):
    ssh root@$(cat ./{{host}}/ADDRESS) ./anemos -c anemos.conf

# Deploy an existing host
deploy host: (check host) (get-anemos host) (payload host) && (cleanup host)
    scp ./{{host}}/payload.tar.gz root@$(cat ./{{host}}/ADDRESS):
    ssh root@$(cat ./{{host}}/ADDRESS) mount /boot
    ssh root@$(cat ./{{host}}/ADDRESS) ./anemos