Skip to content
Permalink
Browse files

improved logging and debugging options

  • Loading branch information...
d2
d2 committed Nov 11, 2015
1 parent 4ccb5ae commit 376bab63c58a2abd69d7d75fc175b8e0f9424d1e
Showing with 62 additions and 44 deletions.
  1. +62 −44 qw_update_binaries.sh
@@ -16,132 +16,150 @@ LOC_QWFWD=
# automatically update sources?
AUTOUPDATE=no
# debug: 0=no, anything else=yes
DEBUG=1
DEBUG=0
################################################### CONFIGURATION END HERE - DO NOT MODIFY ANYTHING BELOW THIS LINE

# project name to compile
PROJECT=${1}
# destination directory created under each project
BINARYDIR=binaries

b_update_locations() {
if [ ${AUTOUPDATE} = "yes" ]; then
printf "\t[i] updatng binaries\n"
printf "\t[i] updatng binaries\n" | tee -a ${LOGFILE}
val=LOC_$(b_upper ${PROJECT})
vval=$(eval "echo \$$val")
for binarylocation in ${vval}; do
if [ ! -e ${binarylocation} ]; then
printf "\t\t[-] \"${binary}\" binary does not exists under \"${binarylocation}\" location, unable to update it. Please verify \"${val}\" variable\n"
printf "\t\t[-] \"${binary}\" binary does not exists under \"${binarylocation}\" location, unable to update it. Please verify \"${val}\" variable\n" | tee -a ${LOGFILE}
else
printf "\t\t[+] updating \"${binarylocation}\"\n"
printf "\t\t[+] updating \"${binarylocation}\"\n" | tee -a ${LOGFILE}
DNOW=$(date +%Y-%m-%d@%H%M%S)
printf "\t\t\t[+] creating backup copy: ${binarylocation}_${DNOW}\n"
printf "\t\t\t[+] creating backup copy: ${binarylocation}_${DNOW}\n" | tee -a ${LOGFILE}
cp -pr ${binarylocation} ${binarylocation}_${DNOW}
cp -pr ${SRCROOTDIR}/${PROJECT}/${BINARYDIR}/${binary} ${binarylocation}
chmod 755 ${binarylocation}
fi
done
printf "\t\t[i] done, remember to restart \"${PROJECT}\"\n"
printf "\t\t[i] done, remember to restart \"${PROJECT}\"\n" | tee -a ${LOGFILE}
b_end
else
printf "\t[i] automatic updates are disabled, please copy new binaries manually\n"
printf "\t[i] automatic updates are disabled, please copy new binaries manually\n" | tee -a ${LOGFILE}
b_end
fi
}

b_upper() {
echo ${1} | tr "[a-z]" "[A-Z]"
b_start() {
echo "#### START: $(date +%Y-%m-%d@%H%M%S) ####" | tee -a ${LOGFILE}
}

b_set_debug_options() {
if [ ${DEBUG} = 0 ]; then
GITOPTIONS=" --quiet "
GCCOPTIONS=" --quiet "
CFGOPTIONS=" > /dev/null 2>&1 "
fi
b_end() {
echo "#### END: $(date +%Y-%m-%d@%H%M%S) ####" | tee -a ${LOGFILE}
}

b_upper() {
echo ${1} | tr "[a-z]" "[A-Z]"
}

b_check_status() {
if [ ${?} = 0 ]; then
printf "\t\t[+] OK\n"
printf "\t\t[+] OK\n" | tee -a ${LOGFILE}
else
printf "\t\t[-] operation failed\n"
printf "\t\t[-] operation failed\n" | tee -a ${LOGFILE}
b_end
exit 1
fi
}

b_git_update() {
if [ ! -e ${SRCROOTDIR}/${PROJECT} ]; then
printf "\t[-] unable to find proper \"${PROJECT}\" sources, trying git clone https://github.com/deurk/${PROJECT}\n"
git clone ${GITOPTIONS} https://github.com/deurk/${PROJECT}
printf "\t[-] unable to find proper \"${PROJECT}\" sources, trying git clone https://github.com/deurk/${PROJECT}\n" | tee -a ${LOGFILE}
b_run git clone ${GITOPTIONS} https://github.com/deurk/${PROJECT} 2>&1 >> ${LOGFILE}
b_check_status
else
printf "\t[+] trying to update sources first\n"
printf "\t[+] trying to update sources first\n" | tee -a ${LOGFILE}
cd ${SRCROOTDIR}/${PROJECT}
git pull ${GITOPTIONS}
b_run git pull ${GITOPTIONS} 2>&1 >> ${LOGFILE}
b_check_status
fi
}

b_run() {
if [ $DEBUG -ne 0 ]; then
v=$(exec 2>&1 && set -x && set -- "$@")
echo "#### DEBUG: executing ->${v#*--} ####"
"$@"
if [ ${DEBUG} -ne 0 ]; then
n_cmd=$(exec 2>&1 && set -x && set -- "$@")
echo "#### DEBUG: executing ->${n_cmd#*--} ####" 2>&1 >> ${LOGFILE}
"$@" 2>&1 >> ${LOGFILE}
else
GITOPTIONS=" --quiet "
GCCOPTIONS=" --quiet "
CFGOPTIONS=" > /dev/null 2>&1 "
"$@" >/dev/null 2>&1
fi
}

b_project() {
printf "[i] working on \"${PROJECT}\" project\n"
printf "[i] working on \"${PROJECT}\" project\n" | tee -a ${LOGFILE}
b_git_update
if [ -e ${SRCROOTDIR}/${PROJECT}/build/make ]; then
cd ${SRCROOTDIR}/${PROJECT}/build/make
else
cd ${SRCROOTDIR}/${PROJECT}
fi
b_run make ${GCCOPTIONS}
b_run make ${GCCOPTIONS} clean 2>&1 >> ${LOGFILE}
if [ ! -e ${SRCROOTDIR}/${PROJECT}/${BINARYDIR} ]; then
printf "\t\t[i] \"creating ${SRCROOTDIR}/${PROJECT}/${BINARYDIR}\" directory\n"
printf "\t\t[i] creating \"${SRCROOTDIR}/${PROJECT}/${BINARYDIR}\" directory\n" | tee -a ${LOGFILE}
mkdir -p ${SRCROOTDIR}/${PROJECT}/${BINARYDIR}
fi
if [ -e ./configure ]; then
printf "\t[+] configure\n"
b_run ./configure
printf "\t[+] configure\n" | tee -a ${LOGFILE}
b_run ./configure 2>&1 >> ${LOGFILE}
b_check_status
fi
printf "\t[+] make\n"
b_run make ${GCCOPTIONS}
printf "\t[+] make\n" | tee -a ${LOGFILE}
b_run make ${GCCOPTIONS} 2>&1 >> ${LOGFILE}
b_check_status
if [ -e ${SRCROOTDIR}/${PROJECT}/build/make/${binary} ]; then
mv ${SRCROOTDIR}/${PROJECT}/build/make/${binary} ${SRCROOTDIR}/${PROJECT}/${BINARYDIR}/
elif [ -e ${SRCROOTDIR}/${PROJECT}/${binary} ]; then
mv ${SRCROOTDIR}/${PROJECT}/${binary} ${SRCROOTDIR}/${PROJECT}/${BINARYDIR}/
else
printf "\t[-] unable to find \"${binary}\" (checked ${SRCROOTDIR}/${PROJECT}/build/make/${binary} and ${SRCROOTDIR}/${PROJECT}/${binary})\n"
printf "\t[-] unable to find \"${binary}\" (checked ${SRCROOTDIR}/${PROJECT}/build/make/${binary} and ${SRCROOTDIR}/${PROJECT}/${binary})\n" | tee -a ${LOGFILE}
b_end
exit 1
fi
printf "\t[i] done, \"${binary}\" should be available under \"${SRCROOTDIR}/${PROJECT}/${BINARYDIR}\" directory\n"
printf "\t[i] done, \"${binary}\" should be available under \"${SRCROOTDIR}/${PROJECT}/${BINARYDIR}\" directory\n" | tee -a ${LOGFILE}
}

b_root() {
if [ $(whoami) = root ]; then
printf "[i] please do not run this script as root\n"
printf "[i] please do not run this script as root\n" | tee -a ${LOGFILE}
b_end
exit 1
fi
}

# project name to compile
PROJECT=${1}
# destination directory created under each project
BINARYDIR=binaries
# logfile for debugging purposes
if [ ${DEBUG} -ne 0 ]]; then
rm /tmp/${PROJECT}_debug.log > /dev/null 2>&1
LOGFILE=/tmp/${PROJECT}_debug.log
else
LOGFILE=/dev/null
fi

b_start

if [ ! -e ${SRCROOTDIR} ]; then
printf "[-] unable to find ${SRCROOTDIR}. Create one (mkdir ${SRCROOTDIR}) and launch this script again\n"
printf "[-] unable to find ${SRCROOTDIR}. Create one (mkdir ${SRCROOTDIR}) and launch this script again\n" | tee -a ${LOGFILE}
b_end
exit 1
fi

if [ $(which git > /dev/null 2>&1; echo ${?}) -ne 0 ]; then
printf "[-] unable to find git binaries, this is required. Please install it (Debian: sudo apt-get install git)\n"
printf "[-] unable to find git binaries, this is required. Please install it (Debian: sudo apt-get install git)\n" | tee -a ${LOGFILE}
b_end
exit 1
fi

b_root
b_set_debug_options

case ${PROJECT} in
ktx) binary=qwprogs.so
@@ -164,7 +182,7 @@ case ${PROJECT} in
b_project
b_update_locations
;;
*) printf "[-] usage: $(basename ${0}) [ktx|mvdparser|mvdsv|qtv|qwfwd]\n\nthis script is using Deurk sources (https://github.com/deurk/)\n"
*) printf "[-] usage: $(basename ${0}) [ktx|mvdparser|mvdsv|qtv|qwfwd]\n\nthis script is using Deurk sources (https://github.com/deurk/)\n" | tee -a ${LOGFILE}
exit 1
;;
esac

0 comments on commit 376bab6

Please sign in to comment.
You can’t perform that action at this time.