🐛 fix(_dir): error logger dir

This commit is contained in:
eshanized
2024-12-20 00:30:25 +05:30
parent bc4ee677a4
commit 46900f4934

View File

@@ -2,66 +2,74 @@
# Function to log messages to a log file # Function to log messages to a log file
log_message() { log_message() {
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" >> /var/log/snigdha_assistant.log # This function logs messages with a timestamp to /var/log/snigdhaos_assistant.log
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" >> /var/log/snigdhaos_assistant.log
} }
# Check if the first file (setup script) exists and execute it # Check if the first file (setup script) exists and execute it
if [ -e "$1" ]; then if [ -e "$1" ]; then
echo "" echo ""
echo "Preparing setup ⏳" echo "Preparing setup ⏳" # Show waiting emoji when preparing setup
echo "" echo ""
log_message "Executing setup script: $1" log_message "Executing setup script: $1"
if ! sudo bash - <$1; then if ! sudo bash - <$1; then
# If the setup script execution fails, print an error message with a cross emoji
echo "❌ Error executing setup script. Check logs for more details." echo "❌ Error executing setup script. Check logs for more details."
log_message "Error executing setup script: $1" log_message "Error executing setup script: $1"
exit 1 exit 1 # Exit the script if setup fails
fi fi
else else
# If the setup script doesn't exist, show a warning with a caution emoji
echo "⚠️ Setup script ($1) not found! Skipping setup." echo "⚠️ Setup script ($1) not found! Skipping setup."
log_message "Setup script ($1) not found." log_message "Setup script ($1) not found."
fi fi
# Install packages from the second file # Install packages from the second file
echo "" echo ""
echo "Installing packages 🛠️" echo "Installing packages 🛠️" # Show tools emoji for package installation
echo "" echo ""
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)) # Find common packages between the pacman repo and the list in $2
if [ -z "$installable_packages" ]; then if [ -z "$installable_packages" ]; then
# If no installable packages are found, show a warning with a caution emoji
echo "⚠️ No installable packages found. Skipping package installation." echo "⚠️ No installable packages found. Skipping package installation."
log_message "No installable packages found from $2" log_message "No installable packages found from $2"
else else
# If packages are found, list them and show a package emoji
echo "📦 The following packages will be installed: $installable_packages" echo "📦 The following packages will be installed: $installable_packages"
log_message "Installing packages: $installable_packages" log_message "Installing packages: $installable_packages"
if ! sudo pacman -S --needed $installable_packages; then if ! sudo pacman -S --needed $installable_packages; then
# If the package installation fails, show an error with a cross emoji
echo "❌ Error installing packages. Check logs for more details." echo "❌ Error installing packages. Check logs for more details."
log_message "Error installing packages: $installable_packages" log_message "Error installing packages: $installable_packages"
exit 1 exit 1 # Exit the script if package installation fails
fi fi
rm -f $2 rm -f $2 # Remove the file after successful installation
echo "✅ Packages installed successfully." echo "✅ Packages installed successfully." # Show success emoji after installation
log_message "Packages installed successfully." log_message "Packages installed successfully."
fi fi
# Check if the third file (service script) exists and execute it # Check if the third file (service script) exists and execute it
if [ -e "$3" ]; then if [ -e "$3" ]; then
echo "" echo ""
echo "Enabling services ⚙️" echo "Enabling services ⚙️" # Show gear emoji for service enabling
echo "" echo ""
log_message "Enabling services from: $3" log_message "Enabling services from: $3"
if ! sudo bash - <$3; then if ! sudo bash - <$3; then
# If enabling services fails, show an error with a cross emoji
echo "❌ Error enabling services. Check logs for more details." echo "❌ Error enabling services. Check logs for more details."
log_message "Error enabling services from: $3" log_message "Error enabling services from: $3"
exit 1 exit 1 # Exit the script if enabling services fails
fi fi
else else
# If the service script doesn't exist, show a warning with a caution emoji
echo "⚠️ Service script ($3) not found! Skipping services." echo "⚠️ Service script ($3) not found! Skipping services."
log_message "Service script ($3) not found." log_message "Service script ($3) not found."
fi fi
# Final prompt # Final prompt
echo "" echo ""
read -p "Press enter to return to Snigdha OS Assistant 🛑" read -p "Press enter to return to Snigdha OS Assistant 🛑" # Show stop sign emoji for returning to the assistant
# End of script # End of script
log_message "Script execution completed successfully 🎉" log_message "Script execution completed successfully 🎉" # Log success with a celebration emoji