]> git.saurik.com Git - cydia.git/blame - Library/move.sh
Update to the completed translations from Tethras.
[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
8994cfca
JF
24 tmp=$(mktemp -d /var/stash/_.XXXXXX)
25 dst=${tmp}/${src##*/}
26
27 mkdir -- "${dst}" || {
28 rmdir -- "${tmp}"
29 exit 1
30 }
c7c6384e
JF
31
32 if [[ -e ${src} ]]; then
33 chmod --reference="${src}" "${dst}"
34 chown --reference="${src}" "${dst}"
35
d4b6208d 36 cp -aT $v "${src}" "${dst}" || {
8994cfca 37 rm -rf "${tmp}"
c7c6384e
JF
38 exit 1
39 }
40
d4b6208d 41 rm -rf $v "${src}"
c7c6384e
JF
42 else
43 chmod 775 "${dst}"
44 chown root.admin "${dst}"
45 fi
46
47 ln -s "${dst}" "${src}"
8994cfca 48 echo -n "${src}" >"${tmp}.lnk"
c7c6384e
JF
49}
50
51function shift_() {
6d9712c4 52 dir=${1%/}
c7c6384e
JF
53
54 if [[ -d ${dir} && ! -h ${dir} ]]; then
6204f56a 55 used=$(/usr/libexec/cydia/du -bs "${dir}")
c7c6384e
JF
56 used=${used%%$'\t'*}
57 free=$(df_ /var)
58
59 if [[ $((used + 524288)) -lt ${free} ]]; then
9b76c840 60 mv_ "${dir}"
c7c6384e 61 fi
9b76c840 62 elif [[ ! -e ${dir} ]]; then
c7c6384e 63 rm -f "${dir}"
9b76c840 64 mv_ "${dir}"
c7c6384e
JF
65 fi
66}
67
68shift_ "$@"