]> git.saurik.com Git - cydia.git/blob - Library/move.sh
Add section icons for: Fonts, Site-Specific Apps, and Soundboards.
[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 mkdir -p /var/stash
24 dst=$(mktemp -d /var/stash/"${src##*/}".XXXXXX)
25
26 if [[ -e ${src} ]]; then
27 chmod --reference="${src}" "${dst}"
28 chown --reference="${src}" "${dst}"
29
30 cp -aT $v "${src}" "${dst}" || {
31 rm -rf "${dst}"
32 exit 1
33 }
34
35 rm -rf $v "${src}"
36 else
37 chmod 775 "${dst}"
38 chown root.admin "${dst}"
39 fi
40
41 ln -s "${dst}" "${src}"
42 }
43
44 function shift_() {
45 dir=${1%/}
46
47 if [[ -d ${dir} && ! -h ${dir} ]]; then
48 used=$(/usr/libexec/cydia/du -bs "${dir}")
49 used=${used%%$'\t'*}
50 free=$(df_ /var)
51
52 if [[ $((used + 524288)) -lt ${free} ]]; then
53 mv_ "${dir}"
54 fi
55 elif [[ ! -e ${dir} ]]; then
56 rm -f "${dir}"
57 mv_ "${dir}"
58 fi
59 }
60
61 shift_ "$@"