Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- this=$(basename "$0")
- there=$(dirname "$0")
- idle='nice -n +40 chrt -i 0 ionice -c 3'
- dir_cache=/var/cache/apt/archives
- dir_lists=/var/lib/apt/lists
- f_storage=/opt/apt.lists.tar.xz
- compress='xz -C none -v'
- ratio=1
- N00B=1
- __install() { for i in ${shortcuts}; do ln -vfs ${N00B:+-i} "${this}" "${there}/$i"; done; }
- __uninstall() { for i in ${shortcuts}; do rm -vf ${N00B:+-i} "${there}/$i"; done; }
- shortcuts='a-u a-s a-r a-p'
- __help() { cat >&2 <<-EOF
- usage:
- ${this} {cmd} [args]
- {a-u|u|update}
- {a-s|s|save}
- {a-r|r|restore}
- {a-p|p|purge}
- {install}
- {uninstall}
- EOF
- exit 1; }
- __try_file() { local d=$(dirname "$1"); test \( -f "$1" -a -w "$1" \) -o \( ! -e "$1" -a -w "$d" \) ; }
- __try_dir() { test -d "$1" -a -w "$1"; }
- __test_file() { test -f "$1" -a -r "$1"; }
- __action() {
- case "$1" in
- a-u|u|update)
- exec ${idle} apt-get update
- ;;
- a-s|s|save)
- __try_file "${f_storage}" || exit 1
- f_tmp=$(mktemp)
- du -hd0 "${dir_lists}"
- tar cPf - "${dir_lists}" | ${idle} ${compress} -${ratio} > "${f_tmp}"
- cp -f "${f_tmp}" "${f_storage}"
- rm "${f_tmp}"
- ;;
- a-r|r|restore)
- __test_file "${f_storage}" || exit 1
- ls -lhgG "${f_storage}"
- ${idle} ${compress} -d < "${f_storage}" | tar xPf -
- ;;
- a-p|p|purge)
- __try_dir "${dir_lists}" || exit 1
- __try_dir "${dir_cache}" || exit 1
- find "${dir_lists}" "${dir_cache}" -mindepth 1 -delete
- ;;
- install) __install ;;
- uninstall) __uninstall ;;
- *) __help ;;
- esac
- }
- case "${this}" in
- apt.cmd) [ $# -eq 0 ] && __help; __action "$@" ;;
- *) __action "${this}" "$@" ;;
- esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement