]>
Commit | Line | Data |
---|---|---|
c7c6384e JF |
1 | #!/bin/bash |
2 | ||
3 | shopt -s extglob nullglob | |
4 | ||
d4b6208d JF |
5 | if [[ ${1:0:1} == - ]]; then |
6 | v=$1 | |
7 | shift 1 | |
8 | else | |
9 | v= | |
10 | fi | |
11 | ||
c7c6384e JF |
12 | function df_() { |
13 | free=$(df -B1 "$1") | |
14 | free=${free% *%*} | |
15 | free=${free%%*( )} | |
16 | free=${free##* } | |
17 | echo "${free}" | |
18 | } | |
19 | ||
20 | function 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 | ||
44 | function shift_() { | |
6d9712c4 | 45 | dir=${1%/} |
c7c6384e JF |
46 | |
47 | if [[ -d ${dir} && ! -h ${dir} ]]; then | |
6204f56a | 48 | used=$(/usr/libexec/cydia/du -bs "${dir}") |
c7c6384e JF |
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 | ||
61 | shift_ "$@" |