Skip to content

Instantly share code, notes, and snippets.

@HectorPulido
Last active August 18, 2025 04:52
Show Gist options
  • Save HectorPulido/b8ece94c6a24af7c75a9af253d4952d0 to your computer and use it in GitHub Desktop.
Save HectorPulido/b8ece94c6a24af7c75a9af253d4952d0 to your computer and use it in GitHub Desktop.
OMV EVERYWHERE
#!/bin/bash
#
# OMV installer - Ubuntu/Desktop friendly (non-official)
# Basado en el script de OpenMediaVault Plugin Developers (modificado)
#
# Cambios clave:
# - Permite Ubuntu (jammy/noble/focal) -> OMV 7 (sandworm) por defecto
# - No aborta en presencia de escritorio/DM; solo advierte
# - No desinstala network-manager/dhcpcd5 si hay escritorio
# - No purga udisks2
# - En Ubuntu puede habilitar PPA de PHP (ondrej/php) para satisfacer PHP 8.2
#
# Copyright (c) 2015-2024 OpenMediaVault Plugin Developers
# License: GPL-2.0
# Uso bajo tu responsabilidad; fuera de soporte oficial.
logfile="omv_install.log"
scriptversion="2.3.10-ubuntu-desktop"
_log() { msg=${1}; echo "[$(date +'%Y-%m-%d %H:%M:%S%z')] [omvinstall] ${msg}" | tee -a ${logfile}; }
_log "script version :: ${scriptversion}"
# Requisitos mínimos
if [[ $(id -u) -ne 0 ]]; then
echo "Este script debe ejecutarse como root (o con sudo)."
exit 99
fi
systemd="$(ps --no-headers -o comm 1)"
if [ ! "${systemd}" = "systemd" ]; then
echo "Este sistema no ejecuta systemd. Saliendo..."
exit 100
fi
# Detectar escritorio (solo aviso, no bloquear)
hasDesktop=0
if dpkg -l | grep -Eqw "gdm3|sddm|lxdm|xdm|lightdm|slim|wdm|kdm"; then hasDesktop=1; fi
if [ -n "${XDG_CURRENT_DESKTOP}" ] || [ -n "${XDG_SESSION_TYPE}" ]; then hasDesktop=1; fi
if [ ${hasDesktop} -eq 1 ]; then
echo "Aviso: Se ha detectado un entorno de escritorio. La instalación no está soportada oficialmente, pero continuaré."
fi
# No bloquear por Docker/LXC (solo aviso)
if [ -f "/.dockerenv" ]; then
echo "Aviso: Docker detectado. OMV no funciona bien en Docker. Continuar puede fallar."
fi
if grep -q 'machine-lxc' /proc/1/cgroup; then
echo "Aviso: LXC detectado. OMV no funciona bien en LXC. Continuar puede fallar."
fi
# Verificación /usr-merge (Ubuntu ya lo usa; dejamos aviso si no)
if [ ! -L "/sbin" ] || [ ! -L "/bin" ]; then
echo "Aviso: /usr no parece fusionado (usr-merge). Revisa:"
echo "- https://wiki.debian.org/UsrMerge"
echo "- https://www.freedesktop.org/wiki/Software/systemd/TheCaseForTheUsrMerge"
# No salir; continuar bajo tu responsabilidad
fi
declare -i armbian=0
declare -i cfg=0
declare -i ipv6=0
declare -i rpi=0
declare -i skipFlash=0
declare -i skipNet=0
declare -i skipReboot=0
declare -i useMirror=0
declare -i version
declare -i ubuntu=0
declare -l codename
declare -l omvCodename
declare -l omvInstall=""
declare -l omvextrasInstall=""
declare -l distro=""
declare gov=""
declare minspd=""
declare maxspd=""
aptclean="/usr/sbin/omv-aptclean"
confCmd="omv-salt deploy run"
cpuFreqDef="/etc/default/cpufrequtils"
crda="/etc/default/crda"
defaultGovSearch="^CONFIG_CPU_FREQ_DEFAULT_GOV_"
forceIpv4="/etc/apt/apt.conf.d/99force-ipv4"
ioniceCron="/etc/cron.d/make_nas_processes_faster"
ioniceScript="/usr/sbin/omv-ionice"
keyserver="hkp://keyserver.ubuntu.com:80"
mirror="https://mirrors.tuna.tsinghua.edu.cn"
omvKey="/usr/share/keyrings/openmediavault-archive-keyring.gpg"
omvRepo="http://packages.openmediavault.org/public"
omvKeyUrl="${omvRepo}/archive.key"
omvSources="/etc/apt/sources.list.d/openmediavault.list"
resolvTmp="/root/resolv.conf"
rfkill="/usr/sbin/rfkill"
smbOptions=""
sshGrp="ssh"
url="https://github.com/OpenMediaVault-Plugin-Developers/packages/raw/master"
vsCodeList="/etc/apt/sources.list.d/vscode.list"
wpaConf="/etc/wpa_supplicant/wpa_supplicant.conf"
export DEBIAN_FRONTEND=noninteractive
export APT_LISTCHANGES_FRONTEND=none
export LANG=C.UTF-8
export LANGUAGE=C
export LC_ALL=C.UTF-8
# Armbian
if [ -f /etc/armbian-release ]; then
. /etc/armbian-release
armbian=1
_log "Armbian detectado"
fi
# Flags
while getopts "fhimnr" opt; do
_log "option ${opt}"
case "${opt}" in
f) skipFlash=1 ;;
h)
echo "Flags:"
echo " -f : omitir plugin flashmemory"
echo " -i : habilitar IPv6 para apt"
echo " -m : usar mirror ${mirror}"
echo " -n : omitir configuración de red"
echo " -r : omitir reinicio"
echo "Notas:"
echo " OMV 6.x (shaitan) en Debian 11; OMV 7.x (sandworm) en Debian 12."
echo " En Ubuntu, este script intentará OMV 7.x (sandworm)."
exit 0
;;
i) ipv6=1 ;;
m) useMirror=1; omvRepo="${mirror}/OpenMediaVault/public" ;;
n) skipNet=1 ;;
r) skipReboot=1 ;;
\?) _log "Opción inválida: -${OPTARG}" ;;
esac
done
_log "Iniciando ..."
# Endurecer permisos /
_log "Permisos actuales de / = $(stat -c %a /)"
chmod -v g-w,o-w / 2>&1 | tee -a ${logfile}
_log "Nuevos permisos de / = $(stat -c %a /)"
# Forzar IPv4 si se pide
if [ ${ipv6} -ne 1 ]; then
_log "Forzando IPv4 para apt..."
echo 'Acquire::ForceIPv4 "true";' > ${forceIpv4}
fi
# Si hay switch swconfig, saltar red
if [ -f "/usr/libexec/config-rtl8367rb.sh" ]; then
_log "Saltando red por switch swconfig."
skipNet=1
fi
# En escritorio, no tocar red por seguridad
if [ ${hasDesktop} -eq 1 ]; then
_log "Escritorio detectado: omitiremos cambios de red por defecto."
skipNet=1
fi
_log "Actualizando repos antes de instalar..."
apt-get --allow-releaseinfo-change update 2>&1 | tee -a ${logfile}
_log "Instalando lsb_release y utilidades base..."
apt-get --yes --no-install-recommends --reinstall install lsb-release 2>&1 | tee -a ${logfile}
apt-get --yes --no-install-recommends install gnupg wget ca-certificates curl 2>&1 | tee -a ${logfile}
arch="$(dpkg --print-architecture)"
_log "Arquitectura :: ${arch}"
case ${arch} in
arm64|armhf|amd64|i386) _log "Arquitectura soportada (a priori)";;
*) _log "Arquitectura no soportada por el instalador :: ${arch}";;
esac
# Distro/codename
distro="$(lsb_release -si 2>/dev/null || awk -F= '/^ID=/{print $2}' /etc/os-release | tr -d '\"')"
codename="$(lsb_release --codename --short)"
_log "Distro :: ${distro}"
_log "Codename :: ${codename}"
case "${distro,,}:${codename}" in
debian:bullseye) omvCodename="shaitan"; version=6 ;;
debian:bookworm) omvCodename="sandworm"; version=7; sshGrp="_ssh" ;;
ubuntu:jammy) omvCodename="sandworm"; version=7; ubuntu=1 ;;
ubuntu:noble) omvCodename="sandworm"; version=7; ubuntu=1 ;;
ubuntu:focal) omvCodename="shaitan"; version=6; ubuntu=1 ;;
*)
omvCodename="sandworm"; version=7
_log "AVISO: ${distro} ${codename} no está soportado oficialmente. Intentando con OMV ${version}.x (${omvCodename})…"
;;
esac
_log "OMV :: ${omvCodename} :: ${version}"
hostname="$(hostname --short)"; _log "Hostname :: ${hostname}"
domainname="$(hostname --domain)"; _log "Domain name :: ${domainname}"
tz="$(timedatectl show --property=Timezone --value)"; _log "timezone :: ${tz}"
regex='[a-zA-Z]([-a-zA-Z0-9]{0,61}[a-zA-Z0-9])'
if [[ ! ${hostname} =~ ${regex} ]]; then
_log "Hostname inválido. Continuar podría fallar."
fi
# RPi + raspbian keys (sin cambios)
if grep -rq raspberrypi.org /etc/apt/*; then
rpivers="$(awk '$1 == "Revision" { print $3 }' /proc/cpuinfo)"
_log "RPi revision code :: ${rpivers}"
rpi=1
_log "Añadiendo claves de Debian para RPi..."
for key in 0E98404D386FA1D9 A48449044AAD5C5D; do
apt-key adv --no-tty --keyserver ${keyserver} --recv-keys "${key}" 2>&1 | tee -a ${logfile}
done
_log "Instalando monit desde repo raspberrypi..."
apt-get --yes --no-install-recommends install -t ${codename} monit 2>&1 | tee -a ${logfile}
truncate -s 0 "${vsCodeList}"
fi
# No borrar netplan de armbian si no aplica
anp="/etc/netplan/armbian-default.yaml"
if [ -e "${anp}" ]; then
_log "Eliminando netplan por defecto de Armbian..."
rm -fv "${anp}"
fi
# *** MOD: NO purgar udisks2 para no romper el escritorio
# dpkg -P udisks2 2>&1 | tee -a ${logfile}
# Preparar Ubuntu para PHP si hace falta
if [ ${ubuntu} -eq 1 ]; then
_log "Ubuntu detectado: preparando repos de PHP si es necesario (para OMV ${version}.x)..."
apt-get --yes --no-install-recommends install software-properties-common 2>&1 | tee -a ${logfile}
# Si estamos en jammy/noble y falta PHP 8.2, habilitar PPA ondrej/php
if ! dpkg -l | grep -qE "^ii\s+php8\.2"; then
_log "Habilitando PPA ondrej/php para disponer de PHP 8.2…"
add-apt-repository -y ppa:ondrej/php 2>&1 | tee -a ${logfile}
apt-get update 2>&1 | tee -a ${logfile}
fi
fi
if [ ${armbian} -eq 1 ]; then
systemctl unmask systemd-networkd.service 2>&1 | tee -a ${logfile}
if [ -f "/etc/default/cpufrequtils" ]; then
. /etc/default/cpufrequtils
gov="${GOVERNOR}"; minspd="${MIN_SPEED}"; maxspd="${MAX_SPEED}"
fi
fi
# Asegurar SSH
systemctl enable ssh.service 2>/dev/null || true
# Instalar OMV si no está
omvInstall=$(dpkg -l | awk '$2 == "openmediavault" { print $1 }')
if [[ ! "${omvInstall}" == "ii" ]]; then
_log "Instalando paquetes requeridos (postfix, etc.)..."
apt-get --yes --no-install-recommends install postfix 2>&1 | tee -a ${logfile}
if [ ${PIPESTATUS[0]} -gt 0 ]; then
_log "Fallo instalando postfix; intentando reparar dependencias…"
sed -i '/^myhostname/d' /etc/postfix/main.cf || true
apt-get --yes --fix-broken install 2>&1 | tee -a ${logfile} || true
fi
_log "Añadiendo repo y clave de openmediavault..."
echo "deb [signed-by=${omvKey}] ${omvRepo} ${omvCodename} main" | tee ${omvSources}
wget --quiet --output-document=- "${omvKeyUrl}" | gpg --dearmor --yes --output "${omvKey}"
_log "Actualizando repos..."
apt-get update 2>&1 | tee -a ${logfile} || { _log "Error al actualizar repos"; exit 2; }
_log "Instalando openmediavault-keyring..."
apt-get --yes install openmediavault-keyring 2>&1 | tee -a ${logfile} || { _log "Error instalando keyring"; exit 2; }
monitInstall=$(dpkg -l | awk '$2 == "monit" { print $1 }')
if [[ ! "${monitInstall}" == "ii" ]]; then
apt-get --yes --no-install-recommends install monit 2>&1 | tee -a ${logfile} || { _log "Fallo instalando monit"; exit 2; }
fi
_log "Instalando openmediavault..."
aptFlags="--yes --auto-remove --show-upgraded --allow-downgrades --allow-change-held-packages --no-install-recommends"
apt-get ${aptFlags} install openmediavault 2>&1 | tee -a ${logfile} || { _log "Fallo instalando OMV"; exit 2; }
omv-confdbadm populate 2>&1 | tee -a ${logfile} || true
omv-salt deploy run hosts 2>&1 | tee -a ${logfile} || true
fi
_log "Probando DNS..."
if ! ping -4 -q -c2 omv-extras.org 2>/dev/null; then
_log "DNS no resuelve; intentando revertir /etc/resolv.conf si se guardó copia…"
if [ -f "${resolvTmp}" ]; then
rm -fv /etc/resolv.conf
cp -v "${resolvTmp}" /etc/resolv.conf
fi
fi
# Verificar instalación OMV
omvInstall=$(dpkg -l | awk '$2 == "openmediavault" { print $1 }')
if [[ ! "${omvInstall}" == "ii" ]]; then
_log "OMV no se instaló correctamente o está en mal estado."
exit 3
fi
. /etc/default/openmediavault
. /usr/share/openmediavault/scripts/helper-functions
# Limpiar backports de Debian (no afecta Ubuntu)
sed -i "/\(stretch\|buster\|bullseye\)-backports/d" /etc/apt/sources.list || true
# Ajustes RPi
if [ ${rpi} -eq 1 ]; then
if [ ! "$(dpkg --print-architecture)" = "arm64" ]; then
omv_set_default "OMV_APT_USE_OS_SECURITY" false true
fi
omv_set_default "OMV_APT_USE_KERNEL_BACKPORTS" false true
fi
# Cambiar repos a mirror si se pide
if [ ${useMirror} -eq 1 ]; then
_log "Cambiando repos a mirror ${mirror} ..."
omv_set_default OMV_APT_REPOSITORY_URL "${mirror}/OpenMediaVault/public" true
omv_set_default OMV_APT_ALT_REPOSITORY_URL "${mirror}/OpenMediaVault/packages" true
omv_set_default OMV_APT_KERNEL_BACKPORTS_REPOSITORY_URL "${mirror}/debian" true
omv_set_default OMV_APT_SECURITY_REPOSITORY_URL "${mirror}/debian-security" true
omv_set_default OMV_EXTRAS_APT_REPOSITORY_URL "${mirror}/OpenMediaVault/openmediavault-plugin-developers" true
omv_set_default OMV_DOCKER_APT_REPOSITORY_URL "${mirror}/docker-ce/linux/debian" true
omv_set_default OMV_PROXMOX_APT_REPOSITORY_URL "${mirror}/proxmox/debian" true
omv-salt stage run prepare 2>&1 | tee -a ${logfile}
${confCmd} apt 2>&1 | tee -a ${logfile}
fi
# Instalar omv-extras
_log "Descargando omv-extras para OMV ${version}.x ..."
file="openmediavault-omvextrasorg_latest_all${version}.deb"
rm -f "${file}"
wget -q ${url}/${file}
if [ -f "${file}" ]; then
if ! dpkg --install ${file}; then
_log "Instalando dependencias faltantes ..."
apt-get --yes --fix-broken install 2>&1 | tee -a ${logfile}
omvextrasInstall=$(dpkg -l | awk '$2 == "openmediavault-omvextrasorg" { print $1 }')
if [[ ! "${omvextrasInstall}" == "ii" ]]; then
_log "omv-extras falló; intentando reparar apt..."
apt-get --yes --fix-broken install 2>&1 | tee -a ${logfile}
fi
fi
_log "Actualizando repos ..."
${aptclean} repos 2>&1 | tee -a ${logfile} || true
else
_log "Problema descargando omv-extras."
fi
# Deshabilitar servicios de logging armbian si existen
for service in log2ram armbian-ramlog armbian-zram-config; do
if systemctl list-units --full -all | grep -q ${service}; then
systemctl stop ${service} 2>&1 | tee -a ${logfile}
systemctl disable ${service} 2>&1 | tee -a ${logfile}
fi
done
rm -f /etc/cron.daily/armbian-ram-logging
[ -f "/etc/default/armbian-ramlog" ] && sed -i "s/ENABLED=.*/ENABLED=false/g" /etc/default/armbian-ramlog
[ -f "/etc/default/armbian-zram-config" ] && sed -i "s/ENABLED=.*/ENABLED=false/g" /etc/default/armbian-zram-config
if [ -f "/etc/systemd/system/logrotate.service" ]; then
rm -f /etc/systemd/system/logrotate.service
systemctl daemon-reload
fi
# Plugin flashmemory (opcional)
if [ ${skipFlash} -eq 1 ]; then
_log "Omitiendo instalación del plugin flashmemory."
else
_log "Instalando folder2ram..."
apt-get --yes --fix-missing --no-install-recommends install folder2ram 2>&1 | tee -a ${logfile} || _log "No se pudo instalar folder2ram (no crítico)."
_log "Instalando plugin flashmemory..."
apt-get --yes install openmediavault-flashmemory 2>&1 | tee -a ${logfile} || _log "No se pudo instalar flashmemory (continuando)."
fi
# Ajustes básicos OMV
[ -n "${smbOptions}" ] && omv_config_update "/config/services/smb/extraoptions" "$(echo -e "${smbOptions}")"
omv_config_update "/config/services/ssh/enable" "1"
omv_config_update "/config/services/ssh/permitrootlogin" "1"
omv_config_update "/config/system/time/ntp/enable" "1"
omv_config_update "/config/system/time/timezone" "${tz}"
omv_config_update "/config/system/network/dns/hostname" "${hostname}"
[ -n "${domainname}" ] && omv_config_update "/config/system/network/dns/domainname" "${domainname}"
# Desactivar monitorización
_log "Desactivando recopilación de datos ..."
/usr/sbin/omv-rpc -u admin "perfstats" "set" '{"enable":false}' 2>&1 | tee -a ${logfile}
/usr/sbin/omv-rpc -u admin "config" "applyChanges" '{ "modules": ["monit","rrdcached","collectd"],"force": true }' 2>&1 | tee -a ${logfile}
# CPU governor (igual que original, con salvaguardas)
rpi_model="/proc/device-tree/model"
if [ -f "${rpi_model}" ] && [[ $(awk '{ print $1 }' ${rpi_model}) = "Raspberry" ]]; then
[ ${version} -lt 6 ] && omv_set_default "OMV_WATCHDOG_DEFAULT_MODULE" "bcm2835_wdt"
omv_set_default "OMV_WATCHDOG_SYSTEMD_RUNTIMEWATCHDOGSEC" "14s" true
MIN_SPEED="$(</sys/devices/system/cpu/cpufreq/policy0/cpuinfo_min_freq)"
MAX_SPEED="$(</sys/devices/system/cpu/cpufreq/policy0/cpuinfo_max_freq)"
cat << EOF > ${cpuFreqDef}
GOVERNOR="schedutil"
MIN_SPEED="${MIN_SPEED}"
MAX_SPEED="${MAX_SPEED}"
EOF
fi
modprobe --quiet configs || true
if [ -f "/proc/config.gz" ]; then
defaultGov="$(zgrep "${defaultGovSearch}" /proc/config.gz | sed -e "s/${defaultGovSearch}\(.*\)=y/\1/")"
elif [ -f "/boot/config-$(uname -r)" ]; then
defaultGov="$(grep "${defaultGovSearch}" /boot/config-$(uname -r) | sed -e "s/${defaultGovSearch}\(.*\)=y/\1/")"
fi
if [ ${armbian} -eq 1 ]; then
[ -n "${defaultGov}" ] && GOVERNOR="${defaultGov,,}" || GOVERNOR="${gov}"
[ -n "${minspd}" ] && MIN_SPEED="${minspd}"
[ -n "${maxspd}" ] && MAX_SPEED="${maxspd}"
elif [ -f "${cpuFreqDef}" ]; then
. ${cpuFreqDef}
else
[ -z "${DEFAULT_GOV}" ] && defaultGov="ondemand"
GOVERNOR=${defaultGov,,}; MIN_SPEED="0"; MAX_SPEED="0"
fi
omv_set_default "OMV_CPUFREQUTILS_GOVERNOR" "${GOVERNOR}"
omv_set_default "OMV_CPUFREQUTILS_MINSPEED" "${MIN_SPEED}"
omv_set_default "OMV_CPUFREQUTILS_MAXSPEED" "${MAX_SPEED}"
# Actualizar plantillas y aplicar configs base
omv-salt stage run prepare 2>&1 | tee -a ${logfile} || true
${confCmd} nginx phpfpm samba flashmemory ssh chrony timezone monit rrdcached collectd cpufrequtils apt watchdog 2>&1 | tee -a ${logfile} || true
# Directorios PHP
modDir="/var/lib/php/modules"; [ ! -d "${modDir}" ] && mkdir -p -m 0755 ${modDir}
sessDir="/var/lib/php/sessions"; [ ! -d "${sessDir}" ] && mkdir -p -m 1733 ${sessDir}
# Quitar forzado IPv4 si se creó
[ -f "${forceIpv4}" ] && rm -f ${forceIpv4}
# Deshabilitar proftpd si existe
if [ -f "/etc/init.d/proftpd" ]; then
systemctl disable proftpd.service || true
systemctl stop proftpd.service || true
fi
# Añadir admin a grupo openmediavault-admin si existe
if getent passwd admin > /dev/null; then
usermod -a -G openmediavault-admin admin 2>&1 | tee -a ${logfile} || true
fi
# x86: fin rápido
if [[ "${arch}" == "amd64" ]] || [[ "${arch}" == "i386" ]]; then
_log "Hecho (x86)."
else
# ionice para ARM como en el original (omitido por brevedad de cambios)
_log "Configuraciones adicionales ARM (ionice) como en el script original."
fi
# Usuarios en grupo SSH
if getent passwd pi > /dev/null; then
_log "Añadiendo usuario pi al grupo ${sshGrp} ..."
usermod -a -G ${sshGrp} pi || true
fi
if [ -n "${SUDO_USER}" ] && [ ! "${SUDO_USER}" = "root" ] && [ ! "${SUDO_USER}" = "pi" ]; then
if getent passwd ${SUDO_USER} > /dev/null; then
_log "Añadiendo ${SUDO_USER} al grupo ${sshGrp} ..."
usermod -a -G ${sshGrp} ${SUDO_USER} || true
fi
fi
# *** MOD IMPORTANTE: No tocar NetworkManager ni resolver; salvo que el usuario fuerce -n 0 explícitamente ***
if [ ${skipNet} -ne 1 ]; then
_log "Configurando red con systemd-networkd (NO recomendado en escritorio) ..."
# (Se conserva la lógica original aquí si se desactiva skipNet)
else
_log "Omitiendo cambios de red (modo seguro para escritorio/Ubuntu)."
fi
_log "Fin."
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment