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

Externalise all commands from code #31

Closed
btd1337 opened this issue Nov 12, 2018 · 28 comments
Closed

Externalise all commands from code #31

btd1337 opened this issue Nov 12, 2018 · 28 comments
Assignees
Labels
Milestone

Comments

@btd1337
Copy link
Contributor

btd1337 commented Nov 12, 2018

@babluboy Congratulations on your great work on Nutty!

Is It possible you to add support to Arch Linux? Some features aren't working...

@babluboy
Copy link
Owner

@btd1337 Thanks for your interest in nutty. At the moment I’m building for Elementary OS, but longer term plan is to make it compatible with other distros.
Someone has built the AUR package for nutty here.
https://aur.archlinux.org/packages/nutty-git/

Please update this ticket and the aur link above with the features which are not working and depending on what needs fixing either I or the aur maintainer will take a look.

Probably the AUR maintainer would suggest if the code has an issue or if it’s a library in Arch that is missing...

@btd1337
Copy link
Contributor Author

btd1337 commented Nov 13, 2018

I believe the problem is the commands used.

Network commands for Arch Linux are a bit different from Ubuntu.

Ping test fail:
captura de tela de 2018-11-12 22-06-29

Devices detect fail:
captura de tela de 2018-11-12 22-05-53

Network usage data fail:
captura de tela de 2018-11-12 22-07-10

I believe that something like this would solve the problem and it would be easier to get helpers:

switch(command) {
  case Distro-Ubuntu: execute 'X'; break;
  case Distro-Arch: execute 'Y'; break;
  case Disto-Fedora: execute 'Z'; break;
  defaut: execute 'K';
}

@babluboy
Copy link
Owner

babluboy commented Nov 13, 2018

@btd1337 This is very helpful. I have externalized most of the commands that Nutty executes in script files. So the actual commands can be modified in the scripts like nmap, nethogs, etc. Probably you can modify them to get most of the application working. The scripts are installed in the /usr/share/nutty/scripts/ directory.
I will update the code to ensure no external command is hardcoded within the code and move them to the scripts. Then we can identify the OS during installation and change the scripts as part of the meson build. We can then have the If - then - else you have mentioned as part of the install script. What do you feel about this approach ?

@btd1337
Copy link
Contributor Author

btd1337 commented Nov 14, 2018

It's a good way!

@babluboy babluboy changed the title Arch Linux Support Externalise all commands from code Nov 29, 2018
@babluboy
Copy link
Owner

@btd1337 I have now got all the command line programs that nutty uses externalised into scripts located in the /usr/share/com.github.babluboy.nutty/scripts/ directory.

You can get the changes by running the following commands:

cd ~
git clone https://github.com/babluboy/nutty.git
cd nutty
meson build --prefix=/usr
mkdir build && cd build
ninja
sudo ninja install

Try and replace the commands - for example in nutty_nethogs_script.sh with the Arch equivalent for the same - and see if the code is able to parse the output. I'm assuming that the arch equivalent for nethogs will be producing the same output format as the one on Ubuntu and the code should parse the command output correctly.

Once you have got the Arch equivalents of all the scripts in the /usr/share/com.github.babluboy.nutty/scripts/ directory, do provide them here so that I can update the ninja install to try and use the Arch scripts instead of the Ubuntu scripts if I can detect somehow that the OS is Arch during installation

Let me know how it goes, and thanks again for your interest in Nutty.

@babluboy babluboy self-assigned this Nov 29, 2018
@babluboy babluboy added enhancement completed Code Fix Issued labels Nov 29, 2018
@babluboy babluboy added this to the 1.1.1 milestone Nov 29, 2018
@btd1337
Copy link
Contributor Author

btd1337 commented Nov 30, 2018

Is this normal?

captura de tela de 2018-11-29 22-44-42

@babluboy
Copy link
Owner

Looks like you have the latest code as I introduced the error message bar recently. If I understand correctly the error is around permissions to execute the script which is odd. Can you try executing the script in terminal ?

@btd1337
Copy link
Contributor Author

btd1337 commented Nov 30, 2018

The problem is apparently permission. I think Nutty could ask for root password to solve this problem.

@babluboy
Copy link
Owner

Yes, I use pkexec in the code to let Nutty ask for the sudo password when invoking the scripts that use it. Are you saying pkexec is not working on Arch and is not prompting you a dialog like the below? Do we need to install pkexec for Arch to make this work?

pkexec

@babluboy
Copy link
Owner

Is this normal?

captura de tela de 2018-11-29 22-44-42

In this section, none of the commands require root permissions to run. Is this a problem in the way the scripts are installed and it does not let the user with which Nutty is being run execute the script? That might be the issue. Here is the ls- l on the scripts dir on my system:

sid@sid-Latitude-E4300:/usr/share/com.github.babluboy.nutty/scripts$ ls -l
total 60
-rwxr-xr-x 1 root root  1340 Nov 29 21:40 nutty_cli_script.sh
-rwxr-xr-x 1 root root  1780 Apr 19  2018 nutty_device_alert.sh
-rwxr-xr-x 1 root root  1503 Apr  8  2018 nutty_device_monitor.sh
-rwxr-xr-x 1 root root   337 Nov 17 16:55 nutty_nethogs_script.sh
-rwxr-xr-x 1 root root   460 Nov 20 22:22 nutty_nmap_script.sh
-rwxr-xr-x 1 root root   310 Nov 20 21:40 nutty_ports_script.sh
-rwxr-xr-x 1 root root   334 Nov 20 19:41 nutty_traceroute_script.sh
-rwxr-xr-x 1 root root   312 Nov 17 18:55 nutty_vnstat_script.sh
-rwxr-xr-x 1 root root 24994 Sep 10  2016 speedtest-cli

It has got execute permissions for root, group and all - can you check yours?

@btd1337
Copy link
Contributor Author

btd1337 commented Dec 3, 2018

pkexec version 0.116 is installed but Nutty doesn't runs him

@btd1337
Copy link
Contributor Author

btd1337 commented Dec 3, 2018

Directory Permissions:

captura de tela de 2018-12-03 14-12-31

@babluboy
Copy link
Owner

babluboy commented Dec 3, 2018

@btd1337 Looks three scripts (ports, traceroute and vnstat) are missing execute permissions - could you please provide the execute permissions by running:
sudo chmod 755 nutty_ports_script.sh nutty_traceroute_script.sh nutty_vnstat_script.sh

also try manually running the command from terminal like:
pkexec /usr/share/com.github.babluboy.nutty/scripts/nutty_nethogs_script.sh
to check if a dialog prompt for the password is appearing and you see some output on the terminal.

I am suspecting that the missing execute permissions are the cause of those three scripts not working.
After you change the permissions, it should like the the below as per my original comment above:

-rwxr-xr-x 1 root root   310 Nov 20 21:40 nutty_ports_script.sh
-rwxr-xr-x 1 root root   334 Nov 20 19:41 nutty_traceroute_script.sh
-rwxr-xr-x 1 root root   312 Nov 17 18:55 nutty_vnstat_script.sh

@btd1337
Copy link
Contributor Author

btd1337 commented Dec 3, 2018

Now...

captura de tela de 2018-12-03 14-38-52

@btd1337
Copy link
Contributor Author

btd1337 commented Dec 3, 2018

Is it possible to set the permissions correctly in the MESON installer?

And add this program vnstat to Nutty's dependencies to avoid this problem in the future?

@btd1337
Copy link
Contributor Author

btd1337 commented Dec 3, 2018

After installing vnstat

captura de tela de 2018-12-03 14-42-57

@babluboy
Copy link
Owner

babluboy commented Dec 3, 2018

Is it possible to set the permissions correctly in the MESON installer?

And add this program vnstat to Nutty's dependencies to avoid this problem in the future?

Yes, just spotted that the meson build is missing the permissions for the scripts install - i will make the fix.

vnstat is already mentioned as part of the dependencies in the debian/control file. Maybe you installed from source and missed the dependencies, best to ensure the following are installed:
net-tools, nmap, traceroute, vnstat, nethogs, curl, wireless-tools, iproute2, pciutils

@babluboy
Copy link
Owner

babluboy commented Dec 3, 2018

Not sure about the vnstat error you are getting, can you check this to see if it resolves the issue:
https://askubuntu.com/questions/500663/vnstat-not-updating

@btd1337
Copy link
Contributor Author

btd1337 commented Dec 3, 2018

Please, add too vnstat to Nutty's dependencies.

@babluboy
Copy link
Owner

babluboy commented Dec 3, 2018

Vmstat is already in Debian/control so it should be automatically installed along with nutty when installing via ppa or by appcenter ....

When building from source all the dependent programs need to be installed manually....I will update the manual instructions details on github to mention the dependant programs

Did you get vnstat to work for you on Arch?

@btd1337
Copy link
Contributor Author

btd1337 commented Dec 3, 2018

No, the error persists.

@babluboy
Copy link
Owner

babluboy commented Dec 3, 2018

looks like the issue is due to vnstat not finding the eth0 interface. This page lists the steps on how to create the directory and vnstat database and then refresh the daemon by running a few commands. If you are able to give it a try and get vnstat running then I might do a check inside nutty and run these commands automatically to resolve the issue.

https://www.2daygeek.com/install-vnstat-to-monitor-network-interface-traffic-on-linux/

btd1337 added a commit to btd1337/nutty that referenced this issue Dec 4, 2018
btd1337 added a commit to btd1337/nutty that referenced this issue Dec 4, 2018
@btd1337 btd1337 mentioned this issue Dec 4, 2018
btd1337 added a commit to btd1337/nutty that referenced this issue Dec 4, 2018
btd1337 added a commit to btd1337/nutty that referenced this issue Dec 4, 2018
babluboy added a commit that referenced this issue Dec 4, 2018
@babluboy
Copy link
Owner

babluboy commented Dec 4, 2018

Thanks for the PR - did sudo systemclt enable vnstat resolve the issue on your system ?

@btd1337
Copy link
Contributor Author

btd1337 commented Dec 6, 2018

Yep,

This command solve this problem.

49387770-d8458080-f709-11e8-884c-51ce9012c483

@babluboy
Copy link
Owner

babluboy commented Dec 7, 2018

Thanks for the update...is all functionality of nutty working now on arch? ...did you have to change any of the scripts with arch specific commands ?..if yes, the please attach the updated script here, so that I can build an arch set of scripts

@btd1337
Copy link
Contributor Author

btd1337 commented Dec 7, 2018

I didn't have to make any adjustments. The errors were those mentioned above.

@babluboy
Copy link
Owner

babluboy commented Dec 7, 2018

Thanks for the update, I will add some logic to spot the error of vnstat not starting and run the start daemon command with sudo...

Closing this issue and will raise a separate one to handle the vnstat error

@btd1337
Copy link
Contributor Author

btd1337 commented Dec 8, 2018

@babluboy Thank you for your support!

@babluboy babluboy closed this as completed Dec 8, 2018
@babluboy babluboy added released code fix released and removed completed Code Fix Issued labels Jan 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants