71 lines
3.0 KiB
Bash
71 lines
3.0 KiB
Bash
#! /usr/bin/env bash
|
|
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
|
USER_HOME=$HOME
|
|
[[ -n "${SUDO_USER}" ]] && USER_HOME="$(eval "echo ~${SUDO_USER}")"
|
|
|
|
source $(ls -1 ~/.*.shrc | head -1); [[ -z "${SHRC_D}" ]] && { echo "ERROR: Couldn't load ~/.*.shrc script!" 1>&2; return 1 2>/dev/null; exit 1; }
|
|
source ${SHRC_D}/${SHELL##*/}.pre/21_aliases
|
|
source ${SHRC_D}/01_util.functions
|
|
source ${SHRC_D}/97_chezmoi_aliases
|
|
|
|
set -e
|
|
|
|
require_sudo \
|
|
|| eval $(error 3 "POLARISqb: Not in sudo group, skipping $(basename $0)")
|
|
|
|
printf "%s\n" \
|
|
"POLARISqb Workstation/Laptop Owner initialization tool" \
|
|
"" \
|
|
"The machine will be initialized with the following values unless" \
|
|
"specified otherwise:" \
|
|
"" \
|
|
$(cz-import-data) \
|
|
""
|
|
|
|
eval "$(cz-import-data)"
|
|
|
|
if [[ -z "${CZ_PQB_DATA_LOCAL_USER_NAME}" ]]; then eval $(error 1 \
|
|
"local_user_name not defined in 'cehzmoi data', " "please run 'chezmoi init' or 'chezmoi edit-config' to fix, then try again"
|
|
); fi
|
|
|
|
if [[ -n "$(getent passwd ${CZ_PQB_DATA_LOCAL_USER_NAME})" ]]; then eval $(error 2 \
|
|
"User '${CZ_PQB_DATA_LOCAL_USER_NAME}' already exists, aborting."
|
|
); fi
|
|
|
|
#gecos field: "Full_Name,Room_Number,Work_Phone,Home_Phone,Other"
|
|
sudo adduser --disabled-password --gecos "${CZ_PQB_DATA_LOCAL_OWNER_NAME},,,,${CZ_PQB_DATA_EMAIL}" ${CZ_PQB_DATA_LOCAL_USER_NAME}
|
|
sudo adduser ${CZ_PQB_DATA_LOCAL_USER_NAME} sudo
|
|
INITIAL_PASSWORD='password'
|
|
printf "${CZ_PQB_DATA_LOCAL_USER_NAME}:${INITIAL_PASSWORD}" | sudo chpasswd
|
|
|
|
NEW_USER_HOME=$( eval "printf ~${CZ_PQB_DATA_LOCAL_USER_NAME}" )
|
|
if [[ -z "${NEW_USER_HOME}" ]]; then eval $(error 3 \
|
|
"Something is wrong, couldn't find the home dir for ${CZ_PQB_DATA_LOCAL_USER_NAME}!"
|
|
); fi
|
|
|
|
NEW_HOSTNAME="${CZ_PQB_DATA_LOCAL_USER_NAME}-pqb"
|
|
[[ "$(hostname)" != "${NEW_HOSTNAME}" ]] && sudo hostname $NEW_HOSTNAME
|
|
|
|
_CZ_REMOTE_URL=$(chezmoi git -- remote get-url origin)
|
|
_CZ_REMOTE_BRANCH=$(chezmoi git -- branch --show-current)
|
|
_CZ_DATA_PAIRS="$(cz-import-data promptString)"
|
|
cat ~/.config/chezmoi/chezmoi.toml | env sudo -u ${CZ_PQB_DATA_LOCAL_USER_NAME} -- sh -c "mkdir -p ~/.config/chezmoi; cat - > ~/.config/chezmoi/chezmoi.toml"
|
|
sudo -u ${CZ_PQB_DATA_LOCAL_USER_NAME} -- sh -c "cd ~; $(curl -fsLS chezmoi.io/get)" -- init --promptString="${_CZ_DATA_PAIRS}" --apply --branch "${_CZ_REMOTE_BRANCH}" "${_CZ_REMOTE_URL}"
|
|
|
|
echo "Chezmoi complete"
|
|
|
|
CUR_USER=$SUDO_USER
|
|
[[ -z "$CUR_USER" ]] && CUR_USER=$USER
|
|
|
|
# setup local git config values
|
|
git config --global --get user.email > /dev/null || git config --global user.email "${CUR_USER}@${NEW_HOSTNAME}"
|
|
git config --global --get user.name > /dev/null || git config --global user.name $(getent passwd $USER | cut -d':' -f5 | cut -d',' -f1)
|
|
|
|
sudo -u ${CZ_PQB_DATA_LOCAL_USER_NAME} -- sh -c "cd ~; git config --global user.email '${CZ_PQB_DATA_EMAIL}' && git config --global user.name '${CZ_PQB_DATA_LOCAL_OWNER_NAME}'"
|
|
|
|
sudo chage -d0 ${CZ_PQB_DATA_LOCAL_USER_NAME}
|
|
|
|
#${CZ_PQB_DATA_EMAIL}
|
|
#${CZ_PQB_DATA_LOCAL_OWNER_NAME}
|
|
#${CZ_PQB_DATA_LOCAL_USER_NAME}
|