-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·102 lines (90 loc) · 2.58 KB
/
build.sh
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
#!/bin/bash
set -eo pipefail
function build_data {
buildah rm devdata || true
buildah from --name devdata busybox:latest
buildah unshare --mount devdata sh -c 'tar -czf wsl-data.tar.gz -C $devdata .'
buildah rm devdata
}
function reset_build_data {
build_data
wsl.exe --unregister wsl-data-dev || true
WINHOME_LIN=$(wslpath $(powershell.exe Write-Output '$env:USERPROFILE') | tr -d '\r')
WINHOME=$(wslpath -w "$WINHOME_LIN")
wsl.exe --import wsl-data-dev "${WINHOME}\\wsl\\wsl-data" "./wsl-data.tar"
wsl.exe -d wsl-data-dev /mount.sh
}
function build_wsl {
local variant=$1
rm "devbox-${variant}-wsl.tar" || true
buildah bud --format=docker -f "docker/${variant}/Dockerfile" -t "devbox-${variant}:latest" .
buildah from --name devdevdev "localhost/devbox-${variant}:latest"
buildah unshare --mount devdevdev sh -c 'tar -czf devbox-'"${variant}"'-wsl.tar.gz -C $devdevdev .'
buildah rm devdevdev
}
function import_wsl {
local variant=$1
local wslname=$2
echo "installing ${variant} as WSL distribution: ${wslname}"
WINHOME_LIN=$(wslpath $(powershell.exe Write-Output '$env:USERPROFILE') | tr -d '\r')
WINHOME=$(wslpath -w "$WINHOME_LIN")
wsl.exe --import "${wslname}" "${WINHOME}\\wsl\\${wslname}" "./devbox-${variant}-wsl.tar"
}
function build_import {
local variant=$1
local wslname=$2
build_wsl "${variant}"
import_wsl "${variant}" "${wslname}"
echo "new build imported"
}
function delete_build_import {
local variant=$1
local wslname=$2
delete_devbox "${wslname}"
build_wsl "${variant}"
import_wsl "${variant}" "${wslname}"
echo "new build imported"
}
function delete_devbox {
local wslname=$1
wsl.exe --unregister "${wslname}" || true
}
function devbox {
local wslname=$1
wsl.exe -d "${wslname}"
}
# Main switch case to handle command line arguments
case "$1" in
build_data)
build_data
;;
reset_build_data)
reset_build_data
;;
build_wsl)
build_wsl "$2"
;;
import_wsl)
import_wsl "$2" "$3"
;;
build_import)
build_import "$2" "$3"
;;
delete_build_import)
delete_build_import "$2" "$3"
;;
build_wsl_compressed)
build_wsl_compressed "$2"
;;
delete_devbox)
delete_devbox "$2"
;;
devbox)
devbox "$2"
;;
*)
echo "Usage: $0 {build_data|reset_build_data|build_wsl|import_wsl|build_import|delete_build_import|build_wsl_compressed|delete_devbox|devbox} [args]";
exit 1
;;
esac
exit 0