Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- set -o errexit
- set -o pipefail
- add_user() {
- local username="$1"
- local password="$2"
- if id -u "${username}" &>/dev/null; then
- return
- fi
- useradd -m -U -G wheel -s /bin/bash "${username}"
- echo "${username}:${password}" | chpasswd
- }
- add_sudoers() {
- local username="$1"
- chmod u+w /etc/sudoers
- if [[ "$(grep -P "${username}\tALL=\(ALL\)\s+?ALL" "/etc/sudoers" 2>/dev/null)" != "" ]]; then
- return
- fi
- echo -e "${username}\tALL=(ALL)\tALL" >> "/etc/sudoers"
- chmod u-w /etc/sudoers
- }
- main() {
- local username="$1"
- local password="$2"
- add_user "${username}" "${password}"
- add_sudoers "${username}"
- }
- main "$@"
Add Comment
Please, Sign In to add comment