]> git.saurik.com Git - cydia.git/blame - Library/move.sh
Label width, move.sh, and Default-Icon.
[cydia.git] / Library / move.sh
CommitLineData
1951a333
JF
1#!/bin/bash
2
3shopt -s extglob nullglob
4
5function df_() {
6 free=$(df -B1 "$1")
7 free=${free% *%*}
8 free=${free%%*( )}
9 free=${free##* }
10 echo "${free}"
11}
12
13function mv_() {
14 src=$1
15 dst=$2
16
17 if [[ -e ${dst} ]]; then
18 dst=$(mktemp -d /var/cydia.XXXXXX)
19 else
20 mkdir -p "${dst}"
21 fi
22
23 if [[ -e ${src} ]]; then
24 chmod --reference="${src}" "${dst}"
25 chown --reference="${src}" "${dst}"
26
27 cp -aT "${src}" "${dst}" || {
28 rm -rf "${dst}"
29 exit 1
30 }
31
32 rm -rf "${src}"
33 else
34 chmod 775 "${dst}"
35 chown root.admin "${dst}"
36 fi
37
38 ln -s "${dst}" "${src}"
39}
40
41function shift_() {
42 dir=$1
43 dst=$2
44
45 if [[ -d ${dir} && ! -h ${dir} ]]; then
46 used=$(du -bs "${dir}")
47 used=${used%%$'\t'*}
48 free=$(df_ /var)
49
50 if [[ $((used + 524288)) -lt ${free} ]]; then
51 mv_ "${dir}" "${dst}"
52 fi
53 elif [[ -h ${dir} && ! -e ${dir} ]]; then
54 rm -f "${dir}"
55 mv_ "${dir}" "${dst}"
56 fi
57}
58
59shift_ "$@"