Add an installation script #3

Closed
opened 2020-10-20 04:27:40 +02:00 by p · 0 comments
Owner

Copying snippets from the README is uncomfortable and laborious. It also wastes a lot of space in the document.

This will be a POSIX sh script.

Check the SHELL environment variable and install sdn directly into the user's rc file. Make it possible to specify the shell's name explicitly (-s bash), as well as the path (-f /etc/bash.bashrc). If the path is a dash (-f-), write the snippet to the standard output. Of course, add a help option. Use a getopts s:f:h opt loop, which is POSIX-compatible and works with dash(1). Install the script.

Wrap the snippets in a pair of detection comments (# sdn-install begin .. # sdn-install end should be obvious enough and portable) and try to replace the contents--sed(1) may be used for this. sed -i may not be safe and we should retain permissions. Perhaps use: cp -p -- "$rc" "$rc.sdn.new", sed < "$rc" > "$rc.sdn.new", mv -- "$rc.sdn.new" "$rc". It copies data unnecessarily but it is portable (--attributes-only is GNU), unlike even stat(1).

Compare $(basename "$SHELL") with $(ps -p $$ -o ppid= | xargs ps -o comm= -p) and display an error on mismatch--the user will have to specify the shell manually in this case. Naturally, error out if the shell is not supported.

It might be a good idea to export an environment variable and make sdn not output its variables if it's missing.

Copying snippets from the README is uncomfortable and laborious. It also wastes a lot of space in the document. This will be a POSIX sh script. Check the SHELL environment variable and install sdn directly into the user's rc file. Make it possible to specify the shell's name explicitly (`-s bash`), as well as the path (`-f /etc/bash.bashrc`). If the path is a dash (`-f-`), write the snippet to the standard output. Of course, add a help option. Use a `getopts s:f:h opt` loop, which is POSIX-compatible and works with dash(1). Install the script. Wrap the snippets in a pair of detection comments (`# sdn-install begin` .. `# sdn-install end` should be obvious enough and portable) and try to replace the contents--sed(1) [may be used for this](https://unix.stackexchange.com/a/303649). `sed -i` may not be safe and we should retain permissions. Perhaps use: `cp -p -- "$rc" "$rc.sdn.new"`, `sed < "$rc" > "$rc.sdn.new"`, `mv -- "$rc.sdn.new" "$rc"`. It copies data unnecessarily but it is portable (`--attributes-only` is GNU), unlike even stat(1). Compare `$(basename "$SHELL")` with `$(ps -p $$ -o ppid= | xargs ps -o comm= -p)` and display an error on mismatch--the user will have to specify the shell manually in this case. Naturally, error out if the shell is not supported. It might be a good idea to export an environment variable and make sdn not output its variables if it's missing.
p self-assigned this 2020-10-20 04:27:40 +02:00
p changed title from Add an instalation script to Add an installation script 2020-10-21 08:12:07 +02:00
p closed this issue 2020-10-21 08:27:53 +02:00
Sign in to join this conversation.
No Label
WIP
easy
priority
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: p/sdn#3
No description provided.