#
#                 How to connect scdbackup to a suitable shell
#
#                       since version 0.5.3 , 12 Jan 2000 
#
# If /bin/sh does not exist on your system or if /bin/sh does not understand  
# the scripts of scdbackup , then you have to get a suitable shell (strongly
# recommended: bash). If for some reason you cannot install this new shell
# as /bin/sh then you have to change scdbackup too.
#
# This script shows what has to be done to switch to a shellname different
# from /bin/sh .  Below, you find some commands which help to fulfill this
# task automatically.
# - compile  cd_backup_planer
# - run cd_backup_planer to change all (!) scripts in the current directory
# - write a file which is later used to inform cd_backup_planer about the shell
# Better have a look at these commands before running the script for the first
# time. Maybe your shell will raise protest. (sigh)
#
# What to do :
#
# After having installed bash (or something compatible) you should write "#!"
# and the program's name into the first line of this script.
# Like :  #!my_shel_name 
#
# If your usual shell does not understand the headline notation then you
# are in trouble. Try to execute this script and later all scdbackup commands
# explicitely by something like:  bash -c ...
#
# 
#
# If you cannot get this script running you may try to execute the commands
# manually. You may ignore the lines up to the text 
# "--- Here starts the real action ---"
#


if test -z "$1" 
then
  echo >&2
  echo "usage : $0 shellname" >&2
  echo "Sets a new shellname into the headlines of the scripts in this directory" >&2
  echo >&2
  exit 1
fi 

#
# Just to be sure that we are in the scdbackup directory
# Looking for some quite unusual filenames 
#
if test -e cd_backup_planer.c \
     -a -e KONFIGURIEREN \
     -a -e SUPERUSER_CONFIGURE \
     -a -e cd_dir_afiosize \
     -a -e raedchen.c 
then
  echo "Setting the shell to : $1"
else
  echo >&2
  echo "You seem not to be in the scdbackup directory." >&2
  echo "At least one of several typical files is missing." >&2
  echo >&2
  exit 2
fi

echo "Caution: this script changes #! headlines in ALL files in the current"
echo "         directory. Do you really want to do this ? (y/n)"
read eingabe
if test "$eingabe" = "y" -o "$eingabe" = "Y" -o \
        "$eingabe" = "j" -o "$eingabe" = "J" -o "$eingabe" = "1"
then
  echo 'confirmed'
else
  echo 'aborted'
  exit 3
fi

#
# --------------- Here starts the real action -------------
#
# ======               CAUTION !!!                   ======
# ======  This changes #! headlines in ALL files !   ======
# ======  Be sure to be in the scdbackup directory   ======
# ======  before performing these commands manually  ======

#
# The task of altering the first line is quite easy to program in C and
# quite tricky with an unknown shell. cd_backup_planer.c has to be compiled
# anyway, so it is used for that task too.
#
# With Linux and gcc, the compile command is:
#
echo compiling cd_backup_planer.c ...
cc -g -o cd_backup_planer cd_backup_planer.c
#
# If you had to make changes here, you will have to make them in CONFIGURE
# too (and/or KONFIGURIEREN if you prefer a german version). Vice versa,
# look into CONFIGURE wether there is a different compilation line
# if you experience problems here.
#

#
# This changes the script headlines  #!/bin/sh to #!${1}.
#
echo changing all scripts ...
./cd_backup_planer -set_shell_in_scdbackup_scripts "$1" *


#
# This publishes the shell's name for use inside of cd_backup_planer
#
echo "$1" >scdbackup_use_shell_value

echo done
exit 0