forked from my5t3ry/machine-to-proxmox-lxc-ct-converter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert.sh
executable file
·71 lines (65 loc) · 1.84 KB
/
convert.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
#!/bin/bash
usage()
{
cat <<EOF
$1 -h|--help
-n|--name [lxc container name]
-t|--target [target machine ssh uri]
-i|--id [proxmox container id]
-s|--root-size [rootfs size in GB]
-a|--ip [target container ip]
-b|--bridge [bridge interface]
-g|--gateway [gateway ip]
-m|--memory [memory in mb]
-d|--disk-storage [target proxmox storage pool]
-p|--password [root password for container (min. 5 chars)]
EOF
return 0
}
options=$(getopt -o n:t:i:s:a:b:g:m:d:p:f -l help,name:,target:,id:,root-size:,ip:,bridge:,gateway:,memory:,disk-storage:,password:,foo: -- "$@")
if [ $? -ne 0 ]; then
usage $(basename $0)
exit 1
fi
eval set -- "$options"
while true
do
case "$1" in
-h|--help) usage $0 && exit 0;;
-n|--name) name=$2; shift 2;;
-t|--target) target=$2; shift 2;;
-i|--id) id=$2; shift 2;;
-s|--root-size) rootsize=$2; shift 2;;
-a|--ip) ip=$2; shift 2;;
-b|--bridge) bridge=$2; shift 2;;
-g|--gateway) gateway=$2; shift 2;;
-m|--memory) memory=$2; shift 2;;
-p|--password) password=$2; shift 2;;
-d|--disk-storage) storage=$2; shift 2;;
--) shift 2; break ;;
*) break ;;
esac
done
collectFS() {
tar -czvvf - -C / \
--exclude="sys" \
--exclude="dev" \
--exclude="run" \
--exclude="proc" \
--exclude="*.log" \
--exclude="*.log*" \
--exclude="*.gz" \
--exclude="*.sql" \
--exclude="swap.img" \
.
}
ssh "root@$target" "$(typeset -f collectFS); collectFS" \
> "/tmp/$name.tar.gz"
pct create $id "/tmp/$name.tar.gz" \
-description LXC \
-hostname $name \
--features nesting=1 \
-memory $memory -nameserver 8.8.8.8 \
-net0 name=eth0,ip=$ip/24,gw=$gateway,bridge=$bridge \
--rootfs $rootsize -storage $storage -password $password
rm -rf "/tmp/$name.tar.gz"