-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_common.sh
executable file
·56 lines (47 loc) · 1.1 KB
/
_common.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
#!/bin/bash
import() {
local BASE=$(dirname $(realpath "$0"))
source $BASE/${1}.sh
}
import-lab() {
import lab-$1
}
import-labs() {
for sc in $@; do
import-lab $sc
done
}
is_used() {
[[ ! -z $(ss -tulpn | awk '{print $5}' | grep ":$1") ]]
}
new_port() {
local lb=32768
local port=$(( $RANDOM + $lb ))
while $(is_used $port); do
local port=$(( $RANDOM + $lb ));
done
echo $port
}
user_container() {
echo Lab-"$USER"${1:+-"$1"}
}
_info_long="{{- .Name}} ({{.Config.Image}}) Status: [{{.State.Status}}$1] Home: {{range .Mounts -}}
{{- if eq .Destination \"/home/$USER\" -}}
[{{- .Source -}}]
{{- end -}}
{{- end -}}
; Port: [{{- (index (index .Config.Cmd) 2) -}}]"
_info_short="{{- .Name}} [{{.State.Status}}$1] Port: [{{- (index (index .Config.Cmd) 2) -}}]"
info(){
local id=$1
local format_name=$2
case $format_name in
'long' )
format=$_info_long
;;
'short' | * )
format=$_info_short
;;
esac
$docker inspect --format="$format" $id
}