summaryrefslogtreecommitdiff
path: root/Library/move.sh
diff options
context:
space:
mode:
authorJay Freeman (saurik) <saurik@saurik.com>2008-03-08 21:57:55 +0000
committerJay Freeman (saurik) <saurik@saurik.com>2008-03-08 21:57:55 +0000
commitc7c6384e1b4b08d546b9f1d7728c218eee42ac0f (patch)
tree0d7f37e41222642d1d5f11367471f2d1d3160922 /Library/move.sh
parentec97ef06d3da4f9426d971319fc1b8c6eaf5631a (diff)
Label width, move.sh, and Default-Icon.
Diffstat (limited to 'Library/move.sh')
-rwxr-xr-xLibrary/move.sh59
1 files changed, 59 insertions, 0 deletions
diff --git a/Library/move.sh b/Library/move.sh
new file mode 100755
index 0000000..31c89e4
--- /dev/null
+++ b/Library/move.sh
@@ -0,0 +1,59 @@
+#!/bin/bash
+
+shopt -s extglob nullglob
+
+function df_() {
+ free=$(df -B1 "$1")
+ free=${free% *%*}
+ free=${free%%*( )}
+ free=${free##* }
+ echo "${free}"
+}
+
+function mv_() {
+ src=$1
+ dst=$2
+
+ if [[ -e ${dst} ]]; then
+ dst=$(mktemp -d /var/cydia.XXXXXX)
+ else
+ mkdir -p "${dst}"
+ fi
+
+ if [[ -e ${src} ]]; then
+ chmod --reference="${src}" "${dst}"
+ chown --reference="${src}" "${dst}"
+
+ cp -aT "${src}" "${dst}" || {
+ rm -rf "${dst}"
+ exit 1
+ }
+
+ rm -rf "${src}"
+ else
+ chmod 775 "${dst}"
+ chown root.admin "${dst}"
+ fi
+
+ ln -s "${dst}" "${src}"
+}
+
+function shift_() {
+ dir=$1
+ dst=$2
+
+ if [[ -d ${dir} && ! -h ${dir} ]]; then
+ used=$(du -bs "${dir}")
+ used=${used%%$'\t'*}
+ free=$(df_ /var)
+
+ if [[ $((used + 524288)) -lt ${free} ]]; then
+ mv_ "${dir}" "${dst}"
+ fi
+ elif [[ -h ${dir} && ! -e ${dir} ]]; then
+ rm -f "${dir}"
+ mv_ "${dir}" "${dst}"
+ fi
+}
+
+shift_ "$@"