]> git.saurik.com Git - cydia.git/blob - Library/move.sh
Fixed browser links and modify delegates.
[cydia.git] / Library / move.sh
1 #!/bin/bash
2
3 shopt -s extglob nullglob
4
5 function df_() {
6 free=$(df -B1 "$1")
7 free=${free% *%*}
8 free=${free%%*( )}
9 free=${free##* }
10 echo "${free}"
11 }
12
13 function mv_() {
14 src=$1
15
16 mkdir -p /var/stash
17 dst=$(mktemp -d /var/stash/$(basename "${src}").XXXXXX)
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
37 function shift_() {
38 dir=$1
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
46 mv_ "${dir}"
47 fi
48 elif [[ ! -e ${dir} ]]; then
49 rm -f "${dir}"
50 mv_ "${dir}"
51 fi
52 }
53
54 shift_ "$@"