Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

347
Views
Un script bash universal para instalar con apt-get y yum

Estoy tratando de escribir un contenedor bash simple que resuma yum y apt-get . Básicamente, podemos hacer algo como universal-install curl Esto es lo que tengo hasta ahora:

 # universal-install package=$1 apt=`command -v apt-get` yum=`command -v yum` if [ -n "$apt" ]; then apt-get update apt-get -y install $package elif [ -n "$yum" ]; then yum -y install $package else echo "Err: no path to apt-get or yum" >&2; exit 1; fi

¿Hay algún error o mejora/optimización que se pueda hacer?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Eche un vistazo a cómo pacapt detecta el sistema operativo :

 # Detect package type from /etc/issue _found_arch() { local _ostype="$1" shift grep -qis "$*" /etc/issue && _OSTYPE="$_ostype" } # Detect package type _OSTYPE_detect() { _found_arch PACMAN "Arch Linux" && return _found_arch DPKG "Debian GNU/Linux" && return _found_arch DPKG "Ubuntu" && return _found_arch YUM "CentOS" && return _found_arch YUM "Red Hat" && return _found_arch YUM "Fedora" && return _found_arch ZYPPER "SUSE" && return [[ -z "$_OSTYPE" ]] || return # See also https://github.com/icy/pacapt/pull/22 # Please not that $OSTYPE (which is `linux-gnu` on Linux system) # is not our $_OSTYPE. The choice is not very good because # a typo can just break the logic of the program. if [[ "$OSTYPE" != "darwin"* ]]; then _error "Can't detect OS type from /etc/issue. Running fallback method." fi [[ -x "/usr/bin/pacman" ]] && _OSTYPE="PACMAN" && return [[ -x "/usr/bin/apt-get" ]] && _OSTYPE="DPKG" && return [[ -x "/usr/bin/yum" ]] && _OSTYPE="YUM" && return [[ -x "/opt/local/bin/port" ]] && _OSTYPE="MACPORTS" && return command -v brew >/dev/null && _OSTYPE="HOMEBREW" && return [[ -x "/usr/bin/emerge" ]] && _OSTYPE="PORTAGE" && return [[ -x "/usr/bin/zypper" ]] && _OSTYPE="ZYPPER" && return if [[ -z "$_OSTYPE" ]]; then _error "No supported package manager installed on system" _error "(supported: apt, homebrew, pacman, portage, yum)" exit 1 fi }

Como puede ver, primero verifica /etc/issue y luego, en su defecto, el script busca el archivo ejecutable asociado para cada administrador de paquetes.

Pero diablos, ¿por qué no usar pacapt en lugar de rodar el tuyo?

over 4 years ago · Santiago Trujillo Report

0

Si va a hacer esto, ¿por qué requerir que el usuario le diga al script qué herramienta usar?

 #!/bin/bash # Find our package manager if VERB="$( which apt-get )" 2> /dev/null; then echo "Debian-based" elif VERB="$( which yum )" 2> /dev/null; then echo "Modern Red Hat-based" elif VERB="$( which portage )" 2> /dev/null; then echo "Gentoo-based" elif VERB="$( which pacman )" 2> /dev/null; then echo "Arch-based" else echo "I have no idea what I'm doing." >&2 exit 1 fi if [[ 1 -ne $# ]]; then echo "Syntax: $0 PACKAGE" exit 1 fi $VERB "$1" exit $?

Un poco mejor sería mirar /etc/issue para ver cuál es su distribución y comportarse en consecuencia.

over 4 years ago · Santiago Trujillo Report

0

Estaba buscando una sola línea para instalar un paquete y no pude encontrar ninguno, así que esta fue mi versión final:

 if [ "" == "`which unzip`" ]; then echo "Unzip Not Found"; if [ -n "`which apt-get`" ]; then apt-get -y install unzip ; elif [ -n "`which yum`" ]; then yum -y install unzip ; fi ; fi

Es específico para el paquete de unzip , pero se puede modificar a cualquier otro paquete que esté disponible en apt-get/yum.

Espero que esto ayude a alguien :)

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!