#!/bin/bash -e
# -*-mode: sh; tab-width: 8; coding: utf-8-unix -*-
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

ROLE=local
MODE=all
CONN=all
BIN=/usr/local/sbin

. /usr/local/etc/local.d/local.bash || exit 1

# run this last

# BEGIN ANSIBLE MANAGED BLOCK update lati dmcrypt
if [ "$PROXY_IS_VDA" -ne 0 ] ; then
   local_host_make_dmcrypt_swap
fi
# END ANSIBLE MANAGED BLOCK update lati dmcrypt

# BEGIN ANSIBLE MANAGED BLOCK update lati scheduler
## local_host_sys_set_scheduler
local_host_sys_set_scheduler () {
    local elt
    if [ "$PROXY_IS_VDA" -ne 0 ] ; then
	for elt in b c ; do
	    [ -d /sys/block/sd$elt ] || continue
	    echo deadline > /sys/block/sd$elt/queue/scheduler
	done
    fi
    return 0
}

local_host_sys_set_scheduler
# END ANSIBLE MANAGED BLOCK update lati scheduler

# BEGIN ANSIBLE MANAGED BLOCK update lati sysrq
#   On x86 - You press the key combo ALT-SysRq-<command key>.
#   Some keyboards may not have a key labeled ?SysRq?. The ?SysRq? key is also known as the ?Print Screen? key.
#   Also some keyboards cannot handle so many keys being pressed at the same time, so you might have better
#   luck with press Alt, press SysRq, release SysRq, press <command key>, release everything.
echo 1> /proc/sys/kernel/sysrq 2>/dev/null
# END ANSIBLE MANAGED BLOCK update lati sysrq

# BEGIN ANSIBLE MANAGED BLOCK update Pentoo linux
if [ "$PROXY_IS_VDA" -ne 0 ] ; then
  local_host_symlink_usr_src
fi
# END ANSIBLE MANAGED BLOCK update Pentoo linux
## local_host_restart_intel_sound
local_host_restart_intel_sound () {
    which aplay >/dev/null 2>/dev/null || return 0

    # both
    if ! aplay -L | grep -q default:CARD=PCH ; then
	rmmod snd_hda_intel ;
	sleep 5
	modprobe snd_hda_intel enable=1 ;
	sleep 1
	aplay -L ;
    fi
    
    return 0
}

# BEGIN ANSIBLE MANAGED BLOCK update lati
#? rmmod pata_pcmcia pcmcia pcmcia_core 2>/dev/null

local_host_restart_intel_sound

# END ANSIBLE MANAGED BLOCK update lati

# BEGIN ANSIBLE MANAGED BLOCK testforge npm
[ -f  /usr/lib64/node_modules/npm/node_modules/update-notifier/check.js ] && \
  chmod 000 /usr/lib64/node_modules/npm/node_modules/update-notifier/check.js
# END ANSIBLE MANAGED BLOCK testforge npm

# BEGIN ANSIBLE MANAGED BLOCK update lati fstab
# END ANSIBLE MANAGED BLOCK update lati fstab

# BEGIN ANSIBLE MANAGED BLOCK update lati_unix.yml sysrq
#   On x86 - You press the key combo ALT-SysRq-<command key>.
#   Some keyboards may not have a key labeled ?SysRq?. The ?SysRq? key is also known as the ?Print Screen? key.
#   Also some keyboards cannot handle so many keys being pressed at the same time, so you might have better
#   luck with press Alt, press SysRq, release SysRq, press <command key>, release everything.
echo 1> /proc/sys/kernel/sysrq 2>/dev/null
# END ANSIBLE MANAGED BLOCK update lati_unix.yml sysrq
# BEGIN ANSIBLE MANAGED BLOCK update lati_unix.yml fstab
grep '/mnt/[a-z][ 	]' /etc/fstab| \
  sed -e 's@.*/mnt/@/mnt/@' -e 's/[ 	].*//' | \
    while read elt ;do
      [ -d $elt/tmp ] || mount $elt
      done
exit 0
# END ANSIBLE MANAGED BLOCK update lati_unix.yml fstab
# BEGIN ANSIBLE MANAGED BLOCK update lati_unix.yml stop
local_systemd_stop_services display-manager
# END ANSIBLE MANAGED BLOCK update lati_unix.yml stop
# BEGIN ANSIBLE MANAGED BLOCK hostvms libvirt.yml libvirtd.log
cp /dev/null /var/local/var/log/libvirtd.log
# END ANSIBLE MANAGED BLOCK hostvms libvirt.yml libvirtd.log
