Repository navigation
Expand file tree
/
Copy pathdeploy.sh
More file actions
136 lines (120 loc) · 4.31 KB
/
Copy pathdeploy.sh
File metadata and controls
136 lines (120 loc) · 4.31 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/sh
# Linux Deploy Component
# (c) Anton Skshidlevsky <meefik@gmail.com>, GPLv3
[ -n "${FS_TYPE}" ] || FS_TYPE="auto"
[ -n "${DISK_SIZE}" ] || DISK_SIZE="0"
rootfs_make()
{
msg -n "Checking installation path ... "
case "${TARGET_TYPE}" in
file)
if [ -e "${TARGET_PATH}" -a ! -f "${TARGET_PATH}" ]; then
msg "fail"; return 1
fi
;;
partition)
if [ ! -b "${TARGET_PATH}" ]; then
msg "fail"; return 1
fi
;;
directory|ram)
if [ -e "${TARGET_PATH}" -a ! -d "${TARGET_PATH}" ]; then
msg "fail"; return 1
fi
;;
esac
msg "done"
if [ "${TARGET_TYPE}" = "file" ]; then
local file_size=0
if [ -f "${TARGET_PATH}" ]; then
file_size=$(stat -c %s "${TARGET_PATH}")
fi
if [ -z "${DISK_SIZE}" -o "${DISK_SIZE}" -le 0 ]; then
local block_size=$(stat -c %s -f "${TARGET_PATH%/*}")
local available_size=$(stat -c %a -f "${TARGET_PATH%/*}")
let available_size="${block_size}*${available_size}+${file_size}"
let DISK_SIZE="(${available_size}-${available_size}/10)/1048576"
if [ "${DISK_SIZE}" -gt 4095 ]; then
DISK_SIZE=4095
fi
if [ "${DISK_SIZE}" -lt 512 ]; then
DISK_SIZE=512
fi
fi
let file_size="${file_size}/1048576"
if [ "${DISK_SIZE}" != "${file_size}" ]; then
msg -n "Making new disk image (${DISK_SIZE} MB) ... "
dd if=/dev/zero of="${TARGET_PATH}" bs=1048576 seek="$(expr ${DISK_SIZE} - 1)" count=1 ||
dd if=/dev/zero of="${TARGET_PATH}" bs=1048576 count="${DISK_SIZE}"
is_ok "fail" "done" || return 1
fi
fi
if [ "${TARGET_TYPE}" = "file" -o "${TARGET_TYPE}" = "partition" ]; then
local fs fs_support
for fs in ext4 ext3 ext2
do
if $(grep -q "${fs}" /proc/filesystems); then
fs_support="${fs}"
break
fi
done
if [ -z "${fs_support}" ]; then
msg "The filesystems ext2, ext3 or ext4 is not supported."; return 1
fi
if [ -z "${FS_TYPE}" -o "${FS_TYPE}" = "auto" ]; then
FS_TYPE="${fs_support}"
fi
msg -n "Making file system (${FS_TYPE}) ... "
local loop_exist=$(losetup -a | grep -c "${TARGET_PATH}")
local img_mounted=$(grep -c "${TARGET_PATH}" /proc/mounts)
if [ "${loop_exist}" -ne 0 -o "${img_mounted}" -ne 0 ]; then
msg "fail"; return 1
fi
mke2fs -qF -t "${FS_TYPE}" -O ^has_journal "${TARGET_PATH}" >/dev/null
is_ok "fail" "done" || return 1
fi
if [ "${TARGET_TYPE}" = "directory" ]; then
if [ -d "${TARGET_PATH}" ]; then
chmod -R 755 "${TARGET_PATH}"
rm -rf "${TARGET_PATH}"
fi
mkdir -p "${TARGET_PATH}"
fi
if [ "${TARGET_TYPE}" = "ram" ]; then
umount "${TARGET_PATH}"
if [ -z "${DISK_SIZE}" -o "${DISK_SIZE}" -le 0 ]; then
local ram_free=$(grep ^MemFree /proc/meminfo | awk '{print $2}')
let DISK_SIZE="${ram_free}/1024"
fi
msg -n "Making new disk image (${DISK_SIZE} MB) ... "
if [ ! -d "${TARGET_PATH}" ]; then
mkdir "${TARGET_PATH}"
fi
mount -t tmpfs -o size="${DISK_SIZE}M" tmpfs "${TARGET_PATH}"
is_ok "fail" "done" || return 1
fi
return 0
}
do_install()
{
if [ "${CHROOT_DIR}" != "${TARGET_PATH}" ]; then
container_mounted && { msg "The container is already mounted."; return 1; }
fi
msg ":: Installing ${COMPONENT} ... "
rootfs_make || return 1
container_mount || return 1
if is_archive "${SOURCE_PATH}" ; then
rootfs_import "${SOURCE_PATH}"
fi
}
do_help()
{
cat <<EOF
--target-type=file|partition|directory|ram
Вариант развертывания контейнера.
--disk-size=SIZE
Размер файла образа, когда выбран тип развертывания "file". Ноль означает автоматический выбор размера образа.
--fs-type=ext2|ext3|ext4|auto
Файловая система, которая будет создана внутри образа или на разделе.
EOF
}