-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·89 lines (67 loc) · 1.77 KB
/
setup.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
#!/bin/bash
#####################
#This script setup environment to run this container
#
# --- What it must do? ---
# * Quest where is the ssh pub key
# * Create a volume with chosed name
#
# by: isca
#####################
source ./colors
sshkey(){
read -p "Full path for your public key: " pubkey
export pubkey="$pubkey"
}
volcreate(){
if ! docker volume inspect weechat > /dev/null 2>&1 ;then
echo -e ""$green"Criando volume "$cyan"weechat"$clean""
docker volume create --name weechat
if [ -e $(pwd)/dkweechat.tar.gz ];then
$0 restore
fi
fi
}
compose(){
docker-compose up -d && docker-compose logs -f
}
backup(){
if [ -e $(pwd)/dkweechat.tar.gz ]; then
mv $(pwd)/dkweechat.tar.gz $(pwd)/dkweechat-$(date +%d-%m-%y-%N).tar.gz
fi
docker run --rm -v weechat:/data -v $(pwd):/backup --name weechatbkp alpine tar cvzf /backup/dkweechat.tar.gz /data
}
restore(){
docker run --rm -v weechat:/data -v $(pwd):/backup --name restorewee alpine sh -c "tar xvzf /backup/dkweechat.tar.gz -C / ; chown -R 1000.1000 /data/weechat"
}
run(){
sshkey;
volcreate;
compose;
}
helpme(){
echo -e "\n"$whiteb""$red"Use: "$green""$0" "$cyan"run"$whiteb"|"$cyan"bkp"$whiteb"|"$cyan"restore"$whiteb"|"$cyan"help"$clean"\n"
echo -e "
"$cyan"run "$pink"-->"$clean" Build container and run with docker-compose
"$cyan"bkp "$pink"-->"$clean" Create a backup file "$red"dkweechat.tar.gz"$clean" with settings of the container vol
"$cyan"restore "$pink"-->"$clean" Restore backup file dkweechat.tar.gz to the weechat volume
"$cyan"help "$pink"-->"$clean" Display this help
\n"
}
case $1 in
run)
run
;;
bkp)
backup
;;
restore)
restore
;;
help)
helpme
;;
*)
helpme
;;
esac