diff options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/snapshots/cleanup_snapshots.sh | 87 | ||||
-rwxr-xr-x | scripts/snapshots/create_nullbyte_snapshots.sh | 58 |
2 files changed, 145 insertions, 0 deletions
diff --git a/scripts/snapshots/cleanup_snapshots.sh b/scripts/snapshots/cleanup_snapshots.sh new file mode 100755 index 0000000000..f239cc1af0 --- /dev/null +++ b/scripts/snapshots/cleanup_snapshots.sh @@ -0,0 +1,87 @@ +#!/usr/bin/env bash + +## Open script-dir-homed subshell +( +ABS_SCRIPT_DIR=`pwd`/`dirname "$0"` +cd "${ABS_SCRIPT_DIR}" + + +## Internal config +KEEP_COUNT=7 + +## External config +DRY=0 +case "$1" in +-n) + DRY=1 + ;; +--just-print) + DRY=1 + ;; +--dry-run) + DRY=1 + ;; +esac + +if [[ "$DRY" -eq 1 ]]; then + echo 'NOTE: Running in simulation mode' + echo +fi + + +function cleanup_snapshots { + ## Harvest days + LIST_OF_DAYS= + for i in ????-??-?? ; do + LIST_OF_DAYS="$LIST_OF_DAYS $i"; + done + SORTED_DAYS=`echo ${LIST_OF_DAYS} | sed -r 's/ /\n/g' | sort | uniq` + DAY_COUNT=`echo $SORTED_DAYS | wc -w` + if [[ $DAY_COUNT < 1 ]]; then + echo "No files deleted" + exit 0 + fi + + ## Select days to delete + DELETE_COUNT=$((DAY_COUNT - KEEP_COUNT)) + if [[ "${DELETE_COUNT}" -lt 1 ]]; then + echo "No files deleted" + return + fi + if [[ "${DELETE_COUNT}" -gt "${DAY_COUNT}" ]]; then + DELETE_COUNT="${DAY_COUNT}" + fi + DELETE_DAYS=`echo ${SORTED_DAYS} | sed -r 's/ /\n/g' | head -n $DELETE_COUNT` + echo "Deleting ${DELETE_COUNT} of ${DAY_COUNT} days" + + ## Delete days + COUNTER=1 + for PRETTY_DAY in ${DELETE_DAYS} ; do + echo "Day ${PRETTY_DAY} [${COUNTER}/${DELETE_COUNT}]" + for j in ${PRETTY_DAY}/qtcreator-*-????????????-* ; do + if [[ ! -f ${j} ]]; then + continue + fi + + echo " ${j}" + if [[ "$DRY" -eq 0 ]]; then + ## Note: prefix for extra safety + rm "../snapshots/${j}" + fi + done + if [[ "$DRY" -eq 0 ]]; then + ## Note: prefix for extra safety + rmdir "../snapshots/${PRETTY_DAY}" + fi + COUNTER=$((COUNTER + 1)) + done +} + + +cleanup_snapshots +exit 0 + + +## Properly close subshell +) +exit $? diff --git a/scripts/snapshots/create_nullbyte_snapshots.sh b/scripts/snapshots/create_nullbyte_snapshots.sh new file mode 100755 index 0000000000..9099d183d2 --- /dev/null +++ b/scripts/snapshots/create_nullbyte_snapshots.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env bash + +## Open script-dir-homed subshell +( +ABS_SCRIPT_DIR=`pwd`/`dirname "$0"` +cd "${ABS_SCRIPT_DIR}" + + +print_run() { + echo "$@" + "$@" +} + +rand_range() { + incMin=$1 + incMax=$2 + echo $((RANDOM*(incMax-incMin+1)/32768+incMin)) +} + +rand_range_list() { + for ((i=0;i<$3;++i)); do + rand_range $1 $2 + done +} + + +identifiers="\ +linux-x86-setup.bin \ +linux-x86_64-setup.bin \ +linux-x86-gcc3.3-setup.bin \ +mac-setup.dmg \ +windows-setup.exe \ +" + +hour=23 +minutes=59 + +for version in 0.9 ; do +for year in $(rand_range 2007 2008) ; do +for month in $(rand_range_list 1 12 3) ; do +for day in $(rand_range_list 1 28 10) ; do + dir=`printf '%04d-%02d-%02d' ${year} ${month} ${day}` + print_run mkdir -p ${dir} + timestamp=`printf '%04d%02d%02d%02d%02d' ${year} ${month} ${day} ${hour} ${minutes}` + shared="qtcreator-${version}-${timestamp}" + for i in ${identifiers} ; do + print_run touch "${dir}/${shared}-${i}" + done +done +done +done +done +exit 0 + + +## Properly close subshell +) +exit $? |