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