/
mkpfs
executable file
·147 lines (128 loc) · 5.43 KB
/
mkpfs
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
137
138
139
140
141
142
143
144
145
146
147
#!/bin/sh
#PFS module creator
#VERSION 3.7
. $(which pfs)
D(){
sourcelist="$(find "$1" -maxdepth 1 -mindepth 1 -type d |sort)"
[ "$sourcelist" ] || exitmsg "no directory in '$2'" 1
ondir=
[ "${userout}_" = "_" ] && [ ! "`echo "$arglist" |grep "\-o "`" ] && userout="./$(basename "$1").$EXT"
}
M(){
sourcelist="$(find "$1" -maxdepth 1 -mindepth 1 -type f |egrep ".pfs$|.xzm$|.sfs$|.squashfs$|.$EXT$" |sort)"
[ "$sourcelist" ] || exitmsg "no modules in '$2'" 1
onmod=
[ "${userout}_" = "_" ] && [ ! "`echo "$arglist" |grep "\-o "`" ] && userout="./$(basename "$1").$EXT"
}
#help
HLP(){
echo "Usage: $0 <list of sources> -o out.$EXT"
echo "Examples:"
echo "$0 ./dir -make dir.pfs from dir"
echo "$0 1.$EXT 2.$EXT -o 3.$EXT -collect 1.$EXT and 2.$EXT to contaner 3.$EXT"
echo "$0 * -o ./big.$EXT -collect all dirs and squashfs modules from current dir to big.$EXT"
echo
echo "Параметры (ключи):"
echo " -o / --out-file - указывает название выходного файла (если указать без расширения .$EXT на выходе будет каталог)."
echo " -w - не включать AUFS тени."
echo " -l / --local - сборка на месте, без использования aufs."
echo " -f / --fast - быстрая компрессия (размер .$EXT больше, но создается быстрее)."
echo " --mkilst add files list to simple (non contaner) module"
echo " --mksqfs / параметры для mksquashfs, компрессия размер блока и проч.(Внимание параметр должен быть последним)"
echo "Алиасы (сокращения):"
echo " -d | -D - Только каталоги"
echo " $(basename $0) -d dir ---> $(basename $0)" '$(find dir -maxdepth 1 -mindepth 1 -type d ) -o dir.$EXT'
echo " -m | -M - Только модули"
echo " $(basename $0) -m dir ---> $(basename $0)" '$(find dir -maxdepth 1 -mindepth 1 -type f ) -o dir.$EXT'
exit 1
}
check_kernel(){
checksfsxzb >/dev/null 2>&1
exitmsg "Kernel is not support squashfs/aufs. Work only 'mkpfs -l'" $?
}
#parsing for "--mksqfs" arg
argslist="$@"
if echo $argslist |grep -q "\-*mksqfs .*" ; then
compression="$(echo $@ |sed 's/^.*\-*mksqfs//')"
argslist="$(echo $@ |sed 's/\-*mksqfs.*$//')"
fi
#get opts
sourcelist=""
inplace=""
for arg in $argslist
do
case "${arg}" in
"-o" | "--out-file") onuserout="on";;
"-d" | "-D") ondir="on";;
"-m" | "-M") onmod="on";;
"-h" | "--help") HLP ;exit 1;;
"-q" | "--quiet" ) devnull='>/dev/null' ;;
"-no-progress" | "--no-progress") noprogress="-no-progress";;
"-processors" | "--processors" ) numproc="on";;
"-w") wh="-regex -e ".wh..wh."";;
"-l" | "--local" ) inplace=yes ;;
"--mklist" ) make_list=yes ;;
"-f" | "--fast" | "-g" ) [ "$compression_fast" ] && compression="$compression_fast" || compression="gzip";;
"-"*[A-Za-z]*) echo "$(basename "$0"): invalid option -- '$(echo ${arg} | tr -d '-')'" >&2; HLP; exit 1;;
*) if [ "${usepkname}" = "on" ]; then packname="${arg}"
elif [ "${ondir}" = "on" ]; then D "${arg}"
elif [ "${onmod}" = "on" ]; then M "${arg}"
elif [ "${onuserout}" = "on" ]; then userout="${arg}"
elif [ "${numproc}" = "on" ]; then useproc="-processors ${arg}"
else sourcelist="${sourcelist} ${arg}"; fi
onuserout="off"; usepkname="off"; usindlib="off"; numproc="off";;
esac
done
[ "$sourcelist" ] || HLP
allow_only_root
[ "$inplace" ] || check_kernel
if [ "${userout}_" = "_" ] ; then
first="$(basename $(echo $sourcelist | awk '{print $1}'))"
userout="$(echo ${first%.$EXT}).$EXT"
fi
#1 dir, in place mode
if [ -d $sourcelist 2>/dev/null -a "$inplace" == "yes" ] ;then
eval echo "==== In place mode ====" $devnull
[ ! "$(ls -a $sourcelist)" ] && exitmsg "directory '$sourcelist' empty" 1
[ $make_list ] && mklist $sourcelist $sourcelist ${userout%.$EXT}
mksqmod $sourcelist "${userout}" && exit 0
exitmsg "mkpfs error" 2
fi
#test sources, source must be dir or squashfs module
for source in $sourcelist ;do
[ -d $source ] && continue
[ "$(fs_type $source)" == "squashfs" ] && continue
exitmsg "Type of source \"$source\" is not correct" 2
done
[ -d "$sourcelist" ] && { ls "$sourcelist" 2>/dev/null || exitmsg "\"`echo $sourcelist`\" is empty" 2 ; }
#make root aufs
n="$(mkaufs || exitmsg "mkaufs error" 2)"
nn="$(echo "$n" | sed -n 's/^.*\([0-9]\)$/\1/p')"
[ -d "$n" ] || exitmsg "error mounting aufs" 3
#add sources as aufs layers
for i in $sourcelist ;do
eval addlayer "$nn" "$i" "$devnull" || exitmsg "can't insert layer to aufs $nn" 5
done
if [ $(echo "$sourcelist" | wc -w) -eq 1 ] ;then
# if source is only one - submodule name is $userout with no prefix (pfs,xzm,etc)
[ $make_list ] && mklist "$i" "$n" $([ $(echo $sourcelist |wc -w) -eq 1 ] && echo ${userout%.$EXT} )
else
bundles=$(find $(echo $n |sed 's:aufs:bundles:') -maxdepth 1 -mindepth 1 -type d )
#mklist for modules, submodule name is basename source with no prefix
for i in $bundles ;do
name="$(basename "${i%.$EXT}")"
mklist "$i" "$n" "$name"
done
fi
if echo ${userout} | grep -q "^.*\.$EXT$" ; then
mksqmod "${n}" "${userout}" noexit
else
echo "Please wait..."
rmdir ${userout} 2>/dev/null
[ -d "${userout}" ] && exitmsg "Output diectory already exist" 6
mkdir -p "$(dirname ${userout})"
cp -auPR "${n}" "${userout}"
fi
exitmsg "mksqmod error" $? noexit
delaufs "$nn"
exitmsg "delaufs error" $?