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