#!/bin/bash

WORKDIR=/home/pi/ehc602/backend

dos2unix $WORKDIR/hostid/*.sh
chmod +x $WORKDIR/hostid/*.sh

dos2unix $WORKDIR/bems/*.sh
dos2unix $WORKDIR/bems/*.py
chmod +x $WORKDIR/bems/*.sh

dos2unix $WORKDIR/agents/*.sh
chmod +x $WORKDIR/agents/*.sh
chown pi $WORKDIR/agents/setup-agent.sh $WORKDIR/agents/configuration-merge.sh $WORKDIR/agents/JsonMerge.jar
chgrp pi $WORKDIR/agents/setup-agent.sh $WORKDIR/agents/configuration-merge.sh $WORKDIR/agents/JsonMerge.jar

dos2unix $WORKDIR/ftdi/*.sh
chmod +x $WORKDIR/ftdi/*.sh

dos2unix $WORKDIR/database/*.sh
dos2unix $WORKDIR/database/*.sql
chmod +x $WORKDIR/database/*.sh

dos2unix $WORKDIR/rtc/*.sh
chmod +x $WORKDIR/rtc/*.sh

dos2unix $WORKDIR/logrotate/*.sh
dos2unix $WORKDIR/logrotate/*.conf
chmod +x $WORKDIR/logrotate/*.sh

dos2unix $WORKDIR/httpd/*.sh
chmod +x $WORKDIR/httpd/*.sh

dos2unix $WORKDIR/wifi/*.sh
chmod +x $WORKDIR/wifi/*.sh

dos2unix $WORKDIR/properties/factory/*.sh
chmod +x $WORKDIR/properties/factory/*.sh

dos2unix $WORKDIR/*.sh
chmod +x $WORKDIR/*.sh

if [ -d "$WORKDIR/patch" ]; then
   dos2unix $WORKDIR/patch/*.sh
   chmod +x $WORKDIR/patch/*.sh
fi

if [ -f "$WORKDIR/patch/patch.sh" ]; then
   $WORKDIR/patch/patch.sh
   rm -rf $WORKDIR/patch
fi
