Last active
January 9, 2020 10:24
-
-
Save akihiro/7b9525153b939b8ca0b0baa3f6af6be3 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
[[ -z $STATE ]] && export STATE=init | |
case "$STATE" in | |
init) | |
export STATE=unshare | |
sudo -E unshare -mpf "$0" | |
# cleanup が不要ならexecでも良い | |
exit 0 | |
;; | |
unshare) | |
export STATE=pivot_root | |
# pivot_rootとか | |
exit | |
;; | |
pivot_root) | |
export STATE=sudo | |
# デフォルトの作業ディレクトリとかにcdしたり環境変数設定したり | |
# mountとか | |
sudo -E -i -u container "$0" | |
exit | |
;; | |
sudo) | |
# enter interactive shell | |
bash | |
esac | |
## chrootなどする場合はfiledescriptorを持ち回すとか? | |
# 10<$0 | |
# sudo -E -i -u container /dev/fd/10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment