Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
fortunacio committed Apr 2, 2024
0 parents commit df3ec32
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Maintenance Script for Hive OS

## Overview

This script is specifically designed for automating the maintenance process of mining systems running Hive OS. It executes a series of commands to manage the mining software and system resources efficiently. The script stops the mining process, cleans up installed versions of the mining software, updates Nvidia drivers to the latest version available, removes old Nvidia driver packages, reinstalls nvidia-settings, checks disk space, and finally, prompts for a system restart. It includes error handling to provide warnings for specific known issues and errors for unexpected conditions.

## Installation

To install this maintenance script on your Hive OS setup, use the `curl` command to download it from GitHub releases and make it executable. Replace `URL_TO_SCRIPT` with the actual URL to the script in your GitHub repository's releases.

```bash
curl -LJO URL_TO_SCRIPT
chmod +x hiveos_maintenance.sh
```

## Usage

Once the script is installed, you can run it directly from the terminal of your Hive OS system. It does not require any arguments and will proceed through the maintenance steps automatically, providing step-by-step feedback in the terminal.

```bash
./hiveos_maintenance.sh
```

### Script Functions

1. **Stops the mining process:** Ensures the miner is safely stopped before proceeding with maintenance tasks.
2. **Cleans up installed miner versions:** Removes all previously installed versions of the mining software.
3. **Updates Nvidia drivers:** Checks and updates the Nvidia drivers to the latest version available.
4. **Removes old Nvidia drivers:** Cleans up old Nvidia driver packages that are no longer needed.
5. **Reinstalls nvidia-settings:** Makes sure that nvidia-settings is correctly installed and configured.
6. **Checks disk space:** Provides a summary of the available disk space on the system.
7. **System restart:** Prompts the user to restart the system to ensure all updates and changes are applied effectively.

### Important Notes

- Run the script with root privileges to ensure it can execute all commands without permission issues.
- It's recommended to review and test the script in a controlled environment before running it on your production Hive OS systems to avoid any unintended consequences.
59 changes: 59 additions & 0 deletions hiveos_maintenance.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash

# Function to print a step message and execute a command
print_step() {
echo -e "\e[32mSTEP $1: $2 ($3)\e[0m"
}

# Function to print a warning message
print_warning() {
echo -e "\e[33mWarning: executing command: $1\e[0m"
}

# Function to print an error message
print_error() {
echo -e "\e[91mError: executing command: $1\e[0m"
}

run_command() {
print_step "$1" "$2" "$3"

output=$($3 2>&1)
exit_status=$?

if [ $exit_status -eq 0 ]; then
echo "$output"
else
if [ $1 -eq 1 ]; then
if [[ "$output" != *"no miner screen found"* ]]; then
print_warning "$2"
fi
elif [ $1 -eq 3 ]; then
if [[ "$output" != *"this version is already installed"* ]]; then
print_warning "$2"
fi
else
print_error "$2"
echo "$output"
fi
fi
}


# Execute commands one by one
run_command 1 "Waiting for the miner to stop" "miner stop"
run_command 2 "Cleaning all installed miner versions" "hpkg purge"
run_command 3 "Updating Nvidia drivers to the latest version, if available" "nvidia-driver-update"
run_command 4 "Removing all old Nvidia driver installation packages" "nvidia-driver-update --remove"
run_command 6 "Reinstall nvidia-settings only" "nvidia-driver-update --nvs"
run_command 7 "Checking disk space..." "df -h"


# If all commands executed successfully, prompt the user to press a key to restart
echo "All commands executed successfully. Press any key to restart."
read -n 1 -s -r -p "Press any key to continue"
echo ""

# Restarting the system
reboot

0 comments on commit df3ec32

Please sign in to comment.