#!/bin/bash
usage(){
    echo "Usage $0 archive"
    echo "Update skels from the given archive file"
}

if [ -z "$1" ]
then
    usage
    exit 1
fi
archive="$1"

DIR=`dirname $0`
cd $DIR
# Update skels
rm -rf skels/*
cd skels
echo $PWD
tar xvzf $archive
mv ./home/* .
rmdir ./home
# Remove caches
rm -r ./*/.cache
pwd
# Add proxy
for d in *
do
    echo $d
    for PROTO in HTTP FTP HTPS
    do
        echo "export ${PROTO}_PROXY=\"slis:3128\"" >> $d/.profile
    done
done
cd ..
# Remove xsession errors
find skels -name .xsession-errors -exec rm {} \;
# Push everything
echo "Adding skels to git"
find skels -exec git add {} \;
git commit -m "Skels updated" skels/
git push
