|| die "${MSG}"
}
augment_profile() {
+ local ALIAS_LS='alias ls="ls --color=auto"'
msg 'Augmenting user %s …' "${FNAME_PROFILE}"
- echo 'alias ls="ls --color=auto"' >> "${PATH_PROFILE}"
+ # test ensures idempotency
+ grep -qxF "${ALIAS_LS}" "${PATH_PROFILE}" 2>/dev/null\
+ || echo "${ALIAS_LS}" >> "${PATH_PROFILE}"
}
start_root() {
local TARGET=$1
msg 'Ensuring packages: %s' "${TO_INSTALL}"
apt-get -y install ${TO_INSTALL}
- msg 'Setting up user: %s' "${USERNAME}"
- adduser --disabled-password --comment "" "${USERNAME}"
- retry_until_success passwd "${USERNAME}"
+ if try_quiet id -u "${USERNAME}"; then
+ msg 'User %s already exists, skipping creation …' "${USERNAME}"
+ else
+ msg 'Setting up user: %s' "${USERNAME}"
+ adduser --disabled-password --comment "" "${USERNAME}"
+ retry_until_success passwd "${USERNAME}"
+ fi
usermod -a -G sudo "${USERNAME}"
augment_profile
augment_profile
msg 'Linking %s files into home directory …' "${PATH_SKEL_USER}"
-find "${PATH_SKEL_USER}" -mindepth 1 -maxdepth 1\
- -exec ln -v -s {} "${HOME}/" \;
+find "${PATH_SKEL_USER}" -mindepth 1 -maxdepth 1 | while IFS= read -r SRC; do
+ DEST="${HOME}/$(basename "${SRC}")"
+ if [ -e "${DEST}" ] || [ -L "${DEST}" ]; then
+ msg 'Skipping already-found %s …' "${DEST}"
+ else
+ ln -v -s "${SRC}" "${DEST}"
+ fi
+done