joecannatti / soji

Terminal Based Mindful Workday System
GNU Affero General Public License v3.0
75 stars 16 forks source link

Mixing user and super-user tasks in the Makefile install task #12

Closed DDzwiedziu closed 7 years ago

DDzwiedziu commented 7 years ago

First I should be able to use soji without the need of installing. But trying to run the executable I get only a message about a missing file in the ~/.config.

Expected behaviour: soji creates default config files and dirs when none are found. Essentially Makefile lines 11-19 should be done by soji itself with checks if such task already has been done.

The only command in Makefile that requires root is

sudo ln -fs ~/.config/soji/soji /usr/bin/soji

...which is... "unorthodox" to say at least.

Expected behaviour: the executable is kept off ~/.config and just copied to /usr/bin.

I could patch both of the above in the Makefile itself (as I'm not using Guile), but this would be only a temporary solution. E.g. if configs were to be cleared then the first program run should recreate default ones.

danningc commented 7 years ago

What did you do to change the makefile?

This is what i got from running sudo make install

cp soji.scm soji
mkdir -p ~/.config/soji/notes
cp ./soji ~/.config/soji/soji
cp -r subcommands ~/.config/soji/
>~/.config/soji/sojirc
>~/.config/soji/sojirc.scm
echo "export SOJI_DIR=~/.config/soji" >> ~/.config/soji/sojirc
echo "export SOJI_NOTES_DIR=~/.config/soji/notes" >> ~/.config/soji/sojirc
echo "(define SOJI_DIR (string-append (getenv \"HOME\") \"/.config/soji\"))" >> ~/.config/soji/sojirc.scm
echo "(define SOJI_NOTES_DIR (string-append (getenv \"HOME\") \"/.config/soji/notes\"))" >> ~/.config/soji/sojirc.scm
sudo ln -fs ~/.config/soji/soji /usr/bin/soji
ln: /usr/bin/soji: Operation not permitted
make: *** [install] Error 1
DDzwiedziu commented 7 years ago

I've aborted after that waiting for an answer.

But instead of the sudo ln (...) you could try this:

mkdir ~/bin
ln -s ~/.config/soji/soji ~/bin/soji

And add ~/bin to $PATH in your shell rc file.

joecannatti commented 7 years ago

Hey @DDzwiedziu,

Yeah, I think what you're saying basically correct. Not depending on make install creates one problem that I don't know how to solve though. I don't have a lot of experience distributing this type of software so I might be missing something obvious.

I get how I could easily make the dirs and generate the default sojirc.scm, but how would I know where to copy the bash scripts in the subcommands dir from?

To put it in a narrative to try to make it clear: If you just cp'ed the soji bin somewhere on your machine and then ran it, I see how it could easily setup the dirs and default config file, but how would it put the subcommands dir in place? It wouldn't know where to find them.

One way to solve it would be to also put them into /usr/bin (or wherever you put soji), but that seems error prone and like you'd still want a make task to do it.

Again, I think you're right in the idea, just still not sure how to implement it.

joecannatti commented 7 years ago

@danningc Yeah, what system on you on? I think that the easiest thing to do to get you up and running would be to just alter the path that the ln command writes to to go where bin files are written on you system.

The "works for everyone" version would be to make the make task accept an arg for the path where you want the bin file to go.

Hope that helps!

danningc commented 7 years ago

Thank you @joecannatti @DDzwiedziu for your replies! I'm pretty new to this, so bear with my unintelligent questions... and @joecannatti i'm using Mac OS.

I think i've gone pass the original issue i had, now instead, i'm running into the issue with guile.

which guile gave me /usr/local/bin/guile but when i do soji, the error said "bad interpreter: /usr/bin/guile: no such file or directory`, looks like it's looking for the wrong place? Is there anything i can do about it?

danningc commented 7 years ago

By the way, nice article http://multithreaded.stitchfix.com/blog/2016/10/03/time-thunderdome/

That brought me here 😄

joecannatti commented 7 years ago

@danningc Ah, I see the problem. If you change the shebang (the top lines that tell the os how to run the script) in soji.scm, to

#!/usr/bin/env guile \
-e main -s
!#

I think that will work. The problem is that I have the path to guile hard coded there. This change makes it ask your system where guile is, then run it.

If that works for you, feel free to submit a PR!

danningc commented 7 years ago

I think we are making solid progress here!

Next error: When i typed "soji", i got a permission denied, and sudo soji didn't help either.

date: illegal time format
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
/Users/danning/.config/soji/subcommands/note: line 3: /Users/danning/.config/soji/notes/engineering-log-.org: Permission denied
joecannatti commented 7 years ago

I think there are 2 problems there

  1. The date format string I'm using must not work correctly on the Mac OS version of the date command
  2. The owner of ~/.config/soji must have ended up being root. Probably due to sudo.

I'll have to look into this and get back to you

iacobus42 commented 7 years ago

@joecannatti, the date format string doesn't work with the date command on OS X. I've filed a pull request that fixes this issue and a few other things with running soji on OS X.

@danningc, do you have your $EDITOR set? Try running vim /Users/danning/.config/soji/notes/... where ... is the name of a file in that folder. When $EDITOR isn't set, you get that same error on Linux. If that works, add export $EDITOR=vim to your ~/.bash_profile and run source ~/.bash_profile. It might be a permissions issue but that doesn't match my experience on OS X.

danningc commented 7 years ago

@iacobus42 Thanks for the tip, yep, that works! After reinstalling it with the merged PR from you, soji seems to work, except i need sudo again to use soji start...

 ~ î‚° soji start 'test task 3'
/Users/danning/.config/soji/subcommands/log: line 3: /Users/danning/.config/soji/notes/engineering-log-2016-10-20.org: Permission denied
 ~ î‚° sudo soji start 'test task 3'
Password:
iacobus42 commented 7 years ago

@danningc, does it start when you use sudo soji start 'test' or give the same error? Can you run cat /Users/danning/.config/soji/notes/engineering-log-2016-10-20.org (or if the file doesn't exist can you open that path in vim) and view the log file?

Also if there is an engineering-log-[date].org file, can you run ls -la notes/engineering-log-[date].org and paste the output?

I installed soji with sudo sh install_soji on OS X and am able to access the log files without needing root so I'm not able to debug this problem on my machine.

danningc commented 7 years ago

Seems to resolved by adding write permission to notes..

 ~/.config/soji î‚° sudo chmod a+w notes
 ~/.config/soji î‚° ls -alh
total 24
drwxr-xr-x   7 root  staff   238B Oct 15 09:15 .
drwxr-xr-x   3 root  staff   102B Oct 15 09:15 ..
drwxrwxrwx   4 root  staff   136B Oct 20 22:58 notes
-rwxr-xr-x   1 root  staff   1.0K Oct 22 09:05 soji
-rw-r--r--   1 root  staff    74B Oct 22 09:05 sojirc
-rw-r--r--   1 root  staff   144B Oct 22 09:05 sojirc.scm
drwxr-xr-x  23 root  staff   782B Oct 15 09:15 subcommands
joecannatti commented 7 years ago

I'm pretty sure that these issues are all either fixed or will show up differently in the latest HEAD of master. Going to close this. Feel free to reopen new tickets after checking out the current version.