-
Notifications
You must be signed in to change notification settings - Fork 0
/
system_update.sh
executable file
·48 lines (40 loc) · 1.05 KB
/
system_update.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
# Define the log directory
LOG_DIR="updates"
# Create the log directory if it doesn't exist
mkdir -p "$LOG_DIR"
# Generate a unique timestamp for the log file
TIMESTAMP=$(date +%Y%m%d%H%M%S)
LOG_FILE="$LOG_DIR/update_$TIMESTAMP.log"
# Function to display usage information
display_usage() {
echo "Usage: $0 [-h]"
echo "Options:"
echo " -h Show this help message"
}
# Parse command line options
HELP=0
while getopts "h" opt; do
case ${opt} in
h ) HELP=1;;
\? ) display_usage
exit 1;;
esac
done
if [ "$HELP" -eq "1" ]; then
display_usage
exit 0
fi
# Ask for user confirmation before updating
read -p "Are you sure you want to update the system? (y/n) " -n 1 -r
echo # move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]; then
# Update the system and append output to the log file
echo "Updating system..."
if pacman -Syu | tee -a "$LOG_FILE"; then
echo "System update completed. See $LOG_FILE for details."
else
echo "System update failed. See $LOG_FILE for details."
exit 1
fi
fi