Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crontab not found #1

Closed
S7venLights opened this issue Feb 4, 2023 · 36 comments
Closed

Crontab not found #1

S7venLights opened this issue Feb 4, 2023 · 36 comments

Comments

@S7venLights
Copy link

S7venLights commented Feb 4, 2023

Hi thanks for this script, I installed and waiting to see if it works (doesn't seem to be).

But had this warning when installing:

$ cd Battery-Notifier
[@fedora Battery-Notifier]$ sh install.sh

Battery Notifier

Installing in /var/home/User/laptop_battery_notify ...

Fixing permissions ...

Please select if you're using a dark or light theme

  1. Dark
  2. Light

Setting up cronjob ...
install.sh: line 37: crontab: command not found
install.sh: line 37: crontab: command not found


Also is it fine to edit the .sh and change the % values to ones of your own choosing?

Finally is there a way to set it to play a custom sound? Like a voice recording that says Battery low, please charge?

@StellarSand
Copy link
Owner

I forgot this project existed 😛 . Will fix issues and update it in a few days.

Also is it fine to edit the .sh and change the % values to ones of your own choosing?

I'll update it so in the future you can do battery-notify --max 60 --min 20 something like that. This way the script itself doesn't have to be modified every time.

Finally is there a way to set it to play a custom sound? Like a voice recording that says Battery low, please charge?

Can be done if I implement an option to play custom audio file like battery-notify --sound /path/to/audio_file

@S7venLights
Copy link
Author

S7venLights commented Feb 5, 2023

Okay great thanks! 😎 I can share some nice audio for the battery notification.

Also being able to set notifications at different % values could help EG every 5 or 10%

This way if you miss the first notification you can catch the next…

Alternatively the notification can repeat until the PC is unplugged or plugged

@StellarSand
Copy link
Owner

fixed in latest update.

@S7venLights
Copy link
Author

🙏 Thanks, I will test tonight!

@S7venLights
Copy link
Author

S7venLights commented Feb 9, 2023

Okay, so I use Fedora Kionite and it has an immutable/read only filesystem, so it can't install to the default location, soI had to change all the
/usr/bin/ directories to a folder in my home directory

Then I ran:

[user@fedora Battery-Notifier]$ sh install.sh
Installing ...
[sudo] password for user: 
Done.

Fixing permissions ...
Done.

Setting up service ...
Created symlink /etc/systemd/system/multi-user.target.wants/battery-notify.service → /etc/systemd/system/battery-notify.service.
Done.

install.sh: line 54: battery-notify: command not found

One file, battery-notify had been created at my ser home directory
then


cd Battery-Notifier
[user@fedora Battery-Notifier]$ battery-notify -c 75 -l 56
bash: battery-notify: command not found

I also tried cd to the install folder in my home directory but it didn't work (No such file or directory)

So I tried to uninstall and change my directory to the same directory that git clone had created:

But that didn't work either with the same errors: install.sh: line 54: battery-notify: command not found

Perhaps there's another equivalent directory to user/bin I'm meant to use?

Just found this:
Fedora Silverblue/Kionite filesystem layout

On Fedora Silverblue, the root filesystem is immutable. This means that /, /usr and everything below it is read-only.

/var is where all of Fedora Silverblue’s runtime state is stored. Symlinks are used to make traditional state-carrying directories available in their expected locations. This includes:

/home → /var/home

/opt → /var/opt

/srv → /var/srv

/root → /var/roothome

/usr/local → /var/usrlocal

/mnt→ /var/mnt

/tmp → /sysroot/tmp

This means that separate home partitions should be mounted on /var/home.

@S7venLights
Copy link
Author

S7venLights commented Feb 9, 2023

So ran the uninstall proceedure, then I tried a find and replace on all the Git cloned files to replace:
/usr/local/bin/
with
/var/usrlocal/bin/

Here was the result:

[user@fedora Battery-Notifier]$ sh install.sh
Installing ...
[sudo] password for D24: 
Done.

Fixing permissions ...
Done.

Setting up service ...
Created symlink /etc/systemd/system/multi-user.target.wants/battery-notify.service → /etc/systemd/system/battery-notify.service.
Done.

install.sh: line 54: /usr/local/bin/battery-notify: cannot execute: required file not found
[user@fedora Battery-Notifier]$ battery-notify -h
bash: /usr/local/bin/battery-notify: cannot execute: required file not found
[user@fedora Battery-Notifier]$ 

So I ran the uninstall procedure and I await your advice if possible please.
PS when I ran the uninstall procedure it left the batery-notify file in /var/usrlocal/bin/

Here is another shell script that allowed installations on Kionite, maybe there's something to glean from it:
safing/portmaster-packaging#56 (comment)

@StellarSand
Copy link
Owner

Alright I will look into it tomorrow and test on fedora kionite and silverblue.

@S7venLights
Copy link
Author

Thanks hey, If it makes your life easier you could advise which path to use and I could test for you.

@S7venLights
Copy link
Author

What do you think?

@StellarSand
Copy link
Owner

StellarSand commented Feb 19, 2023

Okay so I did test it, but haven't got time to push an update yet. So here's what you can do manually for the time being.

  • You already mentioned you changed all the /usr/bin to a folder in your home directory.

  • Now find the ExecStart line and change the directory in service file.

  • You also can't do battery-notify -c 75 -l 56 straightaway. Instead you need to do /path/to/installed/script -c 75 -l 56.

  • Alternatively if you want to use battery-notify -c 75 -l 56 without the path every time, you can set a path variable by including the following line at the end in the ~/.bashrc file:
    export PATH=$PATH:/path/to/installed/script

    Other than that I'll fix this next week probably.

@S7venLights
Copy link
Author

🙏 Thanks, I'll test if I get time this week otherwise I look forward to the update and I'll share with people if you think it's ready

@S7venLights
Copy link
Author

Maybe this weekend?

@S7venLights
Copy link
Author

  • Now find the ExecStart line and change the directory in service file.

This is what I have in the batterynotify.service file before install :
ExecStart=/bin/bash /var/usrlocal/bin/battery-notify

Is that correct? Cos I still see this when I install:

[D24@fedora Battery-Notifier]$ sh ./install.shInstalling ...
[sudo] password for D24: 
Done.

Fixing permissions ...
Done.

Setting up service ...
Created symlink /etc/systemd/system/multi-user.target.wants/battery-notify.service → /etc/systemd/system/battery-notify.service.
Done.

./install.sh: line 54: /usr/local/bin/battery-notify: cannot execute: required file not found

One file 'battery-notify' is created at /var/usrlocal/bin/

I then did the following:

cd /var/usrlocal/bin/

battery-notify -c 75 -l 56

bash: /usr/local/bin/battery-notify: cannot execute: required file not found

sudo battery-notify -c 75 -l 56

sudo: unable to execute /usr/local/bin/battery-notify: No such file or directory

So I'm not sure what's wrong cos the file is there...
Maybe it's a read only directory

@S7venLights
Copy link
Author

S7venLights commented Mar 10, 2023

So I uninstalled and...

According to this script, I changed the install dir to: "var/lib/battery_notifier"

I also changed the line in the uninstall sh to:
install_dir="var/lib/battery_notifier"

Then reinstalled:

[user@fedora ~]$ sudo mkdir -p /var/lib/battery_notifier
[user@fedora ~]$ cd Battery-Notifier[D24@fedora Battery-Notifier]$ chmod +x install.sh
[user@fedora Battery-Notifier]$ sh ./install.shInstalling ...
Done.

Fixing permissions ...
Done.

Setting up service ...
Created symlink /etc/systemd/system/multi-user.target.wants/battery-notify.service → /etc/systemd/system/battery-notify.service.
Done.

./install.sh: line 54: battery-notify: command not found

Same errors as before and also only 1 file created at the directory

I also tested an install by making the .service file line:
ExecStart=/var/lib/battery_notifier/battery-notify
But same error as before
"line 54: battery-notify: command not found"

@S7venLights
Copy link
Author

S7venLights commented Mar 10, 2023

I also noticed the uninstall didn't remove: var/lib/battery_notifier/battery-notify or /etc/systemd/system/battery-notify.service

and 'battery-notify.service' was registering as a 'D-bus service file' and not a 'systemd unit file' like the others.
Not sure if that's a bad thing? I just noticed.

@WinkelCode
Copy link

Please try my install script: https://gist.github.com/WinkelCode/168028a9e20baa4393a60791cdb7e4b9

@S7venLights
Copy link
Author

Wow thanks so much, I'll try it in a moment!

@S7venLights
Copy link
Author

S7venLights commented Mar 14, 2023

Okay I've installed it and still waiting to see if it works but thought I'd share the setup steps for future users:

see issue: #1

  1. In CLI
    git clone https://github.com/the-weird-aquarian/Battery-Notifier.git

  2. Download the script using the 'Download Zip' Button on the Github link

  3. Extract the "battery-notify4silverblue.sh" file and put it in the home directory folder /var/home/YourUserName/Battery-Notifier/

  4. Right click on the file and go to properties and make it executable [May not be needed?]

  5. cd /var/home/YourUserName/Battery-Notifier/

  6. sh ./battery-notify4silverblue.sh install YourUserName

  7. You should see something like this:

OK: Installed battery-notify
OK: Installed battery-notify systemd unit
OK: Told sed to set 'User=D24' in battery-notify systemd unit
OK: Created profile.d script
OK: Enabled and started systemd unit
Done. Restart your shell or run 'source /etc/profile.d/zzz-battery-notify-add-to-path.sh' to add battery
-notify to your PATH variable

  1. source /etc/profile.d/zzz-battery-notify-add-to-path.sh

  2. Now you can change the settings of the installed app by using the app instructions:

First
cd /var/lib/battery-notify/

Available options
-h, --help Show this help message
-c, --charged Set battery charged percent (default = 80)
-l, --low Set battery low percent (default = 20)
-s, --sound Set custom notification sound
-r, --repeat Repeat notification at set interval (in seconds)
Default = 60 seconds, 0 = Notify only once

Usage
battery-notify -c 60 -l 40
Show notification every 15 seconds
battery-notify -r 15

  1. To uninstall:
    cd /var/home/YourUserName/Battery-Notifier/
    sh ./battery-notify4silverblue.sh uninstall

  2. See next comment for some notes.

@WinkelCode
Copy link

WinkelCode commented Mar 14, 2023

A few notes:

  • You don't need to enter the username when uninstalling
  • It is almost certainly possible to make it installable for users separately, but I have just copied what the original script does with some changes
  • You can change the paths in the script to wherever you like via the variables near the top
  • The script works without sudo installed, though I only implemented self-elevation for sudo, but it will notice if it already runs as root
  • I didn't have a battery in the machine I tested it with so I don't know if it works for sure, but from the testing I did, the script was in the path and executable. The main untested thing is the systemd unit.

Edit:

  • The script installs the program's file into "/var/lib/battery-notify", the downloaded folder can be deleted afterwards.
  • The battery-notifiy4silverblue.sh script just needs to be in the same place as battery-notifier.sh and the .service file.

@S7venLights
Copy link
Author

Thanks Unfortunately it seems to not notify me at all, but maybe the service isn't running, I will try restart.

@WinkelCode
Copy link

Thanks Unfortunately it seems to not notify me at all, but maybe the service isn't running, I will try restart.

It just came to me that I totally forgot to fix the path for the service. That's why it doesn't work.

I'll update the script

@WinkelCode
Copy link

WinkelCode commented Mar 14, 2023

Please try the new version (revision 8), it should work now. I also added output for the uninstall process steps and made it so it only checks for the "required files" when installing.

Edit: (Revision 10), revised sed expression, no more issues when running twice over the same file and added grep command that verifies if the modifications were done correctly.

@S7venLights
Copy link
Author

Must I uninstall before running the new script?

@WinkelCode
Copy link

WinkelCode commented Mar 14, 2023

Must I uninstall before running the new script?

If you used the previous version of my script you can just run the install instruction again, you can also do this if you wish to change the username which the service runs with.

The only time you need to uninstall first is if you change an installation location inside the script file (i.e. targetloc_prog_directory), that is if you don't plan on changing it to the same location again.

@S7venLights
Copy link
Author

Okay the service is running and I'm testing now, waiting for battery to charge.

I was wondering though if it's worth improving the security of the service file using the portmaster file as an example, this is what i came up with:

[Unit]
Description=Battery Notify Service

[Service]
User=
Restart=always # Restart service when it exits, crashes, or is otherwise stopped
RestartSec=5 # Restart after 5 seconds of crashing, exiting etc
LockPersonality=yes
MemoryDenyWriteExecute=yes
NoNewPrivileges=yes
PrivateTmp=yes
ProtectSystem=true
#ReadWritePaths=/var/lib/battery-notify
RestrictNamespaces=yes
ProtectHome=read-only
ProtectKernelTunables=yes
ProtectKernelLogs=yes
ProtectControlGroups=yes
PrivateDevices=yes
ExecStart=/var/lib/battery-notify/battery-notify --data /var/lib/battery-notify

[Install]
WantedBy=multi-user.target

@WinkelCode
Copy link

The author, @the-weird-aquarian would have to look into that, I am not too familiar with systemd units and I don't know what features they might want to add that could conflict with these restrictions.

@S7venLights
Copy link
Author

S7venLights commented Mar 14, 2023

Okay well as I said the service is running and I set my notification to go off at 75% but it hasn't gone off even if over 75%, and EDIT no notification at 81%

@WinkelCode
Copy link

Okay well as I said the service is running and I set my notification to go off at 75% but it hasn't gone off even if over 75%, and EDIT no notification at 81%

Troubleshooting this would require me to either test it on some device that has a battery, or (more practically) use a fake/simulated battery kernel module. I'd be happy to do that, I am actually curious why it doesn't work, but I have more pressing stuff to finally get done right now. Maybe I can fit it in in the next few days, but no guarantees.

@S7venLights
Copy link
Author

S7venLights commented Mar 14, 2023

Yes, no of course. You've done a lot already.

Out of interest
A while ago I searched for battery notifier apps and these are the only others that came close:
https://github.com/duttaprasanta/battery_alert (Feature rich but I'm not sure how to install on Fedora)
and https://github.com/HxnDev/Battery-Percentage-Notifier/blob/main/main.py (simple and not sure how to install)

@S7venLights
Copy link
Author

Hi guys so, what would it take to get this over the line?
Is the issue with the script or the app?
Maybe the script installs it well but the app just isn't working as intended?
@WinkelCode should we consider using this other app

@WinkelCode
Copy link

WinkelCode commented Mar 29, 2023

Hi guys so, what would it take to get this over the line?
Is the issue with the script or the app?
Maybe the script installs it well but the app just isn't working as intended?
@WinkelCode should we consider using this other app

I actually recently wrote a script for my SteamDeck to keep the battery between 45 and 55% while plugged in, which obviously works with immutable systems. It should be trivial to modify it for this purpose, the only thing is I’d have to research how sending the notification is implemented in bash scripts. I’ll get back to you when I figure it out.

@S7venLights
Copy link
Author

Okay perfect!

@S7venLights
Copy link
Author

Any chance we can solve this soon or should I look at duttaprasanta/battery_alert#4

@WinkelCode
Copy link

Not sure what functionality you are looking for, I wrote this Systemd unit that contains a basic battery level notification system: https://gist.github.com/WinkelCode/3c87dfc2a96d0263a03d240c8bb8786d

(Check the gist description for installation infos)

If you run into any issues, run journalctl --user -u user-battery-notify.service -r to see the logs.

@S7venLights
Copy link
Author

Will have a look, thanks

@S7venLights
Copy link
Author

Not sure what functionality you are looking for, I wrote this Systemd unit that contains a basic battery level notification system: https://gist.github.com/WinkelCode/3c87dfc2a96d0263a03d240c8bb8786d

I had a look, it seems like that notifies when you battery is low at 35%, am I right?
I was wondering about this which you mentioned before:

I actually recently wrote a script for my SteamDeck to keep the battery between 45 and 55% while plugged in, which obviously works with immutable systems. It should be trivial to modify it for this purpose, the only thing is I’d have to research how sending the notification is implemented in bash scripts. I’ll get back to you when I figure it out.

Or fixing this script: https://gist.github.com/WinkelCode/168028a9e20baa4393a60791cdb7e4b9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants