#!/bin/sh 

##################################################
#
# GiantDisc mp3 Jukebox
# 
# © 2002, Rolf Brugger
#
##################################################


# Installs the GiantDisc package. No user data or config files are
# overwritten.
#
# Files are only modified in / written to the directory ~music (home
# directory of user "music").
#
# This script should be executed from within the unpacked GiantDisc
# install archive.

echo ""
echo "GiantDisc installation/update script"
echo ""

if [ ! -e Install.sh ]; then
  echo "ERROR: You have to cd to the  directory where Install.sh resides"
  echo "Exit"
  exit
fi


### Check if user music exists
userslist=`finger music | grep Login:`
if [ -n "$userslist" ]; then
  echo "user 'music' exists. OK"
else
  echo "ERROR: a user 'music' is needed. Create it first"
  echo "Exit"
  exit
fi


#base=~music/tst

#base=~music          # for a few users this doesn't work
base=/home/music


### Create a few mp3 directories
if [ -d $base/00 ]; then
  echo "directory $base/00 exists"
else
  echo "create directory $base/00" 
  mkdir $base/00
fi

if [ -d $base/01 ]; then
  echo "directory $base/01 exists"
else
  echo "create directory $base/01" 
  mkdir $base/01
fi

if [ -d $base/02 ]; then
  echo "directory $base/02 exists"
else
  echo "create directory $base/02" 
  mkdir $base/02
fi

### Create temp-directory
if [ -d $base/tmp ]; then
  echo "directory $base/tmp exists"
else
  echo "create directory $base/tmp" 
  mkdir $base/tmp
fi

### Create inbox
if [ -d $base/inbox ]; then
  echo "directory $base/inbox exists"
else
  echo "create directory $base/inbox" 
  mkdir $base/inbox
fi
if [ -d $base/inbox/albums ]; then
  echo "directory $base/inbox/albums exists"
else
  echo "create directory $base/inbox/albums" 
  mkdir $base/inbox/albums
fi

### Create outbox
if [ -d $base/outbox ]; then
  echo "directory $base/outbox exists"
else
  echo "create directory $base/outbox" 
  mkdir $base/outbox
fi

### Create browse
if [ -d $base/browse ]; then
  echo "directory $base/browse exists"
else
  echo "create directory $base/browse" 
  mkdir $base/browse
fi

### Create bin + content
if [ -d $base/bin ]; then
  echo "directory $base/bin exists"
else
  echo "create directory $base/bin" 
  mkdir $base/bin
fi
echo "copy its content ..."
cp -r bin/* $base/bin
chmod a+x $base/bin/*.pl $base/bin/gdplaytimefilter $base/bin/gdmp3cutter

### Create PalmClient + content
if [ -d $base/PalmClient ]; then
  echo "directory $base/PalmClient exists"
else
  echo "create directory $base/PalmClient" 
  mkdir $base/PalmClient
fi
echo "copy its content ..."
cp -r PalmClient/*.prc $base/PalmClient

### Create public_html + content
if [ -d $base/public_html ]; then
  echo "directory $base/public_html exists"
else
  echo "create directory $base/public_html" 
  mkdir $base/public_html
fi
if [ -d $base/public_html/webint ]; then
  echo "directory $base/public_html/webint exists"
else
  echo "create directory $base/public_html/webint" 
  mkdir $base/public_html/webint
fi
if [ -d $base/public_html/webint/img ]; then
  echo "directory $base/public_html/webint/img exists"
else
  echo "create directory $base/public_html/webint/img" 
  mkdir $base/public_html/webint/img
fi
if [ -d $base/public_html/webint/musichome ]; then
  echo "directory $base/public_html/webint/musichome exists"
else
  echo "create symolic link $base/public_html/webint/musichome" 
  ln -s $base $base/public_html/webint/musichome
fi
cp -r public_html/webint/* $base/public_html/webint
cp -r public_html/webint/img/* $base/public_html/webint/img

### Create database + content
if [ -d $base/database ]; then
  echo "directory $base/database exists"
else
  echo "create directory $base/database" 
  mkdir $base/database
fi

echo "copy its content ..."
cp -r database/*mysql $base/database
cp -r database/make*  $base/database
if [ -f $base/database/genres.txt ]; then
  echo "file $base/database/genres.txt exists. Do not overwrite"
else
  cp database/genres.txt $base/database/
fi
if [ -f $base/database/languages.txt ]; then
  echo "file $base/database/languages.txt exists. Do not overwrite"
else
  cp database/languages.txt $base/database/
fi
if [ -f $base/database/musictypes.txt ]; then
  echo "file $base/database/musictypes.txt exists. Do not overwrite"
else
  cp database/musictypes.txt $base/database/
fi
if [ -f $base/database/sources.txt ]; then
  echo "file $base/database/sources.txt exists. Do not overwrite"
else
  cp database/sources.txt $base/database/
fi


### Other files
if [ -f $base/.gdconfig ]; then
  echo "file $base/.gdconfig exists. Do not overwrite"
  cp .gdconfig $base/.gdconfig.newest-version
else
  cp .gdconfig $base/
fi

cp [A-Z][A-Z]* $base



echo ""
echo "Installation complete, all files are copied"
echo ""

#
