Please, please FreeBSD gurus, I need your help! šŸ™

Itā€™s leftover from an old scriptā€¦
Iā€™ll clean that up some more.

It was part of a script that Iā€™d it wound have had to run an chown, it would have taken a long time because of terabytes of files.

Also, I wasnā€™t sure what the install command would do if the directories were already there.

So my logic is, if the directories arenā€™t there, install will create them, and if they are, make sure they are owned by the user.

should just overwrite the file with the given UID and GID.

install(1) (freebsd.org)

wait! Are you installing a directory or a binary program (I could be steering you down the wrong path)?

Just a directory. Itā€™s where the log file and pid file will go once the program runs.

Then if were only talking about a directory, Iā€™d do something like this:

slskd_startprecmd() {
   # 'mkdir -p' will not overwrite a directory if it exists
   mkdir -p /var/run/${name}
   mkdir -p /var/log/${name}
   chown ${slskd_user}:${slskd_group} /var/run/${name};
   chown ${slskd_user}:${slskd_group} /var/log/${name};
}

This is sightly verbose, but it also allows for easy removal/additional when future versions change.


EDIT:
1.The install program is for copying a binary file (a program) from one location to another (so my direction above was leading you down the wrong path).
2. Removed the recursive flag from chown (the -R) because multiple files are not involved.

I missed this logic explanation from you.

Your logic can be simplified to two (2) statements.

The base syntax is:
if [predicate] [consequent] [alternative]

The base logic is:
If the ā€˜predicateā€™ is TRUE then do the ā€˜consequentā€™, else do the ā€˜alternativeā€™.

The modification I propose, in the code directly above, is to eliminate the ā€˜predicateā€™ (or more accurately combine it with a revised statement) and take the millisecond performance drop (if there is one) in trade to ensure the proper permissions exist no matter what the conditions are. My logic is: ā€œI always want to make sure proper permissions exist, but I should also make sure the directory exists as well.ā€

Sorry, I didnā€™t mean to make that sound ā€œpreachyā€; just trying to cover my bases in that explanation (you could be a genius programmer, for all I know, and think my explanation is good coming from a potato).

For the record, Iā€™m ambivalent towards the ā€œmark as solutionā€ feature.

There are some drawbacks to it:

  • More than one post can have a ā€œsolutionā€
  • Sometimes a ā€œsolutionā€ is more nuanced within the discussion itself
  • When a thread is marked as ā€œSolvedā€, it almost feels like itā€™s been ā€œclosedā€ to any further discussion, even though thatā€™s not the case

Iā€™m fine with that.

@John Iā€™m also good with your advise. Itā€™s easier to read and such.

Thatā€™s fine; itā€™s your thread. But Victor deserves the gold-star IMO.

Oh, look at that; I added ā€œin my opinionā€ to text I just wrote. Or was that redundancy lost and possibly gotten away with not pointing out my idiocy.

1 Like

Simple is best. I remember running into the ā€œinstallā€ command the first time. Whatā€¦

The way you propose is clean and easy to follow.

The logic is the interesting part about programming.

For example: I know itā€™s not related, so to speak, but itā€™s a fun story nonetheless. I had an interaction with a new architect writing some python code to produce building layouts with a CAD package. They asked me what I thought: ā€œIt produces 23 parking garage layouts in seconds.ā€ My reply was ā€œyou can save time by reading a bookā€. When they asked what I meant I said: ā€œwhen you have 23 different layouts you need ā€˜knowledgeā€™ to know which layout is the ā€˜correctā€™ one, so if you just read a book (i.e. gain ā€˜knowledgeā€™) and produce the ā€˜correctā€™ layoutā€“onceā€“youā€™d save yourself, the structural, electrical and mechanical engineerā€™s time.ā€. ā€¦If you were wondering, they never spoke to me again.

1 Like

Typical these daysā€¦

Sounds like an angry person. Maybe they need to do some soul searching? Or maybe someā€¦ soul seeking?

Click this if you laughed

:drum: :clap: :wink:

Click this if you groaned

Iā€™m sorry. :pensive:

Iā€™ll accept the apology. lol

It could be my laconic nature but I feel as though I ā€œinspire angerā€ in a lot of people. Speaking of which, I was going to write a post on how to ā€œignore meā€. I forgot. I should put that on my list of things todo.

1 Like

I guess a ā€œlesson learnedā€ from this is that it was really due to the application itself, and not FreeBSD rc scripting. (Even though rc scripting was ā€œpartā€ of the issue.)

1 Like

Yes and no. I agree but I think the job of the rc.d scripting mechanism is to be as flexible as possible and I think it proved that in this case. Iā€™m not sure about the flexibility of the systemfile method of systemd though. In the past systemd has been constraining and volatile so I suspect the systemfile method could possibly become more/less constrained over time so, there is no telling what future hoops the app developer may have to jump though and what that may mean for ā€œportabilityā€. Hopefully that is on the dotnet library porting shouldersā€“in this appā€™s case. The C# language is an extremely volatile language though; please note: dotNet at itā€™s core is rock solid but developer trends are what cause disturbances.