#!/usr/bin/env bash
apt install -y conky conky-all curl jq ttf-ubuntu-font-family

#USER=default
USER=root
DEST=${1:-/etc/skel}

echo "Hidden folder conky is created if it is not there"
[ -d "${DEST}/.conky" ] || mkdir -p ${DEST}/".conky"

#wget -q0- -O /tmp/tmp.zip https://dl.opendesktop.org/api/files/download/id/1465391516/137272-conky_grey.zip && unzip /tmp/tmp.zip && rm /tmp/tmp.zip

wget -qO- -O /var/tmp/aurora.tar.gz http://downloads.sourceforge.net/project/auroraconkytheme/Aurora_v3.0.4.tar.gz && tar xzf /var/tmp/aurora.tar.gz && mv Aurora/ ${DEST}/.conky && rm /var/tmp/aurora.tar.gz

#cd /tmp
#git clone http://github.com/maxiwell/conky-seamod
#git clone http://github.com/zagortenay333/Harmattan

apt install -y lm-sensors hddtemp dmidecode

chmod u+s /usr/sbin/hddtemp
chmod u+s /usr/sbin/dmidecode
chmod u+s /usr/sbin/smartctl

cd ${DEST}/.conky/Aurora

echo "installing necessary fonts"
[ -d "${DEST}"/.conky/fonts ] || mkdir -p "${DEST}"/.conky/fonts
cp ./fonts/* ${DEST}/.conky/fonts
#sudo chown $USER ${DEST}/.fonts
#sudo chmod 644 ${DEST}/.fonts/*
#fc-cache -fv

#sensors-detect
#service kmod restart

#echo "building conky-manager2" 
#apt install -y p7zip-full rsync imagemagick
#cd /var/tmp
#
## build deps
#apt install -y autotools-dev devscripts debhelper valac libgtk-3-dev libgee-0.8-dev libjson-glib-dev
#git clone http://github.com/zcot/conky-manager2
#cd conky-manager2
#
## Adjust to accept current valac version
#sed -i -e "s|\(valac-\)....|valac|" debian/control
#sed -i -e "s|\( realpath\).||" debian/control
#dch -R 
#dpkg-buildpackage -us -uc -b
#dpkg -i ../conky-manager_*deb
#apt -f install
#
## Remove build deps
#apt remove -y autotools-dev valac debhelper libgtk-3-dev libgee-0.8-dev libjson-glib-dev
#apt -y autoremove

# Run conky + theme on x startup. Points at the symlink in dotconky changed by theme
mkdir -p ${DEST}/.xinitrc.d/
cat > ${DEST}/.xinitrc.d/start_conky.sh << 'EOF'
#!/usr/bin/env bash

exec /bin/sh ${HOME}/.conky/conky-startup.sh
EOF

chmod +x  ${DEST}/.xinitrc.d/start_conky.sh

# download example conky theme.
mkdir -p ${DEST}/.conky
if [ ! -d ${DEST}/.conky/conky-xanimos ]; then
   git clone https://git.ring-zero.co.uk/cyteen/conky-xanimos ${DEST}/.conky/conky-xanimos
fi

# Change conky symlink to point to our default theme.
ln -sfr ${DEST}/.conky/conky-xanimos/conky_start.sh ${DEST}/.conky/conky-startup.sh
