Skip to content

Commit

Permalink
Apache integration with macos
Browse files Browse the repository at this point in the history
  • Loading branch information
raupulus committed Jul 21, 2022
1 parent f7a2514 commit 7ed1781
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 69 deletions.
1 change: 1 addition & 0 deletions Software-Lists/macos/servers/apache2.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
httpd
102 changes: 67 additions & 35 deletions functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,19 @@ opciones() {
## @param $* String Nombre de programas a instalar
##
instalarSoftware() {
if [[ "$MY_DISTRO" = 'debian' ]] || [[ "$MY_DISTRO" = 'raspbian' ]]; then
if [[ "$DISTRO" = 'debian' ]] || [[ "$DISTRO" = 'raspbian' ]]; then
for programa in $*; do
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y "$programa"
done
elif [[ "$MY_DISTRO" = 'gentoo' ]]; then
elif [[ "$DISTRO" = 'gentoo' ]]; then
for programa in $*; do
sudo emerge "$programa"
done
elif [[ "$MY_DISTRO" = 'fedora' ]]; then
elif [[ "$DISTRO" = 'fedora' ]]; then
for programa in $*; do
sudo dnf install -y "$programa"
done
elif [[ "$MY_DISTRO" = 'macos' ]]; then
elif [[ "$DISTRO" = 'macos' ]]; then
for programa in $*; do
brew install "$programa"
done
Expand All @@ -84,19 +84,19 @@ instalarSoftware() {
## @param $* String Nombres de programas para ser actualizados
##
actualizarSoftware() {
if [[ "$MY_DISTRO" = 'debian' ]] || [[ "$MY_DISTRO" = 'raspbian' ]]; then
if [[ "$DISTRO" = 'debian' ]] || [[ "$DISTRO" = 'raspbian' ]]; then
for programa in $*; do
sudo DEBIAN_FRONTEND=noninteractive apt-get upgrade -y "$programa"
done
elif [[ "$MY_DISTRO" = 'gentoo' ]]; then
elif [[ "$DISTRO" = 'gentoo' ]]; then
for programa in $*; do
sudo emerge -vDuN "$programa"
done
elif [[ "$MY_DISTRO" = 'fedora' ]]; then
elif [[ "$DISTRO" = 'fedora' ]]; then
for programa in $*; do
sudo dnf upgrade -y "$programa"
done
elif [[ "$MY_DISTRO" = 'macos' ]]; then
elif [[ "$DISTRO" = 'macos' ]]; then
for programa in $*; do
brew upgrade "$programa"
done
Expand Down Expand Up @@ -131,7 +131,7 @@ instalarSoftwareLista() {

lista_Software=$(cat $1)

if [[ "$MY_DISTRO" = 'debian' ]] || [[ "$MY_DISTRO" = 'raspbian' ]]; then
if [[ "$DISTRO" = 'debian' ]] || [[ "$DISTRO" = 'raspbian' ]]; then
## Paquetes a instalar
## La siguiente variable guarda toda la lista de paquetes desde DPKG
local lista_todos_paquetes=(${dpkg-query -W -f='${Installed-Size} ${Package}\n' | sort -n | cut -d" " -f2})
Expand All @@ -149,18 +149,18 @@ instalarSoftwareLista() {
fi
done
done
elif [[ "$MY_DISTRO" = 'gentoo' ]]; then
elif [[ "$DISTRO" = 'gentoo' ]]; then
for x in "${lista_Software[@]}"; do
instalarSoftware "$x"
done
elif [[ "$MY_DISTRO" = 'fedora' ]]; then
elif [[ "$DISTRO" = 'fedora' ]]; then
for x in "${lista_Software[@]}"; do
instalarSoftware "$x"
done
elif [[ "$DISTRO" = 'macos' ]]; then
for x in "${lista_Software[@]}"; do
instalarSoftware "$x"
done
elif [[ "$MY_DISTRO" = 'macos' ]]; then
for x in "${lista_Software[@]}"; do
instalarSoftware "$x"
done
fi

repararGestorPaquetes
Expand All @@ -184,13 +184,13 @@ repararGestorPaquetes() {
##
actualizarRepositorios() {
echo -e "$VE Actualizando listas de$RO Repositorios$VE (Paciencia)$CL"
if [[ "$MY_DISTRO" = 'debian' ]] || [[ "$MY_DISTRO" = 'raspbian' ]]; then
if [[ "$DISTRO" = 'debian' ]] || [[ "$DISTRO" = 'raspbian' ]]; then
sudo DEBIAN_FRONTEND=noninteractive apt-get update
elif [[ "$MY_DISTRO" = 'gentoo' ]]; then
elif [[ "$DISTRO" = 'gentoo' ]]; then
sudo emerge --sync
elif [[ "$MY_DISTRO" = 'fedora' ]]; then
elif [[ "$DISTRO" = 'fedora' ]]; then
sudo dnf update
elif [[ "$MY_DISTRO" = 'fedora' ]]; then
elif [[ "$DISTRO" = 'macos' ]]; then
brew update
fi
}
Expand All @@ -201,7 +201,7 @@ actualizarRepositorios() {
## @param $* String Nombres de programas para ser instalados
##
instalarSoftwareFlatPak() {
if [[ ! -x '/usr/bin/flatpak' ]]; then
if [[ ! -x '/usr/bin/flatpak' ]] || [[ $DISTRO = 'macos' ]]; then
instalarSoftware 'flatpak'
fi

Expand Down Expand Up @@ -231,7 +231,7 @@ instalarSoftwareFlatPak() {
## @param $1 String Ruta del archivo lista con los paquetes
instalarSoftwareFlatPakLista() {
## Paquetes a instalar
if [[ $1 = '' ]]; then
if [[ $1 = '' ]] || [[ $DISTRO = 'macos' ]]; then
echo -e "$VE No hay paquete a instalar$CL"
return 1
fi
Expand Down Expand Up @@ -361,40 +361,65 @@ enlazarHome() {
## @param $* Recibe los paquetes que necesite y los borra
##
desinstalar_paquetes() {
for x in $*; do
echo -e "$RO Borrando x$CL"
sudo DEBIAN_FRONTEND=noninteractive apt-get purge -y x
done
if [[ $DISTRO = 'macos' ]]; then
for x in $*; do
echo -e "$RO Borrando x$CL"
brew remove "${x}"
done
else
for x in $*; do
echo -e "$RO Borrando x$CL"
sudo DEBIAN_FRONTEND=noninteractive apt-get purge -y x
done
fi
}

##
## Recibe uno o más nombres de servicios para reiniciarlos
## @param $* Recibe los servicios que necesite reiniciar
##
reiniciarServicio() {
for x in $*; do
echo -e "$RO Reiniciando $x$CL"
sudo systemctl restart "$x"
done

if [[ $DISTRO = 'macos' ]]; then
for x in $*; do
echo -e "$RO Reiniciando $x$CL"
brew services restart "${x}"
done
else
for x in $*; do
echo -e "$RO Reiniciando $x$CL"
sudo systemctl restart "$x"
done
fi
}

##
## Recibe uno o más nombres de servicios para detenerlos.
##
pararServicio() {
for x in $*; do
echo -e "$RO Deteniendo Servicio: $x$CL"
sudo systemctl stop "$x"
done
if [[ $DISTRO = 'macos' ]]; then
for x in $*; do
echo -e "$RO Deteniendo Servicio: $x$CL"
brew services stop "${x}"
done
else
for x in $*; do
echo -e "$RO Deteniendo Servicio: $x$CL"
sudo systemctl stop "$x"
done
fi
}

##
## Actualiza la lista de repositorios y repara fallos en el si los hubiese
##
prepararInstalador() {
echo -e "$VE Se actualizarán las$RO listas de repositorios$CL"
sudo DEBIAN_FRONTEND=noninteractive apt-get update
sudo DEBIAN_FRONTEND=noninteractive apt-get install -f -y

if [[ $DISTRO = 'debian' ]] || [[ $DISTRO = 'raspbian' ]];then
sudo DEBIAN_FRONTEND=noninteractive apt-get update
sudo DEBIAN_FRONTEND=noninteractive apt-get install -f -y
fi
}

##
Expand Down Expand Up @@ -441,6 +466,7 @@ setVariableGlobal() {
##
python2Install() {
echo -e "$VE Instalando paquete Python$CL"

for x in $*; do
echo -e "$RO Instalando $x$CL"
pip2 install --user --upgrade "$x"
Expand All @@ -453,6 +479,7 @@ python2Install() {
##
python3Install() {
echo -e "$VE Instalando paquete Python$CL"

for x in $*; do
echo -e "$RO Instalando $x$CL"
pip3 install --user --upgrade "$x"
Expand All @@ -465,6 +492,7 @@ python3Install() {
##
python3InstallGlobal() {
echo -e "$VE Instalando paquete Python de forma global$CL"

for x in $*; do
echo -e "$RO Instalando $x$CL"
sudo pip3 install --upgrade "$x"
Expand All @@ -479,6 +507,7 @@ dir_exist_or_create() {
dir="$1"

echo -e "$VE Creando directorio$RO $dir$CL"

if [[ ! -d "$dir" ]]; then
mkdir -p "$dir"
fi
Expand Down Expand Up @@ -510,6 +539,9 @@ clear_screen() {
## @param $* String Nombres de scripts dentro de conf/bin/ sin la extensión.
##
addScriptToBin() {

// TODO: Revisar si en macos, esto cambiará de ruta

for script in $*; do
sudo cp "${WORKSCRIPT}/conf/bin/${script}.sh" "/bin/${script}"
sudo chmod 755 -R "/bin/${script}"
Expand Down
11 changes: 10 additions & 1 deletion routes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,16 @@ routesApache2() {
elif [[ "$DISTRO" = 'gentoo' ]]; then
echo -e "$VE Configurando directorios apache para $DISTRO$CL"
elif [[ "$DISTRO" = 'macos' ]]; then
echo -e "$VE Configurando directorios apache para $DISTRO$CL"
echo -e "$VE Configurando directorios apache para $DISTRO$CL"
APACHECONF='/opt/homebrew/etc/httpd'
DIRWEBLOG='/var/log/apache2'
DIRWEB="/opt/homebrew/opt/httpd"
APACHESITES="${APACHECONF}/vhosts.conf"
APACHESITESENABLED=""
APACHEPORTSCONF="${APACHECONF}/ports.conf"
APACHEAPACHE2CONF="${APACHECONF}/httpd.conf"
APACHEMODS=""
APACHEMODSENABLED=""
else
echo -e "$VE No se puede configurar rutas de apache$CL"
exit 1
Expand Down
17 changes: 13 additions & 4 deletions servers/apache2/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
apache2LimpiarSites() {
pararServicio 'apache2'

echo -e "$VE Cuidado, esto puede$RO BORRAR$VE algo valioso$RO"
echo -e "$VE Cuidado, esto puede$RO BORRAR$VE algo valioso$RO$CL"
read -p " ¿Quieres borrar todo el directorio ${DIRWEB}/* s/N → " input

if [[ "$input" = 's' ]] || [[ "$input" = 'S' ]]; then
Expand Down Expand Up @@ -146,6 +146,7 @@ apache2ActivarHost() {
if [[ ! -f '/etc/hosts.local' ]]; then
sudo touch '/etc/hosts.local'
fi

echo "127.0.0.1 ${sitioWeb}.local" | sudo tee -a '/etc/hosts.local'
fi
}
Expand Down Expand Up @@ -188,19 +189,23 @@ apache2AsignarPermisos() {
## $* Lista de módulos
##
apache2HabilitarModulo() {
if [[ "$MY_DISTRO" = 'debian' ]] || [[ "$MY_DISTRO" = 'raspbian' ]]; then
if [[ "$DISTRO" = 'debian' ]] || [[ "$DISTRO" = 'raspbian' ]]; then
for modulo in $*; do
echo -e "$VE Activando módulo:$RO $modulo$CL"
sudo a2enmod $modulo
done
elif [[ "$MY_DISTRO" = 'gentoo' ]]; then
elif [[ "$DISTRO" = 'gentoo' ]]; then
for modulo in $*; do
echo "no implementado en gentoo"
done
elif [[ "$MY_DISTRO" = 'fedora' ]]; then
elif [[ "$DISTRO" = 'fedora' ]]; then
for modulo in $*; do
echo "no implementado en fedora"
done
elif [[ "$DISTRO" = 'macos' ]]; then
for modulo in $*; do
echo "No necesario en macos, se habilita en configuracion httpd.conf"
done
fi
}

Expand All @@ -222,6 +227,10 @@ apache2DeshabilitarModulo() {
for modulo in $*; do
echo "no implementado en fedora"
done
elif [[ "$DISTRO" = 'macos' ]]; then
for modulo in $*; do
echo "No necesario en macos"
done
fi
}

Expand Down
Loading

0 comments on commit 7ed1781

Please sign in to comment.