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