Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Replace whoami with id -u -n in scripts for POSIX compliance (#854) #915

Merged
merged 2 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bun/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ file)
```sh
sudo env PATH="$PATH" \
serviceman add --path="$PATH" --system \
--username "$(whoami)" --name my-project -- \
--username "$(id -u -n)" --name my-project -- \
bun run ./my-project.js
```
4. Restart the logging service
Expand Down
8 changes: 4 additions & 4 deletions caddy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ To avoid the nitty-gritty details of `launchd` plist files, you can use
2. Use Serviceman to create a _launchd_ plist file

```sh
my_username="$( id -u -n )"
my_username="$(id -u -n)"

serviceman add --user --name caddy -- \
caddy run --config ./Caddyfile --envfile ~/.config/caddy/env
Expand Down Expand Up @@ -901,7 +901,7 @@ See the notes below to run as a **User Service** or use the JSON Config.
```
4. Use Serviceman to create a _systemd_ config file.
```sh
my_username="$( id -u -n )"
my_username="$(id -u -n)"
sudo env PATH="$PATH" \
serviceman add --system --username "${my_username}" --name caddy -- \
caddy run --config ./Caddyfile --envfile ~/.config/caddy/env
Expand Down Expand Up @@ -1363,15 +1363,15 @@ See also: <https://caddyserver.com/docs/running>
2. Generate the `service` file: \
- JSON Config
```sh
my_app_user="$( id -u -n )"
my_app_user="$(id -u -n)"
sudo env PATH="${PATH}" \
serviceman add --system --cap-net-bind \
--username "${my_app_user}" --name caddy -- \
caddy run --resume --envfile ./caddy.env
```
- Caddyfile
```sh
my_app_user="$( id -u -n )"
my_app_user="$(id -u -n)"
sudo env PATH="${PATH}" \
serviceman add --system --cap-net-bind \
--username "${my_app_user}" --name caddy -- \
Expand Down
4 changes: 2 additions & 2 deletions fish/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ the file:
```sh
#!/bin/bash

echo "Who am I? I'm $(whoami)."
echo "Who am I? I'm $(id -u -n)."
```

You can also run bash explicitly:
Expand Down Expand Up @@ -99,7 +99,7 @@ You should use `chsh` to change your shell:
```sh
#!/bin/sh

sudo chsh -s "$(command -v fish)" "$(whoami)"
sudo chsh -s "$(command -v fish)" "$(id -u -n)"
```

If vim uses `fish` instead of `bash`, annoying errors will happen.
Expand Down
2 changes: 1 addition & 1 deletion go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pushd ./hello/

# swap 'hello' and './hello' for the name of your project and binary
sudo env PATH="$PATH" \
serviceman add --system --username "$(whoami)" --name hello -- \
serviceman add --system --username "$(id -u -n)" --name hello -- \
./hello

# Restart the logging service
Expand Down
2 changes: 1 addition & 1 deletion golang/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pushd ./hello/

# swap 'hello' and './hello' for the name of your project and binary
sudo env PATH="$PATH" \
serviceman add --system --username "$(whoami)" --name hello -- \
serviceman add --system --username "$(id -u -n)" --name hello -- \
./hello

# Restart the logging service
Expand Down
4 changes: 2 additions & 2 deletions node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ Node app as a Non-System (Unprivileged) Service on Mac, Windows, and Linux:
or _User Unit_ (Linux):

```sh
my_username="$( id -u -n )"
my_username="$(id -u -n)"

serviceman add --user --name my-node-project -- \
caddy run --config ./Caddyfile --envfile ~/.config/caddy/env
Expand Down Expand Up @@ -275,7 +275,7 @@ Node app as a Non-System (Unprivileged) Service on Mac, Windows, and Linux:
```sh
pushd ./my-node-project/

my_username="$( id -u -n )"
my_username="$(id -u -n)"
sudo env PATH="$PATH" \
serviceman add --system --path "$PATH" --cap-net-bind \
--name my-node-project --username "${my_username}" -- \
Expand Down
4 changes: 2 additions & 2 deletions postgres/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ To enable Postgres as a Linux Service with [serviceman](../serviceman/): \

```sh
sudo env PATH="$PATH" \
serviceman add --system --username "$(whoami)" --name 'postgres' -- \
serviceman add --system --username "$(id -u -n)" --name 'postgres' -- \
postgres -D ~/.local/share/postgres/var -p 5432

sudo systemctl restart systemd-journald
Expand Down Expand Up @@ -120,7 +120,7 @@ curl https://webi.sh/serviceman | sh

```sh
sudo env PATH="$PATH" \
serviceman add --system --username "$(whoami)" --name 'postgres' -- \
serviceman add --system --username "$(id -u -n)" --name 'postgres' -- \
postgres -D ~/.local/share/postgres/var -p 5432

sudo systemctl restart systemd-journald
Expand Down
2 changes: 1 addition & 1 deletion ssh-adduser/ssh-adduser
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ main() {
my_key_url="${2:-}"
my_keys=""

if [ "root" != "$(whoami)" ]; then
if [ "root" != "$(id -u -n)" ]; then
echo "webi adduser: running user is already a non-root user"
exit 0
fi
Expand Down
2 changes: 1 addition & 1 deletion ssh-pubkey/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ folder:

```sh
rsync -av "$HOME/.ssh/id_rsa.pub" \
"$HOME/Downloads/id_rsa.$(whoami).pub"
"$HOME/Downloads/id_rsa.$(id -u -n).pub"
```

How to print your public key to the Terminal:
Expand Down
8 changes: 4 additions & 4 deletions ssh-pubkey/ssh-pubkey
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ main() {
# TODO use the comment (if any) for the name of the file
echo >&2 ""
#shellcheck disable=SC2088
echo >&2 "~/Downloads/id_${my_keytype}.$(whoami).pub":
echo >&2 "~/Downloads/id_${my_keytype}.$(id -u -n).pub":
echo >&2 ""
rm -f "$HOME/Downloads/id_${my_keytype}.$(whoami).pub"
cp -RPp "$HOME/.ssh/id_${my_keytype}.pub" "$HOME/Downloads/id_${my_keytype}.$(whoami).pub"
cat "$HOME/Downloads/id_${my_keytype}.$(whoami).pub"
rm -f "$HOME/Downloads/id_${my_keytype}.$(id -u -n).pub"
cp -RPp "$HOME/.ssh/id_${my_keytype}.pub" "$HOME/Downloads/id_${my_keytype}.$(id -u -n).pub"
cat "$HOME/Downloads/id_${my_keytype}.$(id -u -n).pub"
echo >&2 ""

if test -f ~/.ssh/id_rsa; then
Expand Down
Loading