mirror of
https://github.com/Snigdha-OS/snigdhaos-blackbox.git
synced 2025-09-20 19:45:02 +02:00
⚡️ perf: more improvements can be done
This commit is contained in:
@@ -12,6 +12,32 @@ usage() {
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Function to print in green (success)
|
||||||
|
success() {
|
||||||
|
echo -e "\033[32m$1\033[0m"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to print in red (error)
|
||||||
|
error() {
|
||||||
|
echo -e "\033[31m$1\033[0m"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to print in yellow (warning)
|
||||||
|
warning() {
|
||||||
|
echo -e "\033[33m$1\033[0m"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to log output to a log file
|
||||||
|
log() {
|
||||||
|
echo "$(date) - $1" >> "$LOGFILE"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Log file location
|
||||||
|
LOGFILE="/tmp/setup_script.log"
|
||||||
|
|
||||||
|
# Clear the previous log
|
||||||
|
> "$LOGFILE"
|
||||||
|
|
||||||
# Display help if the user asks for it
|
# Display help if the user asks for it
|
||||||
if [ "$1" == "--help" ]; then
|
if [ "$1" == "--help" ]; then
|
||||||
usage
|
usage
|
||||||
@@ -19,62 +45,70 @@ fi
|
|||||||
|
|
||||||
# Check if package list file is provided and valid
|
# Check if package list file is provided and valid
|
||||||
if [ -z "$2" ] || [ ! -f "$2" ]; then
|
if [ -z "$2" ] || [ ! -f "$2" ]; then
|
||||||
echo "Error: Package list file is missing or invalid."
|
error "Package list file is missing or invalid."
|
||||||
usage
|
usage
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if service script file is provided and valid
|
# Check if service script file is provided and valid
|
||||||
if [ -n "$3" ] && [ ! -f "$3" ]; then
|
if [ -n "$3" ] && [ ! -f "$3" ]; then
|
||||||
echo "Warning: Service script file ($3) not found. Skipping service enabling."
|
warning "Service script file ($3) not found. Skipping service enabling."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Step 1: Optional Setup Preparation
|
# Step 1: Optional Setup Preparation
|
||||||
if [ -n "$1" ] && [ -e "$1" ]; then
|
if [ -n "$1" ] && [ -e "$1" ]; then
|
||||||
echo ""
|
echo ""
|
||||||
echo "Preparing Setup..."
|
echo "Preparing Setup..."
|
||||||
|
log "Preparing Setup..."
|
||||||
echo ""
|
echo ""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Step 2: Installing Packages
|
# Step 2: Installing Packages
|
||||||
echo ""
|
echo ""
|
||||||
echo "Installing Packages! Please Wait..."
|
echo "Installing Packages! Please Wait..."
|
||||||
echo ""
|
log "Starting package installation..."
|
||||||
|
|
||||||
# Generate the list of installable packages
|
# Generate the list of installable packages
|
||||||
installable_packages=$(comm -12 <(pacman -Slq | sort) <(sed 's/\s/\n/g' - <"$2" | sort))
|
installable_packages=$(comm -12 <(pacman -Slq | sort) <(sed 's/\s/\n/g' - <"$2" | sort))
|
||||||
|
|
||||||
# Check if any valid packages are available
|
# Check if any valid packages are available
|
||||||
if [ -z "$installable_packages" ]; then
|
if [ -z "$installable_packages" ]; then
|
||||||
echo "No packages found to install from the provided list."
|
error "No packages found to install from the provided list."
|
||||||
|
log "No valid packages found."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Attempt to install the packages
|
# Attempt to install the packages
|
||||||
echo "Installing the following packages: $installable_packages"
|
echo "Installing the following packages: $installable_packages"
|
||||||
|
log "Installing packages: $installable_packages"
|
||||||
|
|
||||||
if ! sudo pacman -S --needed $installable_packages; then
|
if ! sudo pacman -S --needed $installable_packages; then
|
||||||
echo "Error: Package installation failed. Please check the package list and try again."
|
error "Package installation failed. Please check the package list and try again."
|
||||||
|
log "Package installation failed."
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
# Remove the package list file after successful installation
|
# Remove the package list file after successful installation
|
||||||
rm "$2"
|
rm "$2"
|
||||||
echo "Packages installed successfully."
|
success "Packages installed successfully."
|
||||||
|
log "Packages installed successfully."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Step 3: Enabling Services (if any)
|
# Step 3: Enabling Services (if any)
|
||||||
if [ -n "$3" ] && [ -f "$3" ]; then
|
if [ -n "$3" ] && [ -f "$3" ]; then
|
||||||
echo ""
|
echo ""
|
||||||
echo "Enabling Services (If Any)..."
|
echo "Enabling Services (If Any)..."
|
||||||
echo ""
|
log "Enabling services..."
|
||||||
|
|
||||||
# Execute the service script with sudo
|
# Execute the service script with sudo
|
||||||
if ! sudo bash - <"$3"; then
|
if ! sudo bash - <"$3"; then
|
||||||
echo "Error: Failed to enable services from the script. Please check the script."
|
error "Failed to enable services from the script. Please check the script."
|
||||||
|
log "Service enabling failed."
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
echo "Services enabled successfully."
|
success "Services enabled successfully."
|
||||||
|
log "Services enabled successfully."
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Final prompt
|
# Final prompt
|
||||||
echo ""
|
echo ""
|
||||||
read -p "Press Enter To Return to Snigdha OS Blackbox."
|
read -p "Press Enter to return to Snigdha OS Blackbox."
|
||||||
|
Reference in New Issue
Block a user