Automatizando (ainda mais) a instalação de pacotes via apt-get
Instalar pacotes via o famoso apt-get realmente é uma facilidade imensa. Porém, as vezes instalamos uma distro no nosso HD novo, ou no computador do vizinho, e nos colocamos a lembrar quais os pacotes devemos instalar. Como todo programador preguiçoso, procurei uma maneira de automatizar esta tarefa e um jeito simples que encontrei foi fazer um script que lê um arquivo que contém nomes de pacotes, instalando no sistema somente os pacotes que ainda não estão instalados, ou também os reinstalando, caso seja desejado.
A utilização é muito simples, por exemplo:
Arquivo packs.txt
xfce4-panel-dbg xfce4-panel-dev xfce4-places-plugin xfce4-radio-plugin xfce4-screenshooter-plugin xfce4-sensors-plugin
$ sudo ./install_pkg.sh packs.txt
O script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | #!/bin/sh # # install_pkg - Easy way to install packages on debian systems # # Author: Renê de Souza Pinto # Date: January / 2008 # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # APTPAR="" PFILE=""; INSTALL=""; REINSTALL=""; if [ "$#" -lt 1 ]; then echo "install_pkg - Easy way to install packages on debian systems" echo echo "Use:" echo " $0 [-r] <package_file>" echo echo " <package_file> = Where <package_file> is a file with the packages that will be installed (listed by name)." echo " Packages already installed will NOT be re-installed." echo " -r = Install all packages from <package_file> (even for already installed packages)" echo exit 0; else if [ "$1" = "-r" ]; then APTPAR="--reinstall"; if [ -z "$2" ]; then echo "Please, provide a package file: $0 -r <package_file>" echo exit 0; else PFILE=$2; fi else PFILE=$1; fi fi # Check packages file if [ ! -f "$PFILE" ]; then echo "Cannot access $PFILE" echo exit 0; fi # Proccessing packages echo echo -n "Proccessing package file..." packs=`mktemp` dpkg -l > $packs for pkg in `cat $PFILE`; do if [ "$(cat $packs | grep $pkg 2> /dev/null | tail -1 | cut -d' ' -f1)" = "ii" ]; then if [ -n "$APTPAR" ]; then REINSTALL="$REINSTALL $pkg" fi else INSTALL="$INSTALL $pkg"; fi done rm $packs echo -e "[ \033[32mDONE\033[0m ]" echo # Execute apt commands if [ -n "$REINSTALL" ]; then apt-get install --reinstall $REINSTALL fi if [ -n "$INSTALL" ]; then apt-get install $INSTALL fi |
Baixar script
Deixe um comentário