forked from Docker-nano/Buildroot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnano
executable file
·98 lines (78 loc) · 2.45 KB
/
nano
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
#!/bin/bash
version=1.0.0
cd "$(dirname "$0")"
. "$PWD"/settings
shopt -s extglob
help() {
cat <<-nano
·▄▄▄▄ ▄▄· ▄ •▄ ▄▄▄ .▄▄▄ ▐ ▄
██▪ ██ ▪ ▐█ ▀▪█▌▄▌▪▀▄.▀·█ █· ▪ █▌▐█ ▄▄▄· •█▄ ▌▪
▐█ ▐█▌▄█▀▄ ██ ▄▄▐█▀▄·█▀▀▪▄▐▀▀▄ ▐█▐▐▌▐█ ▀█ ▐██▐█ ▄█▀▄
██. ██▐█▌.▐▌▐███▌▐█.█▌▐█▄▄▌▐█•█▌ ██▐█▌▐█▀▀█▌██▐█▌▐█▌.▐▌
▀▀▀▀▀• ▀█▄▀▪·▀▀▀ ·▀ ▀ ▀▀▀ .▀ ▀ ▀▀ █▪ ▀ ▪▀ ▀ ▀▪ ▀█▄▀•
Docker nano Buildroot container workflow helper v$version
Usage: '$0' <$ops> [arg]...
nano
}
build() {
docker build -t "$NANO_IMAGE" .
}
run() {
containerExists "$NANO_CONTAINER" && {
read -rn1 -p'Remove previous container [Y/n]? ' remove
echo
[[ $remove = n ]] && { resume; return; }
# Destroy any previous container because image might have been updated.
echo -n Removing old container...
docker stop "$NANO_CONTAINER" >&- 2>&-
docker rm "$NANO_CONTAINER" >&- 2>&-
echo ' done.'
}
echo "Starting '$NANO_CONTAINER' container..."
docker run -it --name="$NANO_CONTAINER" "$NANO_IMAGE"
}
resume() {
docker start "$NANO_CONTAINER" >&-
if which docker-enter >/dev/null; then
echo "Entering '$NANO_CONTAINER' container..."
docker-enter "$NANO_CONTAINER"
else
echo "Resuming '$NANO_CONTAINER' container..."
docker attach "$NANO_CONTAINER"
fi
}
pull() {
# Pull everything.
(( $# == 0 )) && for op in config patches rootfs; do $FUNCNAME $op; done
case $1 in
conf?(ig))
(
dir=in; [ -d $dir ] || mkdir $dir && cd $dir &&
docker cp "$NANO_CONTAINER":/root/buildroot/defconfig . &&
mv defconfig buildroot.conf &&
echo Copied $1 to $dir/$_.
);;
patch?(es))
docker cp "$NANO_CONTAINER":/root/buildroot/patches in &&
echo Copied patches to $_ directory.
;;
rootfs)
docker cp "$NANO_CONTAINER":/root/buildroot/output/images/ out/ &&
echo Copied $1 to $_ directory.
;;
esac
}
containerExists() [[
# Only containers have state.
$(docker inspect -f {{.State}} "$1" 2>&-) = map\[*\]
]]
# Operations whitelist.
ops='help|build|run|resume|pull'
# If operation whitelisted...
if [[ $1 = @($ops) ]]; then
# Execute operation.
$1 "${@:2}"
else
help >&2
exit 1
fi