mirror of
https://codeberg.org/Tealk/systemupdate.git
synced 2024-12-28 02:07:04 +01:00
init
Signed-off-by: Tealk <tealk@rollenspiel.monster>
This commit is contained in:
parent
34c48f1a6a
commit
c59a7d7b37
2 changed files with 237 additions and 2 deletions
51
README.md
51
README.md
|
@ -1,3 +1,50 @@
|
||||||
# systemupdate
|
# System Update Script (Linux)
|
||||||
|
|
||||||
This Bash script is designed to simplify the process of updating your Linux system.
|
## Overview
|
||||||
|
This Bash script is designed to simplify the process of updating your Linux system. It identifies your Linux distribution and uses the appropriate package manager to update the system, including both package updates and cleaning up old packages. Additionally, it checks for Flatpak and Snap package managers and updates them if installed. This script is provided under the MIT License.
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
- Linux-based operating system (e.g., Arch, Debian, Fedora, openSUSE, Gentoo)
|
||||||
|
- Appropriate permissions to run package manager commands
|
||||||
|
- Optional: Flatpak and Snap installed (if you want to update them)
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
1. Download the script to your desired location.
|
||||||
|
2. Open your terminal and navigate to the directory where the script is located.
|
||||||
|
3. Make the script executable by running the following command:
|
||||||
|
```
|
||||||
|
chmod +x system_update.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
Execute the script with the following command:
|
||||||
|
```
|
||||||
|
./system_update.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
## License
|
||||||
|
This script is distributed under the MIT License. You can find the full license text in the LICENSE file included with this script.
|
||||||
|
|
||||||
|
## Script Details
|
||||||
|
- The script will create a log file in `~/.cache/updates` to record its execution.
|
||||||
|
- It identifies your Linux distribution and uses the appropriate update commands.
|
||||||
|
- It checks for the presence of Flatpak and Snap package managers and updates them if installed.
|
||||||
|
- Old log files are periodically deleted to manage disk space.
|
||||||
|
|
||||||
|
## Supported Distributions
|
||||||
|
- Arch Linux and derivatives (e.g., Manjaro): Uses `yay` or `pamac` with `pacman` fallback.
|
||||||
|
- Debian and derivatives (e.g., Ubuntu): Uses `apt-get`.
|
||||||
|
- Fedora: Uses `dnf`.
|
||||||
|
- openSUSE: Uses `zypper`.
|
||||||
|
- Gentoo: Uses `emerge`.
|
||||||
|
- Flatpak: Updates Flatpak packages.
|
||||||
|
- Snap: Updates Snap packages and removes old ones.
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
- If you encounter any issues, please check if you have the required permissions to run package manager commands.
|
||||||
|
- Ensure that the script is executed with administrative privileges if necessary.
|
||||||
|
- If you encounter problems specific to your distribution, consult the documentation or support resources for that distribution.
|
||||||
|
|
||||||
|
Feel free to customize and modify the script according to your needs.
|
||||||
|
|
||||||
|
**Note:** Use this script at your own risk. Make sure you have backups and understand the implications of updating your system.
|
||||||
|
|
188
update.sh
Executable file
188
update.sh
Executable file
|
@ -0,0 +1,188 @@
|
||||||
|
#!/bin/bash
|
||||||
|
mkdir -p ~/.cache/updates
|
||||||
|
|
||||||
|
##*===============================================
|
||||||
|
##* VARIABLE DECLARATION
|
||||||
|
##*===============================================
|
||||||
|
WORK_PATH=~/.cache/updates # Currently the log files are stored here
|
||||||
|
|
||||||
|
# Function: logging
|
||||||
|
# Purpose: Creates a log file for script output and manages log rotation
|
||||||
|
# Parameters: None
|
||||||
|
# Return value: None
|
||||||
|
function logging() {
|
||||||
|
# Check if the folder already exists
|
||||||
|
if [[ ! -d "${WORK_PATH}" ]]; then
|
||||||
|
mkdir -p "${WORK_PATH}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Redirect all output to the log file
|
||||||
|
LOG_DATE=$(date +"%Y-%m-%d")
|
||||||
|
exec &> >(tee -a "${WORK_PATH}/updates_info-${LOG_DATE}.log")
|
||||||
|
|
||||||
|
# Delete old log files
|
||||||
|
find "${WORK_PATH}" -name "updates_info-*.log" -type f -mtime +"${NUM_DAYS_LOG}" -exec rm {} \;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function: time_start
|
||||||
|
# Purpose: Records the start time of the script execution
|
||||||
|
# Parameters: None
|
||||||
|
# Return value: None
|
||||||
|
function time_start() {
|
||||||
|
# Start date and time
|
||||||
|
START_TIME=$(date +"%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
|
# Command to write start date and time to the log file and overwrite the file
|
||||||
|
echo "Script started at ${START_TIME}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function: time_end
|
||||||
|
# Purpose: Calculates the script execution duration and outputs end time
|
||||||
|
# Parameters: None
|
||||||
|
# Return value: None
|
||||||
|
function time_end() {
|
||||||
|
# End date and time
|
||||||
|
END_TIME=$(date +"%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
|
# Calculate duration in seconds
|
||||||
|
SECONDS=$(($(date -d "${END_TIME}" +%s) - $(date -d "${START_TIME}" +%s)))
|
||||||
|
|
||||||
|
# Extract hours, minutes, and seconds from the seconds
|
||||||
|
HOURS=$((SECONDS / 3600))
|
||||||
|
MINUTES=$(((SECONDS % 3600) / 60))
|
||||||
|
SECONDS=$((SECONDS % 60))
|
||||||
|
|
||||||
|
# Command to output end date, time, and duration
|
||||||
|
echo "Script finished at ${END_TIME} (Duration: ${HOURS} hours ${MINUTES} minutes ${SECONDS} seconds)"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function: update_arch
|
||||||
|
# Purpose: Updating Arch or distros based on it
|
||||||
|
# Parameters: None
|
||||||
|
# Return value: None
|
||||||
|
function update_arch() {
|
||||||
|
if command -v yay &> /dev/null; then
|
||||||
|
yay -Su
|
||||||
|
yay -Yc
|
||||||
|
elif command -v pamac &> /dev/null; then
|
||||||
|
sudo pamac update
|
||||||
|
sudo pamac upgrade
|
||||||
|
else
|
||||||
|
sudo pacman -Syu
|
||||||
|
sudo pacman -Rcs "$(pacman -Qdtq)"
|
||||||
|
fi
|
||||||
|
echo "Alle Systemupdates wurden durchgeführt"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function: update_debian
|
||||||
|
# Purpose: Updating Debian or distros based on it
|
||||||
|
# Parameters: None
|
||||||
|
# Return value: None
|
||||||
|
function update_debian() {
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get upgrade -y
|
||||||
|
sudo apt autoremove -y
|
||||||
|
sudo snap refresh
|
||||||
|
echo "Alle Systemupdates wurden durchgeführt"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function: update_fedora
|
||||||
|
# Purpose: Updating Fedora
|
||||||
|
# Parameters: None
|
||||||
|
# Return value: None
|
||||||
|
function update_fedora() {
|
||||||
|
sudo dnf check-update
|
||||||
|
sudo dnf update -y
|
||||||
|
sudo dnf autoremove -y
|
||||||
|
echo "Alle Systemupdates wurden durchgeführt"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function: update_opensuse
|
||||||
|
# Purpose: Updating openSUSE
|
||||||
|
# Parameters: None
|
||||||
|
# Return value: None
|
||||||
|
function update_opensuse() {
|
||||||
|
sudo zypper dup -d
|
||||||
|
sudo zypper dup
|
||||||
|
echo "Alle Systemupdates wurden durchgeführt"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function: update_gentoo
|
||||||
|
# Purpose: Updating openSUSE
|
||||||
|
# Parameters: None
|
||||||
|
# Return value: None
|
||||||
|
function update_gentoo() {
|
||||||
|
sudo emerge --sync
|
||||||
|
sudo emerge -avuDN @world
|
||||||
|
sudo emerge --depclean
|
||||||
|
echo "Alle Systemupdates wurden durchgeführt"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function: update_flatpak
|
||||||
|
# Purpose: Updating flatpak
|
||||||
|
# Parameters: None
|
||||||
|
# Return value: None
|
||||||
|
function update_flatpak() {
|
||||||
|
flatpak update
|
||||||
|
flatpak uninstall --unused
|
||||||
|
echo "Alle Flatpak Updates wurden durchgeführt"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function: update_snap
|
||||||
|
# Purpose: Updating snap
|
||||||
|
# Parameters: None
|
||||||
|
# Return value: None
|
||||||
|
function update_snap() {
|
||||||
|
sudo snap refresh
|
||||||
|
echo "Alle Snap Updates wurden durchgeführt"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function: cleanup_snap
|
||||||
|
# Purpose: Remove old snap packages
|
||||||
|
# Parameters: None
|
||||||
|
# Return value: None
|
||||||
|
function cleanup_snap() {
|
||||||
|
LANG=C snap list --all | awk '/disabled/{print $1, $3}' |
|
||||||
|
while read snapname revision; do
|
||||||
|
snap remove "$snapname" --revision="$revision"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "Dieses Skript installiert Updates auf dem Computer"
|
||||||
|
|
||||||
|
logging
|
||||||
|
|
||||||
|
sudo echo "Die Paketdatenbank wird aktualisiert. Das kann einen Moment dauern."
|
||||||
|
|
||||||
|
time_start
|
||||||
|
|
||||||
|
# Bestimmen der Linux-Distribution anhand der verfügbaren Update-Befehle
|
||||||
|
if command -v pacman &> /dev/null; then
|
||||||
|
update_arch
|
||||||
|
elif command -v apt-get &> /dev/null; then
|
||||||
|
update_debian
|
||||||
|
elif command -v dnf &> /dev/null; then
|
||||||
|
update_fedora
|
||||||
|
elif command -v zypper &> /dev/null; then
|
||||||
|
update_opensuse
|
||||||
|
elif command -v emerge &> /dev/null; then
|
||||||
|
update_gentoo
|
||||||
|
else
|
||||||
|
echo "Die Distribution wird nicht unterstützt."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Überprüfen, ob Flatpak installiert ist
|
||||||
|
if command -v flatpak &> /dev/null; then
|
||||||
|
update_flatpak
|
||||||
|
else
|
||||||
|
echo "Flatpak ist nicht installiert."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Überprüfen, ob Snap installiert ist
|
||||||
|
if command -v snap &> /dev/null; then
|
||||||
|
update_snap
|
||||||
|
else
|
||||||
|
echo "Snap ist nicht installiert."
|
||||||
|
fi
|
||||||
|
|
||||||
|
time_end
|
Loading…
Reference in a new issue