summaryrefslogtreecommitdiff
path: root/kernel/get-deps
blob: d93b434d5473456e8c939fe73589eb246b85558a (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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#! /bin/sh

set -ex

srcdir="$(dirname "$0")"
test -z "$srcdir" && srcdir=.

cd "$srcdir"

clone_repo_commit() {
    if test -d "$2/.git"; then
        git -C "$2" reset --hard
        git -C "$2" clean -fd
        if ! git -C "$2" checkout $3; then
            rm -rf "$2"
        fi
    else
        if test -d "$2"; then
            set +x
            echo "error: '$2' is not a Git repository"
            exit 1
        fi
    fi
    if ! test -d "$2"; then
        git clone $1 "$2"
        if ! git -C "$2" checkout $3; then
            rm -rf "$2"
            exit 1
        fi
    fi
}

download_by_hash() {
    DOWNLOAD_COMMAND="curl -Lo"
    if ! command -v "${DOWNLOAD_COMMAND%% *}" >/dev/null 2>&1; then
        DOWNLOAD_COMMAND="wget -O"
        if ! command -v "${DOWNLOAD_COMMAND%% *}" >/dev/null 2>&1; then
            set +x
            echo "error: Neither curl nor wget found"
            exit 1
        fi
    fi
    SHA256_COMMAND="sha256sum"
    if ! command -v "${SHA256_COMMAND%% *}" >/dev/null 2>&1; then
        SHA256_COMMAND="sha256"
        if ! command -v "${SHA256_COMMAND%% *}" >/dev/null 2>&1; then
            set +x
            echo "error: Cannot find sha256(sum) command"
            exit 1
        fi
    fi
    if ! test -f "$2" || ! $SHA256_COMMAND "$2" | grep $3 >/dev/null 2>&1; then
        rm -f "$2"
        mkdir -p "$2" && rm -rf "$2"
        $DOWNLOAD_COMMAND "$2" $1
        if ! $SHA256_COMMAND "$2" | grep $3 >/dev/null 2>&1; then
            set +x
            echo "error: Cannot download file '$2' by hash"
            echo "incorrect hash:"
            $SHA256_COMMAND "$2"
            rm -f "$2"
            exit 1
        fi
    fi
}

clone_repo_commit \
    https://codeberg.org/osdev/freestnd-c-hdrs.git \
    freestnd-c-hdrs \
    4039f438fb1dc1064d8e98f70e1cf122f91b763b

clone_repo_commit \
    https://codeberg.org/osdev/freestnd-cxx-hdrs.git \
    freestnd-cxx-hdrs \
    85096df5361a4d7ef2ce46947e555ec248c2858e

clone_repo_commit \
    https://codeberg.org/osdev/cc-runtime.git \
    cc-runtime \
    dae79833b57a01b9fd3e359ee31def69f5ae899b

download_by_hash \
    https://github.com/limine-bootloader/limine/raw/4687a182be23939c2d9f15db970382dc353ed956/limine.h \
    src/limine.h \
    6879e626f34c1be25ac2f72bf43b083fc2b53887280bb0fcdaee790e258c6974
#! /bin/sh

set -ex

srcdir="$(dirname "$1")"
test -z "$srcdir" && srcdir=.

cd "$srcdir"

clone_repo_commit() {
    if test -d "$2/.git"; then
        git -C "$2" reset --hard
        git -C "$2" clean -fd
        if ! git -C "$2" checkout $3; then
            rm -rf "$2"
        fi
    else
        if test -d "$2"; then
            set +x
            echo "error: '$2' is not a Git repository"
            exit 1
        fi
    fi
    if ! test -d "$2"; then
        git clone $1 "$2"
        if ! git -C "$2" checkout $3; then
            rm -rf "$2"
            exit 1
        fi
    fi
}

download_by_hash() {
    DOWNLOAD_COMMAND="curl -Lo"
    if ! command -v "${DOWNLOAD_COMMAND%% *}" >/dev/null 2>&1; then
        DOWNLOAD_COMMAND="wget -O"
        if ! command -v "${DOWNLOAD_COMMAND%% *}" >/dev/null 2>&1; then
            set +x
            echo "error: Neither curl nor wget found"
            exit 1
        fi
    fi
    SHA256_COMMAND="sha256sum"
    if ! command -v "${SHA256_COMMAND%% *}" >/dev/null 2>&1; then
        SHA256_COMMAND="sha256"
        if ! command -v "${SHA256_COMMAND%% *}" >/dev/null 2>&1; then
            set +x
            echo "error: Cannot find sha256(sum) command"
            exit 1
        fi
    fi
    if ! test -f "$2" || ! $SHA256_COMMAND "$2" | grep $3 >/dev/null 2>&1; then
        rm -f "$2"
        mkdir -p "$2" && rm -rf "$2"
        $DOWNLOAD_COMMAND "$2" $1
        if ! $SHA256_COMMAND "$2" | grep $3 >/dev/null 2>&1; then
            set +x
            echo "error: Cannot download file '$2' by hash"
            echo "incorrect hash:"
            $SHA256_COMMAND "$2"
            rm -f "$2"
            exit 1
        fi
    fi
}

clone_repo_commit \
    https://codeberg.org/osdev/freestnd-c-hdrs.git \
    freestnd-c-hdrs \
    4039f438fb1dc1064d8e98f70e1cf122f91b763b

clone_repo_commit \
    https://codeberg.org/osdev/freestnd-cxx-hdrs.git \
    freestnd-cxx-hdrs \
    85096df5361a4d7ef2ce46947e555ec248c2858e

clone_repo_commit \
    https://codeberg.org/osdev/cc-runtime.git \
    cc-runtime \
    dae79833b57a01b9fd3e359ee31def69f5ae899b

download_by_hash \
    https://github.com/limine-bootloader/limine/raw/4687a182be23939c2d9f15db970382dc353ed956/limine.h \
    src/limine.h \
    6879e626f34c1be25ac2f72bf43b083fc2b53887280bb0fcdaee790e258c6974