Skip to content

Commit

Permalink
V1.18.18
Browse files Browse the repository at this point in the history
  • Loading branch information
jgyates committed Oct 13, 2023
1 parent 3dcc144 commit 68fa521
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 78 deletions.
26 changes: 8 additions & 18 deletions genloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,11 @@ def CheckBaseSoftware(self):
if self.PipChecked:
return True

command_list = [self.pipProgram, "-V"]
command_list = [sys.executable, "-m", "pip", "-V"]
#command_list = [self.pipProgram, "-V"]
if not self.ExecuteCommandList(command_list):
self.InstallBaseSoftware()

"--break-system-packages"
# /usr/lib/python3.11/EXTERNALLY-MANAGED
managedfile = f"/usr/lib/python{sys.version_info.major:d}.{sys.version_info.minor:d}/EXTERNALLY-MANAGED"
if os.path.isfile(managedfile):
Expand Down Expand Up @@ -457,7 +457,7 @@ def GetLibararyVersion(self, libraryname, importonly=False):
if "linux" in sys.platform:
self.CheckBaseSoftware()

install_list = [self.pipProgram, "freeze", libraryname]
install_list = [sys.executable, "-m", "pip", "freeze", libraryname]

process = Popen(install_list, stdout=PIPE, stderr=PIPE)
output, _error = process.communicate()
Expand Down Expand Up @@ -519,27 +519,19 @@ def InstallLibrary(self, libraryname, update=False, version=None, uninstall=Fals
self.CheckBaseSoftware()

if update:
install_list = [self.pipProgram, "install", libraryname, "-U"]
install_list = [sys.executable, "-m", "pip", "install", libraryname, "-U"]
elif uninstall:
install_list = [self.pipProgram, "uninstall", "-y", libraryname]
install_list = [sys.executable, "-m", "pip", "uninstall", "-y", libraryname]
else:
install_list = [self.pipProgram, "install", libraryname]

if self.OverrideManagedPackages:
# starting with bookworm the raspberry pi os has managed system
# packages enabled so we will override that to install genmon
# requirements
install_list.append("--break-system-packages")
install_list = [sys.executable, "-m", "pip", "install", libraryname]

process = Popen(install_list, stdout=PIPE, stderr=PIPE)
output, _error = process.communicate()

if _error:
self.LogInfo(
"Error in InstallLibrary using pip : "
+ libraryname
+ " : UnInstall: "
+ str(uninstall)
+ str(install_list)
+ ": "
+ str(_error)
)
Expand All @@ -549,9 +541,7 @@ def InstallLibrary(self, libraryname, update=False, version=None, uninstall=Fals
except Exception as e1:
self.LogInfo(
"Error installing module: "
+ libraryname
+ " : UnInstall: "
+ str(uninstall)
+ str(install_list)
+ ": "
+ str(e1),
LogLine=True,
Expand Down
73 changes: 14 additions & 59 deletions genmonmaint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,24 @@ noprompt_opt=false
cleanpython_opt=false
copyfiles_opt=false
update_os=false
managedpackages=false

#-------------------------------------------------------------------------------
function removemanagedpip() {
function checkmanagedpackages() {

# /usr/lib/python3.11/EXTERNALLY-MANAGED
pythonmajor=$($pythoncommand -c 'import sys; print(sys.version_info.major)')
pythonminor=$($pythoncommand -c 'import sys; print(sys.version_info.minor)')
managedfile="/usr/lib/python$pythonmajor.$pythonminor/EXTERNALLY-MANAGED"

if [ -f $managedfile ]; then
pipoptions="--break-system-packages"
echo "Overriding system managed package system.."
managedpackages=true
echo "Managed system packages found, installing python virtual environment"
sudo apt-get -yqq install python3-venv
# create the virtual environment
echo "Creating virtual python environmnet for genmon"
$pythoncommand -m venv genenv
pythoncommand="./genenv/bin/python"
fi
}

Expand Down Expand Up @@ -87,32 +93,7 @@ function copyconffiles() {
function updatelibraries() {

echo "Updating libraries...."
sudo $pipcommand install crcmod -U $pipoptions
sudo $pipcommand install configparser -U $pipoptions
sudo $pipcommand install pyserial -U $pipoptions
sudo $pipcommand install Flask -U $pipoptions
if [ "$usepython3" = true ] ; then
sudo $pipcommand install pyowm==2.10.0 -U $pipoptions
else
sudo $pipcommand install pyowm==2.9.0 -U $pipoptions
fi
sudo $pipcommand install pytz -U $pipoptions
sudo $pipcommand install pyopenssl -U $pipoptions
sudo $pipcommand install twilio -U $pipoptions
sudo $pipcommand install chump -U $pipoptions
sudo $pipcommand install paho-mqtt -U $pipoptions
sudo $pipcommand install pysnmp -U $pipoptions
sudo $pipcommand install ldap3 -U $pipoptions
sudo $pipcommand install pyasn1==0.4.8 -U $pipoptions
sudo $pipcommand install smbus -U $pipoptions
sudo $pipcommand install psutil -U $pipoptions
if [ "$usepython3" = true ] ; then
sudo $pipcommand install pyotp -U $pipoptions
else
sudo $pipcommand install pyotp==2.3.0 -U $pipoptions
fi
sudo $pipcommand install mopeka_pro_check -U $pipoptions
sudo $pipcommand install fluids -U $pipoptions
sudo $pythoncommand -m pip install -r requirements.txt -U $pipoptions
echo "Done."
}

Expand Down Expand Up @@ -143,48 +124,22 @@ function installrpirtscts() {
# This function will install the required libraries for genmon
function installgenmon() {

echo "Installing...."
checkmanagedpackages
echo "Installing genmon package requirements...."
# possibly use "sudo easy_install3 -U pip"
sudo apt-get -yqq update
if [ "$usepython3" = true ] ; then
sudo apt-get -yqq install python3-pip
else
sudo apt-get -yqq install python-pip
fi
sudo $pipcommand install crcmod $pipoptions
sudo $pipcommand install configparser $pipoptions
sudo $pipcommand install pyserial $pipoptions
sudo $pipcommand install Flask $pipoptions
if [ "$usepython3" = true ] ; then
sudo $pipcommand install pyowm==2.10.0 $pipoptions
else
sudo $pipcommand install pyowm==2.9.0 $pipoptions
fi
sudo $pipcommand install pytz $pipoptions
if [ "$usepython3" = true ] ; then
sudo apt-get -yqq install build-essential libssl-dev libffi-dev python3-dev cargo
else
sudo apt-get -yqq install build-essential libssl-dev libffi-dev python-dev cargo
fi
sudo apt-get -yqq install cmake
sudo $pipcommand install pyopenssl $pipoptions
sudo $pipcommand install twilio $pipoptions
sudo $pipcommand install chump $pipoptions
sudo $pipcommand install paho-mqtt $pipoptions
sudo $pipcommand install pysnmp $pipoptions
sudo $pipcommand install ldap3 $pipoptions
sudo $pipcommand install smbus $pipoptions
sudo $pipcommand install psutil $pipoptions
if [ "$usepython3" = true ] ; then
sudo $pipcommand install pyotp $pipoptions
else
sudo $pipcommand install pyotp==2.3.0 $pipoptions
fi
# correct problem with LDAP3 module install
sudo $pipcommand install pyasn1==0.4.8 -U $pipoptions
sudo $pipcommand install mopeka_pro_check $pipoptions
sudo $pipcommand install fluids $pipoptions
sudo $pipcommand install voipms $pipoptions
sudo $pythoncommand -m pip install -r requirements.txt $pipoptions

sudo chmod 775 "$genmondir/startgenmon.sh"
sudo chmod 775 "$genmondir/genmonmaint.sh"
Expand Down Expand Up @@ -445,7 +400,7 @@ shift $((OPTIND -1))
if [ "$update_os" = true ] ; then
sudo apt-get --allow-releaseinfo-change update && sudo apt-get upgrade
fi
removemanagedpip

if [ "$install_opt" = true ] ; then
if [ "$noprompt_opt" = true ] ; then
installgenmon "noprompt"
Expand Down
39 changes: 38 additions & 1 deletion startgenmon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,36 @@ pipcommand="pip3"
config_path=""
usepython3=true
found_action=false
managedpackages=false


#-------------------------------------------------------------------------------
function env_activate() {

if [ "$managedpackages" = true ] ; then
source genenv/bin/activate
fi
}
#-------------------------------------------------------------------------------
function env_deactivate() {
if [ "$managedpackages" = true ] ; then
deactivate
fi
}
#-------------------------------------------------------------------------------
function checkmanagedpackages() {

# /usr/lib/python3.11/EXTERNALLY-MANAGED
pythonmajor=$($pythoncommand -c 'import sys; print(sys.version_info.major)')
pythonminor=$($pythoncommand -c 'import sys; print(sys.version_info.minor)')
managedfile="/usr/lib/python$pythonmajor.$pythonminor/EXTERNALLY-MANAGED"

if [ -f $managedfile ]; then
pythoncommand="./genenv/bin/python"
managedpackages=true
echo "using binary: $pythoncommand"
fi
}
#-------------------------------------------------------------------------------
function setuppython3() {

Expand Down Expand Up @@ -79,28 +108,36 @@ while (( "$#" )); do
;;
esac
done

checkmanagedpackages
for val in $PARAMS; do
case "$val" in
start)
echo "Starting genmon python scripts"
env_activate
found_action=true
sudo $pythoncommand "$genmondir/genloader.py" -s $config_path
env_deactivate
;;
stop)
found_action=true
env_activate
echo "Stopping genmon python scripts"
sudo $pythoncommand "$genmondir/genloader.py" -x $config_path
env_deactivate
;;
hardstop)
found_action=true
env_activate
echo "Hard Stopping genmon python scripts"
sudo $pythoncommand "$genmondir/genloader.py" -z $config_path
env_deactivate
;;
restart)
found_action=true
env_activate
echo "Restarting genmon python scripts"
sudo $pythoncommand "$genmondir/genloader.py" -r $config_path
env_deactivate
;;
*)
#
Expand Down

0 comments on commit 68fa521

Please sign in to comment.