#!/bin/sh

. ./config

if [ ! -f $KNOPPIX_SOURCE ]; then
  echo "Please edit config file and set appropriate values (KNOPPIX_SOURCE)"
  exit 1;
fi

[ ! -d $REMASTER_PATH/master/KNOPPIX ] && mkdir -p $REMASTER_PATH/master/KNOPPIX
[ ! -d $REMASTER_PATH/master/boot ] && cp isolinux.tar.bz2 $REMASTER_PATH/master/ && cd $REMASTER_PATH/master && tar -xjf isolinux.tar.bz2 && rm isolinux.tar.bz2

# preparing the knoppix source folder
if [ ! -d $REMASTER_PATH/source ]; then
  if [ -f $KNOPPIX_SOURCE ]; then
    cd $REMASTER_PATH 
    echo "Detarring knoppix source file, this can take some minutes"
    tar -xjf $KNOPPIX_SOURCE
  elif [ ${KNOPPIX_SOURCE:0:4} == "http"]; then
    cd $REMASTER_PATH
    if [ -f `which wget`]; then
      wget $KNOPPIX_SOURCE
    elif [ -f `which curl`]; then
      curl $KNOPPIX_SOURCE > knoppix.source.tar.bz2
    else
      "could not download $KNOPPIX_SOURCE, please do it by hand and edit config"
    fi
  else
    echo "problem with accessing knoppix source file"
  fi
fi
