#!/bin/sh
# name    : Frenzy rc script
# version : 0.3 (29.04.2006)
# author  : Mozhaisky Sergei (technix@frenzy.org.ua)

PATH=:/sbin:/bin:/usr/bin:/usr/sbin
export PATH

trap : 2  # Do not interrupt this script

# Language file for Frenzy loader
. /etc/lang/ru
DEFLANG="ru"
# Include subroutines
. /etc/rc.SETTINGS
. /etc/rc.vars
. /etc/rc.bootdev
. /etc/rc.bootsplash
. /etc/rc.fem
. /etc/rc.fromhdd
. /etc/rc.gconsole
. /etc/rc.hdd 
. /etc/rc.mfs
. /etc/rc.toram
. /etc/rc.uzip


# Enable russian locale
enable_locale ()
{
Cons=/dev/ttyv0
vidcontrol < ${Cons} -l koi8-r2cp866
FRENZY_FONT="/usr/share/syscons/fonts/866-frenzy-8x16.fnt"
if [ -f ${FRENZY_FONT} ]; then
    vidcontrol < ${Cons} -f 8x16 866-frenzy-8x16
else
    vidcontrol < ${Cons} -f 8x16 cp866-8x16
fi
}
# -- END

patch_loader ()
{
printf "$mi ${MSG_apply_conf_patch}\n"
CURRDIR=`pwd`
cd ${fc_conf}
for PTC in `ls -1 | grep patch` 
do
    /bin/sh ${PTC} 
done
cd ${CURRDIR}
}


### Frenzy RC script ###

### 0. Define all variables
define_var
### 1. Search and mount boot device (CD or USB FLASH)
search_boot_device

### 1.1. Loading loader config from boot media, if exist
FRENZY_LOADSET="${fc}/${fbootcfg}"
if [ -e "${FRENZY_LOADSET}" ]; then
    . ${FRENZY_LOADSET}
fi



### 2. Mounting compressed FS
mount_uzip_fs
### 2.1. Enable locale
enable_locale
### 2.2. Get MFS size
get_mfs_size
### 3. Bootsplash
if [ "${enable_bootsplash}" = "YES" ]; then
bootsplash
fi
### 4. Create MFS
create_mfs
### 4.1. Save bootsplash settings
bootsplash_save
### 4.2. Graphical console
gconsole
### 5. Patch loading
if [ "${enable_patchloader}" = "YES" ]; then
    patch_loader
fi

### 6. ToRam Loader [if enabled]
if [ -n "${FR_TORAM}" ]; then
    toram
else
    if [ "${enable_toram_default}" = "YES" ]; then
	toram
    fi
fi
###

# 7. Search HDD partition (rc.hdd)
if [ "${enable_hddpartitions}" = "YES" ]; then
    search_partition
    ### 7.1. FromHDD Loader [if enabled]
    if [ -n "${FR_FROMHDD}" ]; then
	fromhdd
    fi
    ###
fi

if [ "$enable_fem" = "YES" ]; then
    load_fem
fi

create_rw

if [ "$enable_fem" = "YES" ]; then
    fem_postinstall
fi


### 
# Create file /tmp/.frenzy - required for patched /etc/rc.d/*
#
touch /tmp/.frenzy

###
# Set system language
/usr/local/bin/frlang ${SYSLANG}

###
# Restore backups
if [ -z "${FR_NOBACKUP}" ]; then
    printf "$mi ${MSG_restoring_backup}\n"
    RBK="/usr/local/bin/frbk-restore"
    if [ -e ${RBK} ]; then
	$RBK
    fi
fi

### Execute system rc
printf "$mi ${MSG_loading_system_rc}\n"
exec /bin/sh /etc/rc


