]> git.saurik.com Git - cydia.git/blame - Library/move.sh
We like the new icon, we do.
[cydia.git] / Library / move.sh
CommitLineData
c7c6384e
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
c7c6384e 15
9b76c840
JF
16 mkdir -p /var/stash
17 dst=$(mktemp -d /var/stash/$(basename "${dir}").XXXXXX)
c7c6384e
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
c7c6384e
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
9b76c840 46 mv_ "${dir}"
c7c6384e 47 fi
9b76c840 48 elif [[ ! -e ${dir} ]]; then
c7c6384e 49 rm -f "${dir}"
9b76c840 50 mv_ "${dir}"
c7c6384e
JF
51 fi
52}
53
54shift_ "$@"