#!/bin/sh
# Initial script for Linux Live Kit
# Author: Tomas M <http://www.linux-live.org/>

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

. /lib/.config
. /lib/livekitlib

transfer_initramfs

MEMORY=/memory
CHANGES=$MEMORY/changes
UNION=$MEMORY/union
DATAMNT=$MEMORY/data
BUNDLES=$MEMORY/bundles

header "Live Kit init <http://www.linux-live.org/>"

init_proc_sysfs

debug_start
debug_shell

init_devs
init_aufs
init_zram

init_union "$CHANGES" "$UNION"

# find data dir with filesystem bundles
DATA="$(find_data 60 "$DATAMNT")"

# copy to RAM if needed
DATA="$(copy_to_ram "$DATA")"

debug_shell

# add data to union
union_append_bundles "$DATA" "$BUNDLES" "$UNION"

# create empty fstab
fstab_create "$UNION"

header "Live Kit done, starting $LIVEKITNAME"

debug_shell
change_root "$UNION"

header "!!ERROR occured, you shouldn't be here.!!"
/bin/sh
