forked from zhangguanzhang/Kubernetes-ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImage.sh
49 lines (41 loc) · 882 Bytes
/
Image.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
#!/bin/bash
set -e
function fhelp (){
cat<<-EOF
Usage: $0 [OPTION]...
Save docker all images to a tar.gz or load from a tar.gz
-f filename
-F [save|load]
Example: $0 -f images.tar.gz -F save
EOF
}
function save (){
[ -f "$filename" ] && { echo 'file exist,please Usage other name';exit 5; }
docker save $(docker images --format {{.Repository}}:{{.Tag}}) | gzip - > $filename
}
function load (){
[ ! -f "$filename" ] && { echo 'file not exist!';exit 6; }
docker load -i $filename
}
while getopts ':f:F:h' args;do
case $args in
f)
filename=$OPTARG
;;
F)
[[ $OPTARG =~ save|load ]] || { fhelp;exit 1; }
func=$OPTARG
;;
h)
fhelp;exit 0;
;;
?)
fhelp;exit 1;
;;
esac
done
[[ -z "$filename" || -z "$func" ]] && {
echo '-f with -F must be simultaneously exist';fhelp
exit 1;
}
$func $filename