#!/bin/bash
# -*-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.
# local_host_sys_scaling
ROLE=local
MODE=all
CONN=all
BIN=/usr/local/sbin

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

loadkeys /etc/keymaps/us.map

# BEGIN ANSIBLE MANAGED BLOCK proxy main.yml start
grep -q root=/dev/vda /proc/cmdline
PROXY_IS_VDA=$?
# END ANSIBLE MANAGED BLOCK proxy main.yml start

      if [ $PROXY_IS_VDA -eq 0 ] ; then
          :
        elif [ -n "$CHROOT" ] ; then
          :
        else
          # host
	  : 
        fi

local_host_sys_scaling () {
    local file
    
    if [ $PROXY_IS_VDA -ne 0 -a -z "$CHROOT" ] ; then
	for file in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor ; do
            echo performance >>$file
	done    
	for file in /sys/devices/system/cpu/cpu*/cpufreq/scaling_min_freq ; do
            echo 1600000 >>$file
	done    
    fi
    return 0
}

# BEGIN ANSIBLE MANAGED BLOCK proxy whonix_host.yml
local_host_sys_scaling
# END ANSIBLE MANAGED BLOCK proxy whonix_host.yml
# BEGIN ANSIBLE MANAGED BLOCK base Debian
[ -f /etc/init.d/console-setup.sh ] && \
  /etc/init.d/console-setup.sh start
# END ANSIBLE MANAGED BLOCK base Debian

local_host_restart_psmouse
local_host_restart_intel_sound

if [ "$PROXY_IS_VDA" -ne 0 ] ; then
  local_manual_stop_services redis postgresql-11
fi
# BEGIN ANSIBLE MANAGED BLOCK base Debian
/etc/init.d/console-setup.sh start
# END ANSIBLE MANAGED BLOCK base Debian
mount /mnt/o
mount /mnt/i
mount /mnt/j
mount /mnt/e
mount /mnt/q
mount /mnt/w

exit 0
# BEGIN ANSIBLE MANAGED BLOCK update lati_unix.yml sound
( cd /var/tmp && rm -rf ansible-local-* Temp-* ssh-* pulse-* .xfsm-ICE-* )
ls /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor 2>/dev/null >/dev/null && \
for file in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor ; do
    echo performance >>$file
  done
for file in /sys/devices/system/cpu/cpu*/cpufreq/scaling_min_freq ; do
    echo 1600000 >>$file
  done
[ -e /usr/share/netsurf/DejaVuSans.ttf ] || \
    sudo ln -s /usr/share/fonts/truetype/dejavu/DejaVuSans.ttf /usr/share/netsurf
true
# END ANSIBLE MANAGED BLOCK update lati_unix.yml sound
# 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 dmcrypt
grep -q root=/dev/vda /proc/cmdline ; PROXY_IS_VDA=$?
if [ "$PROXY_IS_VDA" -ne 0 ] ; then
  local_host_make_dmcrypt_swap
fi
exit 0
# END ANSIBLE MANAGED BLOCK update lati_unix.yml dmcrypt
# BEGIN ANSIBLE MANAGED BLOCK update lati_unix.yml fstab
for elt in h i j o q w l ; do
    [ -d /mnt/$elt/tmp ] || mount /mnt/$elt
  done
# END ANSIBLE MANAGED BLOCK update lati_unix.yml fstab
# BEGIN ANSIBLE MANAGED BLOCK update lati_unix.yml scheduler
for elt in b c ; do
    [ -d /sys/block/sd$elt ] || continue
    echo deadline > /sys/block/sd$elt/queue/scheduler
done
# END ANSIBLE MANAGED BLOCK update lati_unix.yml scheduler
# BEGIN ANSIBLE MANAGED BLOCK base initctl
[ ! -e /dev/initctl -a -e /run/initctl ] && ln -s /run/initctl /dev/initctl && exit 0
[ ! -e /dev/initctl ] || mknod -m=0600 /dev/initctl p
# END ANSIBLE MANAGED BLOCK base initctl
# BEGIN ANSIBLE MANAGED BLOCK testforge npm
[ -f  /usr/lib/node_modules/npm/node_modules/update-notifier/check.js ] && \
  chmod 000 /usr/lib/node_modules/npm/node_modules/update-notifier/check.js
# END ANSIBLE MANAGED BLOCK testforge npm
# BEGIN ANSIBLE MANAGED BLOCK update Pentoo linux
dir=`cat /proc/cmdline|sed -e 's/BOOT_IMAGE=kernel-pentoo-x86_64/linux/' -e 's/_.*//'`
pushd /usr/src
rm -f linux
[ -d $dir ] && ln -s $dir linux || echo WARN: $PWD/$dir not found
popd

# END ANSIBLE MANAGED BLOCK update Pentoo linux

which brightnessctl 2>/dev/null >/dev/null && brightnessctl -c backlight set 95%

local_neuter_gvfs
local_link_linux
local_null_machineid

pkill gvfs

loadkeys /etc/keymaps/us.map
