You are not logged in.

#1 2017-06-05 18:59:45

DJNightchild
Member
Registered: 2013-08-02
Posts: 16

My standard custom installation script

I've created a script which automates the installation of standard software packages I use. I found it became quite annoying to install everything from scratch when I either got new hardware, or messed something up. This script is meant to be used after a normal installation of arch including openbox and if needed, a display manager.

Warning! This script has been written by myself and it works perfectly for me, it might give you different results though. I shared it because there might be someone who likes to use it. It is tested with a normal arch installation and with Arch-Anywhere. ArAA-Openbox stands for Arch and Arch-Anwyhere Openbox.

Have fun with it and remember; even an Archer is allowed to be lazy sometimes wink

https://pastebin.com/SxMtiTEg


EDIT: Command for configuring /etc/X11/xorg.conf.d/00-keyboard.conf has been added

Last edited by DJNightchild (2017-06-09 11:21:13)

Offline

#2 2017-06-06 07:04:46

Head_on_a_Stick
Member
From: London
Registered: 2014-02-20
Posts: 7,732
Website

Re: My standard custom installation script

wget -qO- https://github.com/Erwinovitch/msfonts/raw/master/install.sh | sudo sh -

I'm not sure if downloading random scripts from the internet and running them as root is a good idea.

Anyway, thanks for the contribution.

Offline

#3 2017-06-06 08:05:57

ayekat
Member
Registered: 2011-01-17
Posts: 1,589

Re: My standard custom installation script

DJNightchild wrote:

This script is meant to be used after a normal installation of arch

There is not really a "normal installation of arch", though smile
I can't say much about the usefulness of such a script to a wider community, but I can give some feedback. Here are some random things I noticed:

  • 9,75,80,84,121,126,...: Why are there all those random `sleep` commands?

  • 12,273: I would simply check for $EUID -eq 0 at the beginning of the script, so you don't have to wrap 200+ lines into an `if` statement.

  • 19,21,23: I would generally pass -r to makepkg, to avoid keeping around unrequired buildtime-only dependencies after building the package.

  • 29: Head_on_a_Stick already commented on the `wget ... | sudo ...` being a Very Bad Idea™. Furthermore, why not put the `wget` command on the next line? If your goal is to simply check if pacman successfully completed, I would rather `set -e` at the beginning of the script to make it exit upon encountering an error (this is generally preferrable to having a script that keeps running after something has failed).

  • 34,46: You forgot to escape $EUID. Again, I would move the check-and-exit to the top of the script.

  • 64: .desktop files do not need to be executable.

  • 64..66: This script appears to leave behind at least 3 files in the user's home. I personally wouldn't appreciate it. Can they be moved? Can they be deleted? The script (output) doesn't give any hints.

  • 86,116,117,132,...: The script will break if the user has their XDG base directory environment variables set differently from the default (you assume ~/.config for XDG_CONFIG_HOME).

  • 116,117: I generally try to avoid running GUI applications as root. Is there a reason why you set up mimeapps.list (typo!) in the root user's home?

  • 190..193: There is no need for removing the file separately; the > will truncate the file anyway.

  • 234..242: You mix tabs and spaces for indentation. This is considered bad style. Also, generally, there are some occurences of trailing whitespace in the script. See if you can configure your text editor to highlight those.

  • There are lots of commands with sudo, which I personally consider unelegant (also, the script silently assumes that the user has the right to run sudo). I know this is supposed to be for your user only, but I would still try to split the "general-system-setup" part from the "user-specific-setup" part.

Last edited by ayekat (2017-06-06 08:25:47)


pkgshackscfgblag

Offline

#4 2017-06-06 11:03:16

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,523
Website

Re: My standard custom installation script

ayekat wrote:

29: Head_on_a_Stick already commented on the `wget ... | sudo ...` being a Very Bad Idea™. Furthermore, why not put the `wget` command on the next line? If your goal is to simply check if pacman successfully completed, I would rather `set -e` at the beginning of the script to make it exit upon encountering an error (this is generally preferrable to having a script that keeps running after something has failed).

A much easier fix is to just not run some random script as root which will circumvent the package manager to install untracked files to the root filesystem.  Instead use the AUR package that installs those very same files.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#5 2017-06-06 15:33:47

DJNightchild
Member
Registered: 2013-08-02
Posts: 16

Re: My standard custom installation script

Head_on_a_Stick wrote:
wget -qO- https://github.com/Erwinovitch/msfonts/raw/master/install.sh | sudo sh -

I'm not sure if downloading random scripts from the internet and running them as root is a good idea.

Anyway, thanks for the contribution.

That is my own msfonts script, so that is not a problem wink

Offline

#6 2017-06-06 15:56:50

DJNightchild
Member
Registered: 2013-08-02
Posts: 16

Re: My standard custom installation script

ayekat wrote:
DJNightchild wrote:

This script is meant to be used after a normal installation of arch

There is not really a "normal installation of arch", though smile
I can't say much about the usefulness of such a script to a wider community, but I can give some feedback. Here are some random things I noticed:

  • 9,75,80,84,121,126,...: Why are there all those random `sleep` commands?

  • 12,273: I would simply check for $EUID -eq 0 at the beginning of the script, so you don't have to wrap 200+ lines into an `if` statement.

  • 19,21,23: I would generally pass -r to makepkg, to avoid keeping around unrequired buildtime-only dependencies after building the package.

  • 29: Head_on_a_Stick already commented on the `wget ... | sudo ...` being a Very Bad Idea™. Furthermore, why not put the `wget` command on the next line? If your goal is to simply check if pacman successfully completed, I would rather `set -e` at the beginning of the script to make it exit upon encountering an error (this is generally preferrable to having a script that keeps running after something has failed).

  • 34,46: You forgot to escape $EUID. Again, I would move the check-and-exit to the top of the script.

  • 64: .desktop files do not need to be executable.

  • 64..66: This script appears to leave behind at least 3 files in the user's home. I personally wouldn't appreciate it. Can they be moved? Can they be deleted? The script (output) doesn't give any hints.

  • 86,116,117,132,...: The script will break if the user has their XDG base directory environment variables set differently from the default (you assume ~/.config for XDG_CONFIG_HOME).

  • 116,117: I generally try to avoid running GUI applications as root. Is there a reason why you set up mimeapps.list (typo!) in the root user's home?

  • 190..193: There is no need for removing the file separately; the > will truncate the file anyway.

  • 234..242: You mix tabs and spaces for indentation. This is considered bad style. Also, generally, there are some occurences of trailing whitespace in the script. See if you can configure your text editor to highlight those.

  • There are lots of commands with sudo, which I personally consider unelegant (also, the script silently assumes that the user has the right to run sudo). I know this is supposed to be for your user only, but I would still try to split the "general-system-setup" part from the "user-specific-setup" part.

EDIT: Done with the implementation noticed below. Also reduced the amount of sudo.

  • 9,75,80,84,121,126,...: sleep commands are not random. I want to inform the user of the script what is going to happen, in give them time to read it

  • 12,273: That is an idea, but not an issue imho smile

  • 19,21,23: Will implement it.

  • 29 could have done that. The script downloaded for wget is only for some fonts. the script is created by myself btw. Set -e will be implemented.

  • 34,46: Not sure what you mean by this, I'm quite new to scripting, doesn't it exit by itself after the code has runthrough (there is no loop)?

  • 64: Except when running xfce4. It asks if it is safe to mark them executable.

  • 64..66 Will check if there is a suitable location for those files.

  • 86,116,117,132,...: How would you I let the script check for their custom folder?

  • 116,117 Because some user use a file-manager with root privileges for some situations. Will fix the typo.

  • 190..193: will be fixed

  • 234..242: Will take a look at it

  • Never heard of a install script which doesn't either need you to be root, or needs sudo permissions. Will think about splitting it up.

Anyway thanks for the advice you gave. big_smile It helps a lot.

Last edited by DJNightchild (2017-06-06 16:40:55)

Offline

#7 2017-06-06 16:38:54

ayekat
Member
Registered: 2011-01-17
Posts: 1,589

Re: My standard custom installation script

29 could have done that. The script downloaded for wget is only for some fonts. the script is created by myself btw.

The script you download is simply `git clone` and `cp -r ...`. I think it would be simpler (and clearer) if they were included in this script¹. Piping the output of curl/wget into `sudo sh` is a big no-no, at least if you intend to have the script be used by other people.

34,46: Not sure what you mean by this, I'm quite new to scripting, doesn't it exit by itself after the code has runthrough (there is no loop)?

The way it's written, the value of $EUID is resolved the moment the `jre` and `flashplugin` scripts are created, so the files themselves would simply contain the UID of the user who runs the setup script. I don't understand your "loop" reference, though. There is just an if and else statement, which I would personally rewrite as

if [[ $EUID -eq 0 ]]; then
    echo "This script can't be used as root" >&2
    exit 1
fi
...

64: Except when running xfce4. It asks if it is safe to mark them executable.

What "asks if it is safe to mark them as executable"? .desktop files are simply text files that hold informations about programs. The .desktop files themselves are not executed.

64..66 Will check if there is a suitable location for those files.

Couldn't you simply ask the user if they want to install those packages, rather than creating the script files for later?
The .desktop files can be put into /usr/local/share/applications or $XDG_DATA_HOME/applications (defaults to ~/.local/share/applications, see my comment on XDG variables below).

86,116,117,132,...: How would you I let the script check for their custom folder?

The XDG basedir specs I linked to say that user configuration files should go into $XDG_CONFIG_HOME. If that environment variable is not set, ~/.config should be used. You can do something like this at the beginning of your script²:

XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"

Then you can use $XDG_CONFIG_HOME instead of ~/.config.
The same is true for $XDG_DATA_HOME (~/.local/share by default) and $XDG_CACHE_HOME (~/.cache by default).

116,117 Because some user use a file-manager with root privileges for some situations. Will fix the typo.

Fair enough. I don't use a file manager, so I can't really give the correct approach there (but from what I've gathered, launching a graphical file manager as root is not recommended—I'll let people with more experience chime in on this one).

Never heard of a install script which doesn't either need you to be root, or needs sudo permissions.

To be honest, I don't know if there is even a "best practice" for such install scripts. I would personally replace this script by a git repository containing my personal configuration files³ and a series of PKGBUILDs (for system-wide files). This comes with the benefit of being able to keep my configuration synchronised across machines, and not littering my filesystem with unowned files (see Trilby's comment above).

Then again, some things may still require modifying existing files, but since those are system-wide files (e.g. in /etc/systemd), the script could be modified to run as root directly.


_____
¹ Remark: I don't know about the legality of hosting those font files on Github. It may be wise to check if it's OK.
² To be really pedantic (but this is getting ridiculous), $HOME might not be defined either (but usually is), so you'd need additionally:

HOME="${HOME:-$(getent passwd $(id -un) | cut -d: -f6)}"

³ There are quite a few people who do this—some even publish their personal configuration setups.


pkgshackscfgblag

Offline

#8 2017-06-06 16:47:14

DJNightchild
Member
Registered: 2013-08-02
Posts: 16

Re: My standard custom installation script

You made some fair points, I will check what I can do, and place a new comment when I've done the editing.

Could I ask you to check it again after I done the editing?

Offline

#9 2017-06-06 17:05:27

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: My standard custom installation script

ayekat wrote:

To be really pedantic (but this is getting ridiculous), $HOME might not be defined either (but usually is)

I don't know, there comes a point where I say, "If you're installing Arch Linux and suddenly the $HOME variable isn't set then you have BIGGER THINGS TO WORRY ABOUT". tongue

Offline

#10 2017-06-06 17:12:33

DJNightchild
Member
Registered: 2013-08-02
Posts: 16

Re: My standard custom installation script

Implemented the things Ayekat pointed out,

with exception to the weblink, which is still in the home folder (and ".desktop" files outside of /usr/share/applications (or the user variant) need to be marked as executable by xfce4 (not sure if "xfdesktop" demands it, or "thunar --daemon")).

Offline

#11 2017-06-06 17:44:27

ayekat
Member
Registered: 2011-01-17
Posts: 1,589

Re: My standard custom installation script

That looks cleaner to me now smile
Given that there are now variables (e.g. $XDG_CONFIG_HOME), it is a good idea to quote them (to avoid weird behaviour if a variable contains whitespaces), so for example:

mkdir -p "$XDG_CONFIG_HOME"/autostart

Also, the heredocs (the ones with `cat <<- EOF ...`) are still indented, although that doesn't change the output, so it's just a minor remark.

drcouzelis wrote:
ayekat wrote:

To be really pedantic (but this is getting ridiculous), $HOME might not be defined either (but usually is)

I don't know, there comes a point where I say, "If you're installing Arch Linux and suddenly the $HOME variable isn't set then you have BIGGER THINGS TO WORRY ABOUT". tongue

When I get around it, I'll try to unset HOME, just to see how my applications will react... tongue
IMHO, applications should work correctly even if $HOME is unset. This could happen during the "PAMck time", i.e. the moment between PAM setting up the user environment (and loading modules), and the actual login happening (where $HOME is eventually set).

@DJNightchild: as noted, I wasn't 100% serious about setting $HOME yourself (but it's nice that you included it nevertheless). smile


pkgshackscfgblag

Offline

#12 2017-06-06 18:23:33

DJNightchild
Member
Registered: 2013-08-02
Posts: 16

Re: My standard custom installation script

ayekat wrote:

That looks cleaner to me now smile
Given that there are now variables (e.g. $XDG_CONFIG_HOME), it is a good idea to quote them (to avoid weird behaviour if a variable contains whitespaces), so for example:

mkdir -p "$XDG_CONFIG_HOME"/autostart

Also, the heredocs (the ones with `cat <<- EOF ...`) are still indented, although that doesn't change the output, so it's just a minor remark.

drcouzelis wrote:
ayekat wrote:

To be really pedantic (but this is getting ridiculous), $HOME might not be defined either (but usually is)

I don't know, there comes a point where I say, "If you're installing Arch Linux and suddenly the $HOME variable isn't set then you have BIGGER THINGS TO WORRY ABOUT". tongue

When I get around it, I'll try to unset HOME, just to see how my applications will react... tongue
IMHO, applications should work correctly even if $HOME is unset. This could happen during the "PAMck time", i.e. the moment between PAM setting up the user environment (and loading modules), and the actual login happening (where $HOME is eventually set).

@DJNightchild: as noted, I wasn't 100% serious about setting $HOME yourself (but it's nice that you included it nevertheless). smile

I noticed the joke ayekat, that's why I included it. however, I seem to encounter another issue. Functions can't be called by sudo. So I'll create a file (AGAIN!) in /tmp, for the sysctl part, and run that as sudo. should work I guess...

Offline

Board footer

Powered by FluxBB