Fix/installation (#215)
* fix installation when using service - no need for ctrl+c * Improve uninstallatino process
This commit is contained in:
11
README.md
11
README.md
@@ -18,6 +18,7 @@ The easiest way to track your Raspberry Pi or Ubuntu computer system health and
|
||||
* Remotely restart / shutdown your system and control your monitors.
|
||||
* Automatic HASS configuration: Supports discovery messages, so no manual configuration in [Home Assistant](https://www.home-assistant.io/) configuration.yaml is needed.
|
||||
* Automated installation and configuration: you can install it and schedule it with a service or cron with just one command from shell.
|
||||
* Easy uninstallation, just run rpi-mqtt-monitor --uninstall
|
||||
* Configurable: You can select what is monitored and how the message(s) is send (separately or as one csv message).
|
||||
* Easy update: You can update the script by calling it with command line "rpi-mqtt-monitor --update" or via Home Assistant UI.
|
||||
* Support multiple languages: English, German and Bulgarian
|
||||
@@ -63,7 +64,7 @@ The easiest way to track your Raspberry Pi or Ubuntu computer system health and
|
||||
## CLI arguments
|
||||
|
||||
```
|
||||
usage: rpi-mqtt-monitor [-h] [-H] [-d] [-s] [-v] [-u] [-w]
|
||||
usage: rpi-mqtt-monitor [-h] [-H] [-d] [-s] [-v] [-u] [-w] [--uninstall]
|
||||
|
||||
Monitor CPU load, temperature, frequency, free space, etc., and publish the data to an MQTT server or Home Assistant API.
|
||||
|
||||
@@ -75,6 +76,7 @@ options:
|
||||
-v, --version display installed version and exit
|
||||
-u, --update update script and config then exit
|
||||
-w, --hass_wake display Home assistant wake on lan configuration
|
||||
--uninstall uninstall rpi-mqtt-monitor and remove all related files
|
||||
|
||||
```
|
||||
|
||||
@@ -106,6 +108,13 @@ It is recommended to run the script as a service, this way you can use the resta
|
||||
### Manual
|
||||
[moved to wiki](../../wiki/Manual-Installation)
|
||||
|
||||
## Uninstallation
|
||||
|
||||
To uninstall Raspberry Pi MQTT Monitor, run the following command:
|
||||
|
||||
'''rpi-mqtt-monitor --uninstall'''
|
||||
|
||||
|
||||
## Home Assistant Integration
|
||||
|
||||
If you are using discovery_messages, then this step is not required as a new MQTT device will be automatically created in Home Assistant and all you need to do is add it to a dashboard.
|
||||
|
||||
@@ -237,7 +237,6 @@ set_service(){
|
||||
sudo systemctl enable rpi-mqtt-monitor.service
|
||||
sudo systemctl start rpi-mqtt-monitor.service
|
||||
sudo service rpi-mqtt-monitor restart
|
||||
sudo service rpi-mqtt-monitor status
|
||||
print_green "+ Service is enabled and started"
|
||||
git config --global --add safe.directory ${cwd}
|
||||
}
|
||||
|
||||
@@ -25,9 +25,23 @@ welcome(){
|
||||
uninstall(){
|
||||
printm "Uninstalling rpi-mqtt-monitor"
|
||||
|
||||
# Remove the rpi-mqtt-monitor directory
|
||||
if [ -d "rpi-mqtt-monitor" ]; then
|
||||
rm -rf rpi-mqtt-monitor
|
||||
# Ask for confirmation before proceeding
|
||||
read -r -p "Are you sure you want to uninstall rpi-mqtt-monitor? [y/N] " response
|
||||
if [[ ! "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
|
||||
echo "Uninstallation canceled."
|
||||
exit
|
||||
fi
|
||||
|
||||
# Get the absolute path of the script
|
||||
script_dir=$(dirname "$(realpath "$0")")
|
||||
|
||||
# Remove the rpi-mqtt-monitor directory if it exists
|
||||
if [ -d "$script_dir" ]; then
|
||||
if [ "$(realpath rpi-mqtt-monitor)" == "$script_dir" ]; then
|
||||
# If the script is running from the installation directory, navigate out of it
|
||||
cd ..
|
||||
fi
|
||||
sudo rm -rf "$script_dir"
|
||||
echo "Removed rpi-mqtt-monitor directory."
|
||||
else
|
||||
echo "rpi-mqtt-monitor directory not found."
|
||||
|
||||
@@ -869,7 +869,7 @@ def parse_arguments():
|
||||
parser.add_argument('-v', '--version', action='store_true', help='display installed version and exit', default=False)
|
||||
parser.add_argument('-u', '--update', action='store_true', help='update script and config then exit', default=False)
|
||||
parser.add_argument('-w', '--hass_wake', action='store_true', help='display Home assistant wake on lan configuration', default=False)
|
||||
|
||||
parser.add_argument('--uninstall', action='store_true', help='uninstall rpi-mqtt-monitor and remove all related files')
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.update:
|
||||
@@ -1015,6 +1015,24 @@ def update_status():
|
||||
break
|
||||
|
||||
|
||||
def uninstall_script():
|
||||
"""Call the remote_install.sh script to uninstall the application."""
|
||||
script_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../remote_install.sh")
|
||||
|
||||
if not os.path.exists(script_path):
|
||||
print("Error: remote_install.sh script not found.")
|
||||
return
|
||||
|
||||
try:
|
||||
# Run the uninstall command
|
||||
subprocess.run(["bash", script_path, "uninstall"], check=True)
|
||||
print("Uninstallation process completed.")
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"Error during uninstallation: {e}")
|
||||
except Exception as e:
|
||||
print(f"Unexpected error: {e}")
|
||||
|
||||
|
||||
def on_message(client, userdata, msg):
|
||||
global exit_flag, thread1, thread2
|
||||
print("Received message: ", msg.payload.decode())
|
||||
@@ -1060,6 +1078,11 @@ else:
|
||||
|
||||
if __name__ == '__main__':
|
||||
args = parse_arguments();
|
||||
|
||||
if args.uninstall:
|
||||
uninstall_script()
|
||||
sys.exit(0)
|
||||
|
||||
if args.service:
|
||||
if not args.hass_api:
|
||||
client = paho.Client()
|
||||
|
||||
Reference in New Issue
Block a user