#!/bin/bash function fancy-timer() { for (( i=1; i<=$1; i++ )); do SEC=$(expr ${1} - $(expr ${i} - 1)) SECW="second" if [ "$SEC" -ne "1" ]; then SECW="${SECW}s" fi LINE="$2 ${SEC} ${SECW}" SPC=$(expr $(tput cols) - ${#LINE}) for (( j=1; j<=$SPC; j++ )); do echo -n " "; done; echo -ne "${LINE}\r" sleep 1 done; } function check-blacklist() { grep -v "apt-utils" } function list1() { find `cat /etc/apt/apt-build.conf | grep repository | cut -d'=' -f2` -name *.deb | rev | cut -d'/' -f 1 | rev | cut -d'+' -f 1 | sort | uniq | awk '{ printf " * %s\n", $1 }' } function list2() { dpkg --list | grep "ii " | check-blacklist | grep aptbuild[0-9] | sed -e 's/ */\|/g' | cut -d'|' -f2-3 | sed -e 's/|/ /' | cut -d'+' -f1 | awk '{ printf " * %s-%s\n", $1, $2 }'; } function list2-nodev() { list2 | grep -v "\-dev" } function list-nonopt() { dpkg --list | grep "ii " | check-blacklist | grep -v "gcc" | grep -v "g++" | grep -v "\-dev" | grep -v aptbuild[0-9] | sed -e 's/ */\|/g' | cut -d'|' -f2-3 | sed -e 's/|/ /' } function list-nonopt-fmt() { list-nonopt | awk '{ printf " * %s-%s\n", $1, $2}'; } function list-nonopt-list() { list-nonopt | cut -d' ' -f1 } function list-all() { dpkg --list | grep "ii " | check-blacklist | grep -v "gcc" | grep -v "g++" | grep -v "\-dev" } function update-repo() { sudo apt-get update -o Dir::Etc::sourcelist="sources.list.d/$1" \ -o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0" } function update-aptbuild-repo() { update-repo apt-build.list } function count-packages() { TOT=$(list-all | wc -l) OPT=$(list2-nodev | wc -l) OP2=$(list2 | wc -l) NON=$(list-nonopt | wc -l) TES=$(expr ${OPT} + ${NON}) EXP="?" if [ "$TOT" -eq "$TES" ]; then EXP=$(echo -e \\u2713) else if [ "$TOT" -gt "$TES" ]; then EXP="${EXP} -$(expr ${TOT} - ${TES})" else EXP="${EXP} +$(expr ${TES} - ${TOT})" fi fi if [ "$OP2" -gt "$OPT" ]; then EXP="${EXP} (+$(expr $OP2 - $OPT) dev)" fi echo "${OPT} optimized, ${NON} optimizable, ${TOT} total (${EXP})" } function reb-status() { while (true); do clear; echo "* `date`"; USED=$(df -m / | tail -n 1 | sed -e 's/ */ /g;' | cut -d' ' -f 3)M FREE=$(df -h / | tail -n 1 | sed -e 's/ */ /g;' | cut -d' ' -f 4) MEMU=$(free -m | head -n 2 | tail -n 1 | sed -e 's/ */ /g;' | cut -d' ' -f3) MEMT=$(free -m | head -n 2 | tail -n 1 | sed -e 's/ */ /g;' | cut -d' ' -f2) SWPU=$(free -m | tail -n 1 | sed -e 's/ */ /g;' | cut -d' ' -f3) SWPT=$(free -m | tail -n 1 | sed -e 's/ */ /g;' | cut -d' ' -f2) PROC=$(expr $(ps aux | wc -l) - 1) echo "" echo "Memory: ${MEMU}/${MEMT}M (${SWPU}/${SWPT}M Swap)" echo "Running Processes: ${PROC}" echo "Disk space: Used ${USED} of ${FREE}"; count-packages fancy-timer 30 "Next update in" done; } function help() { echo "Usage: $0 [(u)pdate, (up)grade, (l)ist installed, (a)vailable, (i)nstall, (b)uild, (s)tatus, (n)ot-optimized, (w)orldlist, (c)ount] []" exit } function ipkg() { PKG=$(ls -1 `cat /etc/apt/apt-build.conf | grep repository | cut -d'=' -f2`/${1}* | sort -r | uniq | head -n 1) sudo dpkg -i ${PKG} } function genworldlist() { dpkg --get-selections | grep -v gcc | grep -v g\+\+ | awk '{if ($2 == "install") print $1}' } case $1 in "up") sudo apt-get upgrade ;; "u") update-aptbuild-repo ;; "l") list2 ;; "o") list2 ;; "c") count-packages ;; "n") list-nonopt-fmt ;; "nf") list-nonopt-fmt ;; "nl") list-nonopt-list ;; "nr") list-nonopt ;; "w") genworldlist ;; "s") reb-status ;; "a") list1 ;; "i") ipkg ${2} ;; "ia") sudo dpkg -i /var/cache/apt-build/repository/*.deb ;; "b") sudo apt-build --noupdate build-source ${2} ;; *) help ;; esac