Advertisement
zefie

apt-build-tools v0.3-debian7

Jan 10th, 2014
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.86 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. function fancy-timer() {
  4.         for (( i=1; i<=$1; i++ )); do
  5.             SEC=$(expr ${1} - $(expr ${i} - 1))
  6.             SECW="second"
  7.             if [ "$SEC" -ne "1" ]; then
  8.                 SECW="${SECW}s"
  9.             fi
  10.             LINE="$2 ${SEC} ${SECW}"
  11.             SPC=$(expr $(tput cols) - ${#LINE})
  12.             for (( j=1; j<=$SPC; j++ )); do
  13.                 echo -n " ";
  14.             done;
  15.             echo -ne "${LINE}\r"
  16.             sleep 1
  17.         done;
  18. }
  19.  
  20. function check-blacklist() {
  21.     grep -v "apt-utils"
  22. }
  23. function list1() {
  24.     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 }'
  25. }
  26.  
  27. function list2() {
  28.     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 }';
  29. }
  30.  
  31. function list2-nodev() {
  32.     list2 | grep -v "\-dev"
  33. }
  34.  
  35. function list-nonopt() {
  36.     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/|/ /'
  37. }
  38.  
  39. function list-nonopt-fmt() {
  40.     list-nonopt | awk '{ printf " * %s-%s\n", $1, $2}';
  41. }
  42.  
  43. function list-nonopt-list() {
  44.     list-nonopt | cut -d' ' -f1
  45. }
  46.  
  47. function list-all() {
  48.     dpkg --list | grep "ii  " | check-blacklist | grep -v "gcc" | grep -v "g++" | grep -v "\-dev"
  49. }
  50.  
  51. function update-repo() {
  52.     sudo apt-get update -o Dir::Etc::sourcelist="sources.list.d/$1" \
  53.     -o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0"
  54. }
  55.  
  56. function update-aptbuild-repo() {
  57.     update-repo apt-build.list
  58. }
  59.  
  60. function count-packages() {
  61.     TOT=$(list-all | wc -l)
  62.     OPT=$(list2-nodev | wc -l)
  63.     OP2=$(list2 | wc -l)
  64.     NON=$(list-nonopt | wc -l)
  65.     TES=$(expr ${OPT} + ${NON})
  66.     EXP="?"
  67.  
  68.     if [ "$TOT" -eq "$TES" ]; then
  69.         EXP=$(echo -e \\u2713)
  70.     else
  71.         if [ "$TOT" -gt "$TES" ]; then
  72.             EXP="${EXP} -$(expr ${TOT} - ${TES})"
  73.         else
  74.             EXP="${EXP} +$(expr ${TES} - ${TOT})"
  75.         fi
  76.     fi
  77.  
  78.     if [ "$OP2" -gt "$OPT" ]; then
  79.         EXP="${EXP} (+$(expr $OP2 - $OPT) dev)"
  80.     fi
  81.  
  82.     echo "${OPT} optimized, ${NON} optimizable, ${TOT} total (${EXP})"
  83. }
  84.  
  85. function reb-status() {
  86.     while (true); do
  87.         clear;
  88.         echo "* `date`";
  89.         USED=$(df -m / | tail -n 1 | sed -e 's/  */ /g;' | cut -d' ' -f 3)M
  90.         FREE=$(df -h / | tail -n 1 | sed -e 's/  */ /g;' | cut -d' ' -f 4)
  91.         MEMU=$(free -m | head -n 2 | tail -n 1 | sed -e 's/  */ /g;' | cut -d' ' -f3)
  92.         MEMT=$(free -m | head -n 2 | tail -n 1 | sed -e 's/  */ /g;' | cut -d' ' -f2)
  93.         SWPU=$(free -m | tail -n 1 | sed -e 's/  */ /g;' | cut -d' ' -f3)
  94.         SWPT=$(free -m | tail -n 1 | sed -e 's/  */ /g;' | cut -d' ' -f2)
  95.         PROC=$(expr $(ps aux | wc -l) - 1)
  96.         echo ""
  97.         echo "Memory: ${MEMU}/${MEMT}M (${SWPU}/${SWPT}M Swap)"
  98.         echo "Running Processes: ${PROC}"
  99.         echo "Disk space: Used ${USED} of ${FREE}";
  100.         count-packages
  101.         fancy-timer 30 "Next update in"
  102.     done;
  103. }
  104.  
  105. function help() {
  106.     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] [<pkg to build/install>]"
  107.     exit
  108. }
  109.  
  110. function ipkg() {
  111.     PKG=$(ls -1 `cat /etc/apt/apt-build.conf  | grep repository | cut -d'=' -f2`/${1}* | sort -r | uniq | head -n 1)
  112.     sudo dpkg -i ${PKG}
  113. }
  114.  
  115. function genworldlist() {
  116.     dpkg --get-selections | grep -v gcc | grep -v g\+\+ | awk '{if ($2 == "install") print $1}'
  117. }
  118.  
  119. case $1 in
  120.     "up")
  121.     sudo apt-get upgrade
  122.     ;;
  123.  
  124.     "u")
  125.     update-aptbuild-repo
  126.     ;;
  127.  
  128.     "l")
  129.     list2
  130.     ;;
  131.  
  132.     "o")
  133.     list2
  134.     ;;
  135.  
  136.     "c")
  137.     count-packages
  138.     ;;
  139.  
  140.     "n")
  141.     list-nonopt-fmt
  142.     ;;
  143.  
  144.     "nf")
  145.     list-nonopt-fmt
  146.     ;;
  147.  
  148.     "nl")
  149.     list-nonopt-list
  150.     ;;
  151.  
  152.     "nr")
  153.     list-nonopt
  154.     ;;
  155.  
  156.     "w")
  157.     genworldlist
  158.     ;;
  159.  
  160.     "s")
  161.     reb-status
  162.     ;;
  163.  
  164.     "a")
  165.     list1
  166.     ;;
  167.  
  168.     "i")
  169.     ipkg ${2}
  170.     ;;
  171.  
  172.     "ia")
  173.     sudo dpkg -i /var/cache/apt-build/repository/*.deb
  174.     ;;
  175.  
  176.     "b")
  177.     sudo apt-build --noupdate build-source ${2}
  178.     ;;
  179.  
  180.     *)
  181.     help
  182.     ;;
  183. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement