Skip to content

Commit

Permalink
Merge pull request #688 from linuxkidd/installer-tweaks
Browse files Browse the repository at this point in the history
Installer tweaks - Prompt for camera during install
  • Loading branch information
EricClaeys authored Oct 20, 2021
2 parents 6c9f6e9 + 058d4b3 commit c479a20
Showing 1 changed file with 78 additions and 13 deletions.
91 changes: 78 additions & 13 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#!/bin/bash
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color

source "variables.sh"
if [[ $EUID -eq 0 ]]; then
echo "This script must NOT be run as root" 1>&2
exit 1
Expand All @@ -20,12 +17,85 @@ if [ "$DIR" != "$INSTALL_DIR" ] ; then
exit 1
fi

CAM=""
NEEDCAM=0

echo
echo "**********************************************"
echo "*** Welcome to the Allsky Camera installer ***"
echo "**********************************************"
echo

calc_wt_size() {
# NOTE: it's tempting to redirect stderr to /dev/null, so supress error
# output from tput. However in this case, tput detects neither stdout or
# stderr is a tty and so only gives default 80, 24 values
WT_HEIGHT=18
WT_WIDTH=$(tput cols)

if [ -z "$WT_WIDTH" ] || [ "$WT_WIDTH" -lt 60 ]; then
WT_WIDTH=80
fi
if [ "$WT_WIDTH" -gt 178 ]; then
WT_WIDTH=120
fi
WT_MENU_HEIGHT=$(($WT_HEIGHT-7))
}

select_camera() {
NEEDCAM=0
if [ ! -e ${ALLSKY_CONFIG}/config.sh ]; then
NEEDCAM=1
# NOTE: The config.sh file is put in place during the 'make install' step below.
# This flag will be checked after 'make install', and trigger an edit to set the camera value.
else
source ${ALLSKY_CONFIG}/config.sh
if [ -z "${CAMERA}" ]; then
NEEDCAM=1
# NOTE: The config.sh file is present, but the CAMERA variable is empty, thus we need to query it.
else
CAM=$CAMERA
fi
fi
if [ $NEEDCAM -eq 1 ]; then
MYCAM=$(whiptail --title "Allsky Software Installer" --menu "Camera Type" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT \
"ZWO" "ZWO camera is used for allsky" \
"RPiHQ" "RPiHQ camera is used for allsky" \
3>&1 1>&2 2>&3)
if [ $? -eq 0 ]; then
CAM=$MYCAM
else
whiptail --msgbox "Camera selection required. Please re-run './install.sh' and select a camera to continue." 10 60
exit 1
fi
fi
}

set_camera() {
sed -i -e "s/^CAMERA=.*$/CAMERA=\"${CAM}\"/" "$ALLSKY_CONFIG/config.sh"
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
whiptail --msgbox "Camera set to $CAM" 10 60
return 0
else
whiptail --msgbox "Something went wrong setting camera to ${CAM}. Error code ${RETVAL}?" 10 60
return 1
fi
}


ask_reboot() {
if (whiptail --title "Allsky Software Installer" --yesno "The Allsky Software is now installed. You should reboot the Raspberry Pi to finish the installation.\n\n Reboot now?" 10 60 \
3>&1 1>&2 2>&3); then
sudo reboot now
else
exit 3
fi
}

calc_wt_size
select_camera

echo -e "${GREEN}* Dependencies installation\n${NC}"
sudo make deps
RETVAL=$?
Expand Down Expand Up @@ -53,12 +123,7 @@ if [ $RETVAL -ne 0 ]; then
fi
echo

echo
echo "The Allsky Software is now installed. You should reboot the Raspberry Pi to finish the installation"
echo
read -p "Do you want to reboot now? [y/n] " ans_yn
case "$ans_yn" in
[Yy]|[Yy][Ee][Ss]) sudo reboot now;;

*) exit 3;;
esac
if [ $NEEDCAM -eq 1 ]; then
set_camera
fi
ask_reboot

0 comments on commit c479a20

Please sign in to comment.