summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-08-10 08:05:12 -0500
committerLukas Fleischer <archlinux@cryptocrack.de>2011-08-10 15:23:00 +0200
commit6ae2bc514f61d3e56d008cd1901d91bdbc6752d2 (patch)
tree1af7b7f65c50ba8bbe5c69a4dba6619f77177fa9 /scripts
parent9a79d2105e2dea9876883da65a00d245d475bed2 (diff)
downloadaurweb-6ae2bc514f61d3e56d008cd1901d91bdbc6752d2.tar.xz
Add a upload directory transform script
This goes with the previous patch that moves uploads into segmented subdirectories. To actually run, follow the DRYRUN instructions. Signed-off-by: Dan McGee <dan@archlinux.org> Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/uploadbuckets.sh58
1 files changed, 58 insertions, 0 deletions
diff --git a/scripts/uploadbuckets.sh b/scripts/uploadbuckets.sh
new file mode 100755
index 0000000..3252692
--- /dev/null
+++ b/scripts/uploadbuckets.sh
@@ -0,0 +1,58 @@
+#!/bin/bash
+
+DRYRUN=${DRYRUN:-1}
+
+source="$1"
+dest="$2"
+
+if [[ -z $source || -z $dest ]]; then
+ echo 'usage: uploadbuckets.sh <source> <dest>'
+ echo 'Script runs in DRYRUN mode by default.'
+ echo 'To run for real, set DRYRUN=0 in your environment.'
+ exit 1
+fi
+
+if [[ ! -d $source ]]; then
+ echo 'error: source is not a directory'
+ exit 1
+fi
+
+if [[ -e $dest && ! -d $dest ]]; then
+ echo 'error: dest is not a directory'
+ exit 1
+fi
+
+if [[ $(readlink -e $dest) = $(readlink -e $source) ]]; then
+ echo 'error: source and dest cannot be the same. Rotate the result'
+ echo 'into place once the migration is complete.'
+ exit 1
+fi
+
+if [[ ! -d $dest ]]; then
+ mkdir $dest
+fi
+
+shopt -s nullglob
+
+for package in "$source"/*; do
+ pkgname="${package##*/}"
+ newfolder="$dest/${pkgname:0:2}"
+ if [[ ! -d "$newfolder" ]]; then
+ if [[ $DRYRUN -gt 0 ]]; then
+ echo mkdir -p "$newfolder"
+ else
+ mkdir -p "$newfolder"
+ fi
+ fi
+ if [[ $DRYRUN -gt 0 ]]; then
+ echo mv "$source/$pkgname" "$newfolder/$pkgname"
+ else
+ mv "$source/$pkgname" "$newfolder/$pkgname"
+ fi
+done
+
+if [[ $DRYRUN -gt 0 ]]; then
+ echo
+ echo 'DRYRUN mode was enabled.'
+ echo 'To run for real, set DRYRUN=0 in your environment.'
+fi