#!/bin/sh

# Putting first argument ($1) in variable filename
filename=$1

backupdir='backup'

if [ ! -d $backupdir ] 
    then
    mkdir $backupdir
fi

cd 'backup'

# Getting date
date=$(date '+%A.%d.%m.%g')

#Checking if a directory named date exists

if [ ! -d $date ]
    then
    mkdir $date
fi

cd $date

time=$(date '+%H.%M')

dirName=$filename'_(kl.'$time')'
counter=1

while [ -d $dirName ]
do
    dirName=$filename'_(kl.'$time')_'$counter
    counter=`expr $counter + 1`
done

mkdir $dirName

echo "New dir:".$date"/"$dirName



# List all the files you want to backup (must start with '../../').
cp ../../main.c ../../main.h ../../link.c ../../link.h ../../Makefile $dirName

cd ../../
