]> git.saurik.com Git - cydia.git/blame - Library/move.sh
Ported to latest firmware and fixed locales.
[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
1951a333 15
09a722fb
JF
16 mkdir -p /var/stash
17 dst=$(mktemp -d /var/stash/$(basename "${dir}").XXXXXX)
1951a333
JF
18
19 if [[ -e ${src} ]]; then
20 chmod --reference="${src}" "${dst}"
21 chown --reference="${src}" "${dst}"
22
23 cp -aT "${src}" "${dst}" || {
24 rm -rf "${dst}"
25 exit 1
26 }
27
28 rm -rf "${src}"
29 else
30 chmod 775 "${dst}"
31 chown root.admin "${dst}"
32 fi
33
34 ln -s "${dst}" "${src}"
35}
36
37function shift_() {
38 dir=$1
1951a333
JF
39
40 if [[ -d ${dir} && ! -h ${dir} ]]; then
41 used=$(du -bs "${dir}")
42 used=${used%%$'\t'*}
43 free=$(df_ /var)
44
45 if [[ $((used + 524288)) -lt ${free} ]]; then
09a722fb 46 mv_ "${dir}"
1951a333 47 fi
09a722fb 48 elif [[ ! -e ${dir} ]]; then
1951a333 49 rm -f "${dir}"
09a722fb 50 mv_ "${dir}"
1951a333
JF
51 fi
52}
53
54shift_ "$@"