-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions
executable file
·56 lines (50 loc) · 1.37 KB
/
functions
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
#! /bin/bash
function Downloadfile()
{
if [ "$WHERE" = "china" ]; then
site1="http://mtimercms.u.qiniudn.com/"
site2="http://mtimercms.oss.aliyuncs.com/"
else
site1="http://mtimercms.u.qiniudn.com/"
site2="http://mtimercms.oss.aliyuncs.com/"
fi
randstr=$(date +%s)
package="${1##*/}"
if [ -s ${MPACKAGES_PATH}/$package ]; then
echo "[OK] $package found."
else
echo "[Notice] $package not found, download now......"
if ! wget -c --tries=3 -O ${MPACKAGES_PATH}/$package ${site1}${1}?${randstr} >/dev/null 2>&1; then
if ! wget -c --tries=3 -O ${MPACKAGES_PATH}/$package ${site2}${1}?${randstr} >/dev/null 2>&1; then
echo "[Error] Download Failed : $package, please check $1 "
exit 1
fi
fi
echo "[Success] $package Downloaded."
fi
Unpackfile $package $2
}
function Unpackfile()
{
file_name=$(echo $1 | sed -r 's/ *(.tar|.gz|.bz2|.zip|.tgz)[0-9]* *//g')
file_ext=$(echo $1 |awk -F . '{if (NF>1) {print $NF}}')
case $file_ext in
zip)
unzip ${MPACKAGES_PATH}/$1 -d ${MUNPACKED_PATH} >/dev/null 2>&1
;;
bz2)
tar xvjf ${MPACKAGES_PATH}/$1 -C ${MUNPACKED_PATH} >/dev/null 2>&1
;;
tgz|gz)
tar zxvf ${MPACKAGES_PATH}/$1 -C ${MUNPACKED_PATH} >/dev/null 2>&1
;;
tar)
tar xvf ${MPACKAGES_PATH}/$1 -C ${MUNPACKED_PATH} >/dev/null 2>&1
;;
esac
if test -n "$2"; then
cd ${MUNPACKED_PATH}/$2
else
cd ${MUNPACKED_PATH}/$file_name
fi
}