runit-fstab-generator

Publicado por Perfil removido (última atualização em 20/06/2017)

[ Hits: 1.572 ]

Download runit-fstab-generator




Faz parsing do /etc/fstab e produz scripts pra montar as partições encontradas.

- ignora a partição root.
- ignora partições que tem noauto nas opções.
- cria os arquivos em /run/runit/rc.d/mount-$local_onde_e_montado.rc
- faz uso do lodewijk para garantir paralelização da montagem das partições.
- cria arquivo mounts.target em /run/runit/rc.d , que pode ser usado para rodar todos os scripts gerados

  



Esconder código-fonte

#!/bin/sh
#
# Convert fstab entries into run files for mount
# depends on lodewijk and can't define dependencies
# it requires the dir /run/rc.d to be created and writable
# 
# files created:
# /run/runit/rc.d/mounts.target --> this is a script that keeps a list
# of mounts and executes them with lodewijk
# /run/runit/rc.d/$mount.rc --> this is a run file for a mount, the
# name is mount-[basename of path on fstab].rc
# mount.rc files that are not on tmpfs automatically depend on
# mount-rw.rc

[ "$(id -u)" != "0" ] && exit 128

set -eu

create_run() {
  (
    printf "%s\\n%s\\n\\n" "#!/bin/sh" "set -eu"
    
    if [ "$1" != "tmpfs" ]; then
      printf "%s\\n\\n" "lodewijk mount-rw.rc"
    fi

    printf "%s\\n" "echo \"mounting $2 ...\""

    printf "%s" "exec mount "
    if [ "$1" = "tmpfs" ]; then
      printf "%s" "-t $1 "
    fi
    if [ ! -z "$4" ]; then
      printf "%s" "-o $4 "
    fi

    if [ "$1" != "tmpfs" ]; then
      printf "%s" "$1 "
    fi

    printf "%s\\n" "$2"
    ) > /run/runit/rc.d/mount-"$(echo $2 | grep -o '[^/]*$').rc" 
    chmod +x /run/runit/rc.d/mount-"$(echo $2 | grep -o '[^/]*$').rc"
}

printf "%s\\n%s\\n\\n" "#!/bin/sh" "set -eu" > /run/runit/rc.d/mounts.target
chmod +x /run/runit/rc.d/mounts.target

grep -v '^#' < /etc/fstab | while IFS= read -r mount; do
  # Separate each arg into it's own
  disk="$(echo $mount|cut -d' ' -f1)"
  location="$(echo $mount|cut -d' ' -f2)"
  filesystem="$(echo $mount|cut -d' ' -f3)"

  # If the fstab mentions no auto, then we don't generate a run unit to mount
  opts="$(echo $mount|cut -d' ' -f4)"
  if (echo $opts | grep -q noauto); then
    continue
  fi

  # We don't want to remount the root partition
  [ "$location" = "/" ] && continue

  # We now call a function to create a run file
  create_run "$disk" "$location" "$filesystem" "$opts"

  # We add it to mounts.target
  printf "%s\\n" "lodewijk mount-$(echo $location | grep -o '[^/]*$').rc" >> /run/runit/rc.d/mounts.target
done 

Scripts recomendados

Pegando seu IP e Hostname com um unico comando.

Configurar gateway e servidor DNS com dialog

newchangelog - Script para gerar changelog.

Atualizando KDE 3x para KDE4.1 no Slackware 12

Script para carregar e descarregar regras com iptables


  

Comentários

Nenhum comentário foi encontrado.


Contribuir com comentário




Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts