Skip to content

Commit

Permalink
implemented scheduling
Browse files Browse the repository at this point in the history
  • Loading branch information
anantdark authored Jun 13, 2023
1 parent ae7cbba commit 0200cca
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 81 deletions.
File renamed without changes
File renamed without changes.
File renamed without changes.
123 changes: 42 additions & 81 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
#!/bin/bash

# Function to check internet connectivity
check_internet() {
if ! ping -c 1 google.com &> /dev/null; then
echo "Please connect to the internet and try again."
exit 1
fi
}


animation() {
echo " ___ ___ ___ "
echo "| | |\ | | | |\ | | "
Expand Down Expand Up @@ -54,93 +45,66 @@ USERNAME=$(logname)
install() {
# Create the necessary directories
(
echo "Copying necessary files"
mkdir -p /home/$USERNAME/wallpaperchanger
# Copy the Folder
cp -r bin/ /home/$USERNAME/.local/share/wallpaperchanger

# Copy the Python script
cp main.py /home/$USERNAME/wallpaperchanger/

# Copy the requirements file
cp requirements.txt /home/$USERNAME/wallpaperchanger/

# Copy the Icon file
cp awf.svg /home/$USERNAME/wallpaperchanger/
sleep 1
sleep 2
echo "Files Copied."

sleep 1
# Set the ownership and permissions
echo "setting file ownsership"
chown -R $USERNAME:$USERNAME /home/$USERNAME/wallpaperchanger
chmod +x /home/$USERNAME/wallpaperchanger/main.py
chown -R $USERNAME:$USERNAME /home/$USERNAME/.local/share/wallpaperchanger
chmod +x /home/$USERNAME/.local/share/wallpaperchanger/main.py
echo "done")&

progress_bar $!
wait
progress 1

# Prompt to install requirements
read -s -N 1 -p "Do you want to install the required packages? [Y/n]: " install_requirements
echo
read -s -N 1 -p "Do you want to install the required packages? [y/n]: " install_requirements
echo ""

(if [ "$install_requirements" = "n" ] || [ "$install_requirements" = "N" ]; then
echo "Skipping installation of requirements."
sleep 1
else
# Install requirements
echo "Installing requirements"
pip3 install --no-cache-dir -r /home/$USERNAME/wallpaperchanger/requirements.txt
pip3 install --no-cache-dir -r /home/$USERNAME/.local/share/wallpaperchanger/requirements.txt
sleep 1
fi)&
fi

# Create a desktop entry
echo ""
echo "Creating Desktop entry"
desktop_entry="/home/$USERNAME/.local/share/applications/bing-wallpaper.desktop"
sleep 1
echo -e "[Desktop Entry]\nType=Application\nCategories=Utility\nComment=New Wallpaper Everyday\nName=Bing Wallpaper\nExec=/usr/bin/python3 /home/$USERNAME/.local/share/wallpaperchanger/main.py\nTerminal=false\nIcon=/home/$USERNAME/.local/share/wallpaperchanger/awf.svg" > "$desktop_entry"
chmod +x "$desktop_entry"
chown $USERNAME:$USERNAME "$desktop_entry"
sleep 1
echo "Desktop entry created: $desktop_entry. Use it to run the script.")&
progress_bar $!
wait
progress 1

# Prompt to schedule the script with cron or create a desktop entry
read -s -N 1 -p "Do you want to schedule the script? [Y/n]: " schedule_script

# Prompt to schedule the script or create a desktop entry
read -s -N 1 -p "Do you want to schedule the script? [y/n]: " schedule_script
echo ""
(if [ "$schedule_script" = "n" ] || [ "$schedule_script" = "N" ]; then
# Create a desktop entry
echo ""
echo "Creating Desktop entry"
desktop_entry="/home/$USERNAME/.local/share/applications/bing-wallpaper.desktop"
sleep 1
echo -e "[Desktop Entry]\nType=Application\nName=Bing Wallpaper\nExec=/usr/bin/python3 /home/$USERNAME/wallpaperchanger/main.py\nTerminal=false\nIcon=/home/$USERNAME/wallpaperchanger/awf.svg" > "$desktop_entry"
chmod +x "$desktop_entry"
chown $USERNAME:$USERNAME "$desktop_entry"
sleep 1
echo "Desktop entry created: $desktop_entry. Use it to run the script."
else
echo ""
echo "Cron functionality is still a work in progress."
sleep 1
echo "Creating a desktop entry instead."


# read -p "Do you want to schedule the script with cron? (y/n): " schedule_with_cron
# if [ "$schedule_with_cron" = "y" ] || [ "$schedule_with_cron" = "Y" ]; then
# if crontab -u $USERNAME -l >/dev/null 2>&1; then
# # Append the cron job if the crontab exists
# (crontab -u $USERNAME -l; echo "*/5 * * * * /usr/bin/python3 /home/$USERNAME/wallpaperchanger/main.py") | crontab -u $USERNAME -
# else
# # Create a new crontab with the cron job
# echo "export DISPLAY=:0 && */5 * * * * /usr/bin/python3 /home/$USERNAME/wallpaperchanger/main.py >> /home/$USERNAME/wallpaperchanger/logfile.log" | crontab -u $USERNAME -
# fi

# # Check if the cron job was added successfully
# if crontab -u $USERNAME -l | grep -q "/home/$USERNAME/wallpaperchanger/main.py"; then
# echo "Cron job added successfully."
# else
# echo "Failed to add cron job."
# fi

# Create a desktop entry
desktop_entry="/home/$USERNAME/.local/share/applications/bing-wallpaper.desktop"
echo -e "[Desktop Entry]\nType=Application\nName=Bing Wallpaper\nExec=/usr/bin/python3 /home/$USERNAME/wallpaperchanger/main.py\nTerminal=false\nIcon=/home/$USERNAME/wallpaperchanger/awf.svg" > "$desktop_entry"
desktop_entry="/home/$USERNAME/.config/autostart/bing-wallpaper.desktop"
echo -e "[Desktop Entry]\nType=Application\nCategories=Utility\nComment=New Wallpaper Everyday\nName=Bing Wallpaper\nExec=/usr/bin/python3 /home/$USERNAME/.local/share/wallpaperchanger/main.py\nTerminal=false\nIcon=/home/$USERNAME/.local/share/wallpaperchanger/awf.svg" > "$desktop_entry"
chmod +x "$desktop_entry"
chown $USERNAME:$USERNAME "$desktop_entry"
sleep 1
echo "Desktop entry created: $desktop_entry. Use it to run the script."
echo "Wallpaper Changer scheduled, Enjoy Fresh Wallpapers"
sleep 2
fi)&
progress_bar $!
wait
Expand All @@ -152,26 +116,14 @@ uninstall() {
(echo ""
echo "performing uninstallation"
# Remove the installed files
if [ -d "/home/$USERNAME/wallpaperchanger" ]; then
rm -rf "/home/$USERNAME/wallpaperchanger"
echo "Wallpaper changer folder removed."
if [ -d "/home/$USERNAME/.local/share/wallpaperchanger" ]; then
rm -rf "/home/$USERNAME/.local/share/wallpaperchanger"
echo "Wallpaper changer Uninstalled."
sleep 1
else
echo "No wallpaper changer folder found."
echo "No Wallpaper changer installation found."
sleep 1
fi


# Remove the cron job if present
if crontab -l -u $USERNAME | grep -q "/home/$USERNAME/wallpaperchanger/main.py"; then
crontab -l -u $USERNAME | grep -v "/home/$USERNAME/wallpaperchanger/main.py" | crontab -u $USERNAME -
echo "Cron job removed."
sleep 1
else
echo "No cron job found."
sleep 1
fi

# Remove the desktop entry if present
desktop_entry="/home/$USERNAME/.local/share/applications/bing-wallpaper.desktop"
if [ -f "$desktop_entry" ]; then
Expand All @@ -182,6 +134,16 @@ uninstall() {
echo "No desktop entry found."
sleep 1
fi
# Remove the scheduler entry if present
desktop_entry="/home/$USERNAME/.config/autostart/bing-wallpaper.desktop"
if [ -f "$desktop_entry" ]; then
rm "$desktop_entry"
echo "Scheduler entry removed."
sleep 1
else
echo "No scheduler entry found."
sleep 1
fi

echo "Uninstallation completed successfully.")&
progress_bar $!
Expand All @@ -201,7 +163,6 @@ fi
case $1 in
--install)
animation
check_internet
install
;;
--uninstall)
Expand All @@ -214,4 +175,4 @@ case $1 in
;;
esac

echo "AUTHOR: ANANT"
echo "AUTHOR: ANANT"

0 comments on commit 0200cca

Please sign in to comment.