-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nakamura Kazutaka
committed
Jan 2, 2024
1 parent
b323c14
commit 6dd1920
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/bash | ||
|
||
export USER=rust | ||
export HOME=/home/$USER | ||
|
||
# カレントディレクトリの uid と gid を調べる | ||
uid=$(stat -c "%u" .) | ||
gid=$(stat -c "%g" .) | ||
|
||
if [ "$uid" -ne 0 ]; then | ||
if [ "$(id -g $USER)" -ne $gid ]; then | ||
# rust ユーザーの gid とカレントディレクトリの gid が異なる場合、 | ||
# rust の gid をカレントディレクトリの gid に変更し、ホームディレクトリの | ||
# gid も正常化する。 | ||
getent group $gid >/dev/null 2>&1 || groupmod -g $gid $USER | ||
chgrp -R $gid $HOME | ||
fi | ||
if [ "$(id -u $USER)" -ne $uid ]; then | ||
# rust ユーザーの uid とカレントディレクトリの uid が異なる場合、 | ||
# rust の uid をカレントディレクトリの uid に変更する。 | ||
# ホームディレクトリは usermod によって正常化される。 | ||
usermod -u $uid $USER | ||
fi | ||
fi | ||
|
||
# このスクリプト自体は root で実行されているので、uid/gid 調整済みの rust ユーザー | ||
# として指定されたコマンドを実行する。 | ||
exec setpriv --reuid=$USER --regid=$USER --init-groups "$@" |