Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Share your Debian SCRIPTS

Here you can discuss every aspect of Debian. Note: not for support requests!
Message
Author
User avatar
fabien
Forum Helper
Forum Helper
Posts: 688
Joined: 2019-12-03 12:51
Location: Anarres (Toulouse, France actually)
Has thanked: 62 times
Been thanked: 161 times

Re: Share your Debian SCRIPTS

#81 Post by fabien »

As I don't plan to change my apps, I have no reason to postpone.

updated apt-fly from v.3.1 to v.3.2
- working on arbitrary packages is no longer limited by the maximum length of system arguments,
in other words, it is now possible to work with as many packages as one likes
(this was previously possible, but extremely slow)

User avatar
Hallvor
Global Moderator
Global Moderator
Posts: 2044
Joined: 2009-04-16 18:35
Location: Kristiansand, Norway
Has thanked: 151 times
Been thanked: 212 times

Re: Share your Debian SCRIPTS

#82 Post by Hallvor »

A Russian Roulette Simulator - because I'm watching The Deer Hunter. ;) Disclaimer: I am not trying to trivialize a serious issue, so please don't take offense: This is for entertainment and educational use only.

Code: Select all

#!/bin/bash

echo "Welcome to the Russian Roulette Simulator!"

# Number of chambers
num_chambers=6

# Load a bullet in a random chamber
bullet_chamber=$((1 + RANDOM % num_chambers))

# Function to pull the trigger
pull_trigger() {
    outcome=$((1 + RANDOM % num_chambers))
    [ "$outcome" -eq "$bullet_chamber" ] && echo "BANG! You got the bullet. Game over!" || echo "Click. You survived this round."
}

# Prompt trigger pull
read -p "Press Enter to pull the trigger..."

# Call the pull_trigger function
pull_trigger
[HowTo] Install and configure Debian bookworm
Debian 12 | KDE Plasma | ThinkPad T440s | 4 × Intel® Core™ i7-4600U CPU @ 2.10GHz | 12 GiB RAM | Mesa Intel® HD Graphics 4400 | 1 TB SSD

User avatar
fabien
Forum Helper
Forum Helper
Posts: 688
Joined: 2019-12-03 12:51
Location: Anarres (Toulouse, France actually)
Has thanked: 62 times
Been thanked: 161 times

Re: Share your Debian SCRIPTS

#83 Post by fabien »

Hallvor wrote: 2023-12-28 22:51 A Russian Roulette Simulator
Note that this also works with the Linux kernel :lol:

Code: Select all

#!/bin/bash

echo "Welcome to the Linux Roulette Simulator!"

# Number of kernels
num_kernels=6

# sed -i 's/^GRUB_DEFAULT=[[:digit:]]$/GRUB_DEFAULT='"$((RANDOM % num_kernels))"'/' /etc/default/grub && update-grub && reboot
GRUB_default() {
    echo "Setting GRUB default boot entry..."
    outcome=$(( new_entry - RANDOM % num_kernels))
    echo "Reboot..."; sleep 1
    case "$outcome" in
       14) echo "BANG! Kernel 6.1.0-$outcome, EXT4 data corruption. Game over!";;
       15) echo "BOOM! Kernel 6.1.0-$outcome, WIFI down. Game over!";;
        *) echo "Kernel 6.1.0-$outcome. You survived this reboot."; return 0;;
    esac
    return 1
}

# apt install linux-image-amd64
read -p "Press Enter to update the kernel..."
new_entry=$(( 17 - RANDOM % num_kernels ))
(( new_entry < 17 )) && echo -e "The following NEW packages will be installed:\nlinux-image-6.1.0-$new_entry" \
                     || { echo "linux-image-amd64 is already the newest version"; exit 0; }

# update-grub and reboot
GRUB_default

User avatar
Hallvor
Global Moderator
Global Moderator
Posts: 2044
Joined: 2009-04-16 18:35
Location: Kristiansand, Norway
Has thanked: 151 times
Been thanked: 212 times

Re: Share your Debian SCRIPTS

#84 Post by Hallvor »

fabien wrote: 2023-12-29 12:27 Note that this also works with the Linux kernel :lol:
:lol:

Nothing simulates the suffering of a loss or the thrill of a click like a potential malicious command on a production machine, but I am not going down that route. :wink:
[HowTo] Install and configure Debian bookworm
Debian 12 | KDE Plasma | ThinkPad T440s | 4 × Intel® Core™ i7-4600U CPU @ 2.10GHz | 12 GiB RAM | Mesa Intel® HD Graphics 4400 | 1 TB SSD

User avatar
FreewheelinFrank
Global Moderator
Global Moderator
Posts: 2117
Joined: 2010-06-07 16:59
Has thanked: 38 times
Been thanked: 232 times

Re: Share your Debian SCRIPTS

#85 Post by FreewheelinFrank »

An XFCE genmon script to notify of unread mails in Claws Mail with Gmail.

Claws Mail will not notify of unread emails with Gmail, because it uses the IMAP "new" tag for notifications, which Google does not implement. Claws Mail won't fix this because Google is not following standards. There is a patch for Claws Mail 4.1 to notify of unread mails, which involves compiling Claws Mail. I did this for 4.1, but some of the plugins and spell checking didn't work, and with the update to 4.2, I decided to write a Genmon script to notify of unread mail, using Claws Mail terminal output.

This is the result:

Image

The script uses the Claws Mail NewMail plugin to display the header of any unread mail. It's a bit flakey at times, but sometimes works nicely, as above. Other times it doesn't print headers, or prints header from old mail that has been filtered to the bin (despite setting Claws Mail not to scan the bin for new mail). My current theory is that it works best if the "all mail" folder is selected in Claws Mail.

I used a system icon for new mail, and greyed it out for the "no mail" icon. There are "no mail" icons available in installed icons, but I didn't like any of them.


Image

Code: Select all

#!/bin/bash
allmail=$(claws-mail --status "#imap/<Gmail address>/[Google Mail]/All Mail" | awk '{print $2}')
inbox=$(claws-mail --status "#imap/<Gmail address>/INBOX" | awk '{print $2}')
lines=$(( $allmail * 10 ))
echo $lines
lastmails=$(tail -$lines /home/donald/Mail/NewLog | sed -e:b -e'$!{N;2,9bb' -e\} -e'/.*'Folder:[[:space:]]*Bin'/!P;D'| grep 'Date\|Subject\|From\|---' | sed 's/^\(.\{50\}\).*$/\1/' | sed 's/&/\&#038;/g' | sed 's/</\&#8249;/g' |sed 's/>/\&#8250;/g' | sed 's/Date://g;s/Subject://g;s/From://g' | sed -e 's/^[ \t]*//' | sed 's/+0000//' | sed 's/---//')
unread=$allmail
notifiedemails=$(cat /home/<user name>/Mail/count)
if [ $notifiedemails -gt $unread ] ; then
 echo "0" > /home/<user name>/Mail/count
fi
if [ $unread -gt 0 ] && [ $unread -gt $notifiedemails ] ; then
 canberra-gtk-play -i message 
 $(notify-send --hint=int:transient:1 --icon=internet-mail "Claws Mail" "$unread Unread Mail")
 echo $unread > /home/<user name>/Mail/count
fi
if [ $unread -gt 0 ] ; then
PANEL="<icon>mail-mark-unread</icon>"
PANEL+="<iconclick>./refresh.sh</iconclick>"

TOOLTIP="<tool>"
TOOLTIP+="<span weight='bold'>Unread Emails:  </span>\n"
TOOLTIP+="Inbox:  $inbox\n"
TOOLTIP+="All Mail:  $allmail\n"
TOOLTIP+="$lastmails\n\n"
TOOLTIP+="<span weight='bold'>Click to update</span>"
TOOLTIP+="</tool>"
else
echo $unread > /home/<user name>/Mail/count
#echo -n > /home/<user name>/Mail/NewLog
PANEL="<img>/home/<user name>/applications-email-panel.png</img>"
PANEL+="<click>./panelclick.sh</click>"

TOOLTIP="<tool>"
TOOLTIP+="<span weight='bold'>No unread emails</span>\n"
TOOLTIP+="Check for new mail"
TOOLTIP+="</tool>"
fi

  echo -e "${PANEL}"
  echo -e "${TOOLTIP}"
I don't know scripting - it's just hacked together from bits of code from the internet - so it may not be the best code, but it works. Instructions are for other people like me who just dabble.

The commented-out line will delete the new mail log from time to time. I wondered if that was causing problems and commented it out.

Replace <Gmail address> and <user name> with personal address/user name.

The script needs two other scripts to work. Save as executable files in home directory, or directory of your choice but modify script accordingly. Not sure if they could have been incorporated in the main script.

panelclick.sh

Code: Select all

#!/bin/bash
claws-mail --receive
notify-send -t 5000 --hint=int:transient:1 "Claws Mail" "Checking for new messages" -i xfce-newmail
xfce4-panel --plugin-event=genmon-<n>:refresh:bool:true
allmail=$(claws-mail --status "#imap/<Gmail address>/[Google Mail]/All Mail" | awk '{print $2}')
if [ $allmail == 0 ]; then
echo -n > /<user name>/Mail/NewLog
fi
Replace <n> with the genmon instance in Panel Preferences. (Hover to view).

refresh.sh

Code: Select all

#!/bin/bash
allmailold=$(claws-mail --status "#imap/<Gmail address>/[Google Mail]/All Mail" | awk '{print $2}')
xfce4-panel --plugin-event=genmon-<n>:refresh:bool:true
allmailnew=$(claws-mail --status "#imap/<Gmail address>/[Google Mail]/All Mail" | awk '{print $2}')
new=$((allmailnew - allmailold))

if [ $allmailnew == $allmailold ] && [  $allmailnew -gt 0 ] ; then
  notify-send -t 5000 --hint=int:transient:1 "Claws Mail" "No new mail \n$allmailnew unread" -i xfce-newmail
fi
if [ $allmailnew == 0 ] ; then
 notify-send -t 5000 --hint=int:transient:1 "Claws Mail" "All mail read" -i xfce-newmail
fi
if [ $allmailnew -gt $allmailold ] ; then
  notify-send -t 5000 --hint=int:transient:1 "Claws Mail" "$new new \n$allmailnew unread" -i xfce-newmail
fi
Again replace <n> with the genmon instance in Panel Preferences. (Hover to view).

Edit 6/1/24

Added a bit of code to remove emails sent to the bin after a certain date, which the NewMail plugin adds to the file of new mail headers for some reason, before displaying in the tooltip. Modified from answer 10 here:

https://unix.stackexchange.com/question ... sed-or-awk

User avatar
fabien
Forum Helper
Forum Helper
Posts: 688
Joined: 2019-12-03 12:51
Location: Anarres (Toulouse, France actually)
Has thanked: 62 times
Been thanked: 161 times

Re: Share your Debian SCRIPTS

#86 Post by fabien »

Never say never (which I didn't)

updated apt-fly from v.3.2 to v.3.3
- if the Release file of a Debian (apt) repository does not contain the
'No-Support-for-Architecture-all: Packages' field, clients split the Packages files between
'binary-all_Packages' and 'binary-$ARCH_Packages'. This is not yet the case for Debian
repositories, but it is for some repositories. This version takes this into account, and
this has also been corrected in schow-pkg v.5.1 and why-pkg v.0.11a.
- the Debian Policy Manual does not stipulate that the Package: field must be placed in the first
position in the stanza, and some (non-Debian) repositories actually place it elsewhere.
This can have consequences and has been corrected in this version as well as in schow-pkg v.5.1
and why-pkg v.0.11a.

updated schow-pkg from 5.0 to 5.1
- new -I option: show not installed packages only
- new -W option: pass the arguments to why-pkg

updated why-pkg from v.0.10a v.0.11a
- due to occurrences, a warning is issued if the APT database has not been correctly updated (f_audit)
- remaining dependencies on debtags have been removed and its installation is discouraged
- new Bash completion function, please update /etc/bash_completion.d/why-pkg
- added 'provided by' information for real packages when using c/C/y/Y options (f_why)
- new -Z option: count all possible installed reverse dependencies for each package (f_reverse)

Post Reply