#!/bin/bash
#
#
# Copyright (c) [2013-2014] Novell, Inc.  All Rights Reserved.
#
# THIS WORK IS SUBJECT TO U.S. AND INTERNATIONAL COPYRIGHT LAWS AND TREATIES.  IT
# MAY NOT BE USED, COPIED, DISTRIBUTED, DISCLOSED, ADAPTED, PERFORMED, DISPLAYED,
# COLLECTED, COMPILED, OR LINKED WITHOUT NOVELL'S PRIOR WRITTEN CONSENT.  USE OR
# EXPLOITATION OF THIS WORK WITHOUT AUTHORIZATION COULD SUBJECT THE PERPETRATOR
# TO CRIMINAL AND CIVIL LIABILITY.
#
# NOVELL PROVIDES THE WORK "AS IS," WITHOUT ANY EXPRESS OR IMPLIED WARRANTY,
# INCLUDING WITHOUT THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE, AND NON-INFRINGEMENT. NOVELL, THE AUTHORS OF THE WORK, AND
# THE OWNERS OF COPYRIGHT IN THE WORK ARE NOT LIABLE FOR ANY CLAIM, DAMAGES, OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING
# FROM, OUT OF, OR IN CONNECTION WITH THE WORK OR THE USE OR OTHER DEALINGS IN
# THE WORK.
#
# This script is executed whenever your appliance boots.  Here you can add
# commands to be executed before the system enters the first runlevel.  This
# could include loading kernel modules, starting daemons that aren't managed
# by init files, asking questions at the console, etc.
#
#

# define alias to python based on the below checks
[[ -f /usr/bin/python3 ]] && alias python=/usr/bin/python3 || { [[ -f /usr/bin/python2 ]] && alias python=/usr/bin/python2 || { [[ -f /usr/bin/python ]] && alias python=/usr/bin/python; }; }
shopt -s expand_aliases

. /.profile

if [ -f /etc/init.d/suse_studio_firstboot ]
then

# Put commands to be run on the first boot of your appliance here
 echo "Echo Begining suse-studio-custom Studio first boot script..."
 
# Import VABASE Rpm Build Keys
rpm -import /opt/novell/build-keys/VABASE-rpm.xml.key
rpm -import /opt/novell/build-keys/VABASE-repomd.xml.key 
rpm -import /opt/novell/build-keys/suse_ptf_key.asc  
 
# Create a swap (Not sure we need a swap file going forward)
#SLES11
if grep -Fxq "VERSION = 11" /etc/SuSE-release
 then
  sed -i '1i/swapfile swap swap defaults 0 0' /etc/fstab
  swapon /swapfile
fi 

# Use grub2 in SLES12
sed -i -e 's|GRUB_TIMEOUT=10|GRUB_TIMEOUT=0|' /etc/default/grub
sed -i -e 's|GRUB_HIDDEN_TIMEOUT=0|GRUB_HIDDEN_TIMEOUT=5|' /etc/default/grub
/usr/sbin/grub2-mkconfig -o /boot/grub2/grub.cfg

## Modify Grub2 settings SLES12SP2 for testing
#if [ ! -f /opt/novell/base_config/rebootOnceFlag ];
# then
##Set Grub defaults here.
 #sed -i -e 's|GRUB_CMDLINE_LINUX=""|GRUB_CMDLINE_LINUX="nomodeset"|' /etc/default/grub
 #/usr/sbin/grub2-mkconfig -o /boot/grub2/grub.cfg
 #touch /opt/novell/base_config/rebootOnceFlag
 #touch /var/lib/YaST2/reconfig_system || true
#reboot
#fi

#Call appliance specific suse_studo_custom script
python /opt/novell/base_config/execApplianceScript.py /opt/novell/va_install/suse_studio_custom


echo "Echo End suse-studio-custom Studio first boot script..."
fi



