The main.sh script now uses new logging functions.

pull/593/head
jprochazka 2024-07-22 02:33:33 -04:00
rodzic 99642de229
commit 062cd7ec3a
4 zmienionych plików z 69 dodań i 122 usunięć

Wyświetl plik

@ -9,16 +9,7 @@ The following is a history of the changes made to this project.
* The dump1090-fa installation script now mimics the current dump1090-fa installation instructions.
* Added logging functions which in the future will offer a way to log output to files.
* Added variables which can be modified to adjust text colors used by the bash scripts.
* Modified the dump1090-fa installation script so that it utilizes the new logging functions.
* Modified the dump978-fa installation script so that it utilizes the new logging functions.
* Modified the ADS-B Exchange client installation script so it utilizes the new logging functions.
* Modified the airplanes.live client installation script so it utilizes the new logging functions.
* Modified the FlightRadar24 client installation script so it utilizes the new logging functions.
* Modified the Fly Italy ADS-B client installation script so it utilizes the new logging functions.
* Modified the OpenSky Network client installation script so it utilizes the new logging functions.
* Modified the PlaneFinder client installation script so it utilizes the new logging functions.
* Modified the beast-splitter installation script so it utilizes the new logging functions.
* Modified the Duck DNS installation script so it utilizes the new logging functions.
* All installation scripts now utilize the new logging functions.
* Added the --version and -v arguments in order to display the current project version.
* Removed scripting used for image setup.

Wyświetl plik

@ -1,92 +1,125 @@
#!/bin/bash
## INCLUDE EXTERNAL SCRIPTS
## PRE EXECUTION OPERATIONS
source $RECEIVER_BASH_DIRECTORY/variables.sh
source $RECEIVER_BASH_DIRECTORY/functions.sh
## DISPLAY WELCOME SCREEN
## DISPLAY THE WELCOME SCREEN
if ! whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "The ADS-B Receiver Project" --yesno "Thanks for choosing The ADS-B Receiver Project to setup your receiver.\n\nMore information on this project as well as news, support, and discussions can be found on the projects official website located at:\n\n https://www.adsbreceiver.net\n\nWould you like to continue setup?" 14 78; then
# Setup has been halted by the user.
echo -e "\n\e[91m \e[5mSETUP HALTED!\e[25m"
echo -e " Setup has been halted at the request of the user.\e[37m\n"
read -p "Press enter to continue..." discard
LogHeading "Displaying the welcome message"
LogMessage "Displaying the welcome message to the user"
if ! whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" \
--title "The ADS-B Receiver Project" \
--yesno "Thanks for choosing The ADS-B Receiver Project to setup your receiver.\n\nMore information on this project as well as news, support, and discussions can be found on the projects official website located at:\n\n https://www.adsbreceiver.net\n\nWould you like to continue setup?" \
14 78; then
LogAlertHeading "INSTALLATION HALTED"
LogAlertMessage "Setup has been halted at the request of the user"
exit 1
fi
## ATTEMPT TO UPDATE THE REPOSITORY
## ATTEMPT TO CHANGE AND/OR UPDATE THE REPOSITORY
# Skip update if the development flag was set or the selected branch is not present in origin
if [[ $RECEIVER_DEVELOPMENT_MODE != "true" ]]; then
current_branch=`git rev-parse --abbrev-ref HEAD`
clear
echo -e "\n\e[91m ${RECEIVER_PROJECT_TITLE}\n"
echo -e "\e[92m Fetching the latest version of the '${RECEIVER_PROJECT_BRANCH}' branch."
echo -e "\e[93m -----------------------------------------------------------------------------\e[97m\n"
# Ask if the user wishes to back up this branch if core files have been changed
clear
LogProjectName ${RECEIVER_PROJECT_TITLE}
LogTitleHeading "Fetching the latest version of the ${RECEIVER_PROJECT_BRANCH} branch"
LogTitleMessage "------------------------------------------------------------------------------"
echo ""
LogHeading "Checking out and updating the appropriate branch"
if [[ `git status --porcelain --untracked-files=no` && `git ls-remote --heads https://github.com/jprochazka/adsb-receiver.git refs/heads/master | wc -l` = 1 ]]; then
if whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Stash Changes To Branch '${current_branch}'" --defaultno --yesno "There appears to be changes to the current branch. In order to switch to or fetch the '${current_branch}' branch these changes will need to be stashed. Would you like to stash these changes now?" 14 78; then
echo -e "\e[94m Stashing changes to the ${current_branch} branch...\e[97m\n"
if whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" \
--title "Stash Changes To Branch ${current_branch}" \
--defaultno \
--yesno "There appears to be changes to the current branch. In order to switch to or fetch the ${current_branch} branch these changes will need to be stashed. Would you like to stash these changes now?" \
14 78; then
LogMessage "Stashing changes made to the ${current_branch} branch"
git stash
echo ""
else
echo -e " \e[91m SETUP HAS BEEN TERMINATED.\e[39m\n"
LogAlertHeading "INSTALLATION HALTED"
LogAlertMessage "Setup has been halted at the request of the user"
exit 1
fi
fi
# Checkout the appropriate branch
if [[ "${current_branch}" != "${RECEIVER_PROJECT_BRANCH}" ]]; then
echo -e "\e[94m Switching to branch ${RECEIVER_PROJECT_BRANCH}...\e[97m\n"
LogMessage "Switching to branch ${RECEIVER_PROJECT_BRANCH}"
git checkout $RECEIVER_PROJECT_BRANCH
fi
# Fetch the most recent version of the branch from origin and reset any changes
if [[ `git ls-remote --heads https://github.com/jprochazka/adsb-receiver.git refs/heads/$RECEIVER_PROJECT_BRANCH | wc -l` = 1 ]]; then
echo -e "\n\e[94m Fetching branch ${RECEIVER_PROJECT_BRANCH} from origin...\e[97m"
LogMessage "Fetching branch ${RECEIVER_PROJECT_BRANCH} from origin"
echo ""
git fetch origin
echo -e "\e[94m Performing hard reset of branch ${RECEIVER_PROJECT_BRANCH} so it matches origin/${RECEIVER_PROJECT_BRANCH}...\e[97m\n"
echo ""
LogMessage "Performing hard reset of branch ${RECEIVER_PROJECT_BRANCH} so it matches origin/${RECEIVER_PROJECT_BRANCH}"
echo ""
git reset --hard origin/$RECEIVER_PROJECT_BRANCH
else
echo -e "\e[94m The '${RECEIVER_PROJECT_BRANCH}' does not appear to be in origin...\e[97m"
LogMessage "The branch ${RECEIVER_PROJECT_BRANCH} does not appear to be in origin"
fi
echo -e "\n\e[93m -----------------------------------------------------------------------------"
echo -e "\e[92m Finished fetching the latest version the '${RECEIVER_PROJECT_BRANCH}' branch.\e[39m\n"
LogTitleMessage "-----------------------------------------------------------------------------"
LogTitleHeading "Finished fetching the latest version the '${RECEIVER_PROJECT_BRANCH}' branch."
echo ""
read -p "Press enter to continue..." discard
fi
## ASK IF OPERATING SYSTEM SHOULD BE UPDATED
if whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Operating System Updates" --yesno "It is recommended that you update your system before building and/or installing any ADS-B receiver related packages. This script can do this for you at this time if you like.\n\nWould you like to update your operating system now?" 11 78; then
LogHeading "Performing operating system updates if so desired"
LogMessage "Asking the user if they wish to update the operating system"
if whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" \
--title "Operating System Updates" \
--yesno "It is recommended that you update your system before building and/or installing any ADS-B receiver related packages. This script can do this for you at this time if you like.\n\nWould you like to update your operating system now?" \
11 78; then
clear
echo -e "\n\e[91m ${RECEIVER_PROJECT_TITLE}\n"
echo -e "\e[92m Downloading and installing the latest updates for your operating system."
echo -e "\e[93m ------------------------------------------------------------------------\e[97m\n"
LogProjectName ${RECEIVER_PROJECT_TITLE}
LogTitleHeading "Downloading and installing the latest updates for your operating system"
LogTitleMessage "------------------------------------------------------------------------------"
echo ""
LogMessage "Updating the operating system using apt-get"
echo ""
sudo apt-get -y dist-upgrade
echo -e "\n\e[93m ------------------------------------------------------------------------"
echo -e "\e[92m Your operating system should now be up to date.\e[39m\n"
echo ""
LogTitleMessage "------------------------------------------------------------------------"
LogTitleHeading "Your operating system should now be up to date"
echo ""
read -p "Press enter to continue..." discard
fi
## EXECUTE BASH/MAIN.SH
LogHeading "Executing the script bash/main.sh"
LogMessage "Adding execute permissions to bash/main"
chmod +x $RECEIVER_BASH_DIRECTORY/main.sh
LogMessage "Executing bash/main"
bash $RECEIVER_BASH_DIRECTORY/main.sh
if [[ $? -ne 0 ]] ; then
echo -e "\e[91m ANY FURTHER SETUP AND/OR INSTALLATION REQUESTS HAVE BEEN TERMINIATED\e[39m\n"
LogAlertHeading "ANY FURTHER SETUP AND/OR INSTALLATION REQUESTS HAVE BEEN TERMINIATED"
exit 1
fi
## INSTALLATION COMPLETE
# Display the installation complete message box
whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Software Installation Complete" --msgbox "INSTALLATION COMPLETE\n\nDO NOT DELETE THIS DIRECTORY!\n\nFiles needed for certain items to run properly are contained within this directory. Deleting this directory may result in your receiver not working properly.\n\nHopefully, these scripts and files were found useful while setting up your ADS-B Receiver. Feedback regarding this software is always welcome. If you have any issues or wish to submit feedback, feel free to do so on GitHub.\n\n https://github.com/jprochazka/adsb-receiver" 20 65
echo -e "\n\e[91m Installation complete.\n"
whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" \
--title "Software Installation Complete" \
--msgbox "INSTALLATION COMPLETE\n\nDO NOT DELETE THIS DIRECTORY!\n\nFiles needed for certain items to run properly are contained within this directory. Deleting this directory may result in your receiver not working properly.\n\nHopefully, these scripts and files were found useful while setting up your ADS-B Receiver. Feedback regarding this software is always welcome. If you have any issues or wish to submit feedback, feel free to do so on GitHub.\n\n https://github.com/jprochazka/adsb-receiver" \
20 65
LogProjectName "Installation complete"
exit 0

Wyświetl plik

@ -1,77 +0,0 @@
#####################################################################################
# ADS-B RECEIVER #
#####################################################################################
# #
# A set of scripts created to automate the process of installing the software #
# needed to setup a Mode S decoder as well as feeders which are capable of #
# sharing your ADS-B results with many of the most popular ADS-B aggregate sites. #
# #
# Project Hosted On GitHub: https://github.com/jprochazka/adsb-receiver #
# #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# #
# Copyright (c) 2015 Joseph A. Prochazka #
# #
# Permission is hereby granted, free of charge, to any person obtaining a copy #
# of this software and associated documentation files (the "Software"), to deal #
# in the Software without restriction, including without limitation the rights #
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell #
# copies of the Software, and to permit persons to whom the Software is #
# furnished to do so, subject to the following conditions: #
# #
# The above copyright notice and this permission notice shall be included in all #
# copies or substantial portions of the Software. #
# #
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE #
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, #
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE #
# SOFTWARE. #
# #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
import json
import datetime
from oled.device import ssd1306, sh1106
from oled.render import canvas
from PIL import ImageDraw, ImageFont
from time import time, sleep
with open('/run/dump1090-mutability/aircraft.json') as aircraft_json:
aircraft_data = json.load(aircraft_json)
def date_and_time():
now = datetime.datetime.now()
return now.strftime("%m/%d/%Y %I:%M %p")
def aircraft_total():
return len(aircraft_data['aircraft'])
def aircraft_with_positions():
with_positions = 0
for aircraft in aircraft_data['aircraft']:
if 'seen_pos' in aircraft:
with_positions += 1
return with_positions
def stats(oled):
font = ImageFont.load_default()
font2 = ImageFont.truetype('fonts/alert.ttf', 12)
font3 = ImageFont.truetype('fonts/alert.ttf', 36)
with canvas(oled) as draw:
draw.text((0, 0), date_and_time(), font=font2, fill=255)
draw.text((0, 14), "Total / With Positions", font=font2, fill=255)
draw.text((0, 28), str(aircraft_total()) + "/" + str(aircraft_with_positions()), font=font3, fill=255)
def main():
oled = ssd1306(port=1, address=0x3C)
stats(oled)
if __name__ == "__main__":
main()

Plik binarny nie jest wyświetlany.