]> git.saurik.com Git - cydia.git/blob - Library/move.sh
Allow user to select a specific candidate version.
[cydia.git] / Library / move.sh
1 #!/bin/bash
2
3 shopt -s extglob nullglob
4
5 if [[ ${1:0:1} == - ]]; then
6 v=$1
7 shift 1
8 else
9 v=
10 fi
11
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
22
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
30
31 tmp=$(mktemp -d /var/stash/_.XXXXXX)
32 dst=${tmp}/${src##*/}
33
34 chmod 755 "${tmp}"
35 chown root.admin "${tmp}"
36
37 mkdir -- "${dst}" || {
38 rmdir -- "${tmp}"
39 exit 1
40 }
41
42 if [[ -e ${src} ]]; then
43 chmod --reference="${src}" "${dst}"
44 chown --reference="${src}" "${dst}"
45
46 cp -aT $v "${src}" "${dst}" || {
47 rm -rf "${tmp}"
48 exit 1
49 }
50
51 rm -rf $v "${src}"
52 else
53 chmod 775 "${dst}"
54 chown root.admin "${dst}"
55 fi
56
57 ln -s "${dst}" "${src}"
58 echo -n "${src}" >"${tmp}.lnk"
59 }
60
61 function shift_() {
62 dir=${1%/}
63
64 if [[ -d ${dir} && ! -h ${dir} ]]; then
65 used=$(/usr/libexec/cydia/du -bs "${dir}")
66 used=${used%%$'\t'*}
67 free=$(df_ /var)
68
69 if [[ $((used + 524288)) -lt ${free} ]]; then
70 mv_ "${dir}"
71 fi
72 elif [[ ! -e ${dir} ]]; then
73 rm -f "${dir}"
74 mv_ "${dir}"
75 fi
76 }
77
78 shift_ "$@"