#!/bin/bash

url="http://repo.alter-os.ru/testing/drv/wineprefix/*"
url="http://192.168.5.10:3334/testing/drv/wineprefix/school/"
tmp_dir="/tmp/school"
dest_folder="$HOME"
sudo yum install -y alteros-extras-release
sudo yum clean all
sudo yum install -y --setopt tsflags=nodocs wine.i686

if [ -d /tmp/school ]; then
  echo "folder exists"
else
  mkdir -p /tmp/school
fi


cd /tmp/school
wget -r -N -A '*.tar' -np -nd -e robots=off $url
if [[ $? -ne 0 ]]; then
  echo error
  exit
fi
filelist=`ls .`
echo $filelist
if [ -d $dest_folder ]; then
  echo "folder would be overwritten"
else 
  mkdir -p $dest_folder
fi


for file in  $filelist; do
  echo $file
  tar -xf $file -C $dest_folder
done
chown $USER $dest_folder -R
wineboot
rm -rf $tmp_dir
