lupl
lupl

Reputation: 934

Shell script 'installer'

I would like to create a --setup flag for a shell script that makes the script globally executable, so 1. sudo chmod +x $0 and 2. sudo cp $0 /usr/local/bin, or so..

The problem obviously is, that the script won't run until it is executable. Maybe one could call it as sudo bash ./script --setup?

Are there any best practices this or making scripts behave more like cl tools installed from official repositories?

Upvotes: 1

Views: 641

Answers (1)

Diego Torres Milano
Diego Torres Milano

Reputation: 69189

You can use install

Usage: install [OPTION]... [-T] SOURCE DEST
  or:  install [OPTION]... SOURCE... DIRECTORY
  or:  install [OPTION]... -t DIRECTORY SOURCE...
  or:  install [OPTION]... -d DIRECTORY...

This install program copies files (often just compiled) into destination
locations you choose.  If you want to download and install a ready-to-use
package on a GNU/Linux system, you should instead be using a package manager
like yum(1) or apt-get(1).

or, as it documentation says, build a package for your distro or a universal snap.

Upvotes: 2

Related Questions