dev-scripts/scripts/debian10/install-user.sh

74 lines
2.2 KiB
Bash
Raw Normal View History

2020-09-03 16:56:14 +00:00
#!/bin/sh
# check we have ssh access
[ -z "$ssh_root" ] && echo "Error: no root ssh configuration specified" && exit 5
2020-09-03 16:56:14 +00:00
_home_dir="/home/$user"
ssh -T $ssh_root << EOSSH
2020-09-04 20:49:28 +00:00
echo "Creating user .."
useradd -m -d "$_home_dir" "$user"
echo "$user:$user_pass" | chpasswd
usermod -aG sudo "$user"
EOSSH
2020-09-04 20:19:35 +00:00
2020-09-04 20:49:28 +00:00
echo "Configuring ssh .."
ssh $ssh_root mkdir -v -p "$_home_dir/.ssh"
scp files/private/id_rsa "$ssh_root:$_home_dir/.ssh/"
scp files/id_rsa.pub "$ssh_root:$_home_dir/.ssh/"
scp files/known_hosts "$ssh_root:$_home_dir/.ssh/"
2020-09-03 16:56:14 +00:00
ssh -T $ssh_root << EOSSH
2020-09-04 20:49:28 +00:00
cp -v /root/.ssh/authorized_keys "$_home_dir/.ssh/authorized_keys"
chown -v -R "$user:$group" "$_home_dir/.ssh"
2020-09-04 20:19:35 +00:00
echo "Adding user: $user"
2020-09-04 17:50:00 +00:00
if [ -f /etc/locale.gen ] && command -v locale-gen ; then
echo 'en_GB.UTF-8 UTF-8' > /etc/locale.gen
locale-gen
echo 'LANG="en_GB.UTF-8"' > /etc/default/locale
else
echo 'Warning: cannot set locale'
fi
2020-09-03 16:56:14 +00:00
echo "Installing required packages .."
export DEBIAN_FRONTEND=noninteractive
2020-09-04 21:24:19 +00:00
echo "Installing packages .."
apt-get -qq -y install sudo git tmux zsh curl
echo "Packages installed"
2020-09-03 16:56:14 +00:00
echo "Cloning configuration files .."
2020-09-04 20:19:35 +00:00
su --login "$user"
git config --global user.name rayelliott
git config --global user.email dev@rayelliott.dev
2020-09-04 20:49:28 +00:00
mkdir -v -p "$_home_dir/.config"
2020-09-03 16:56:14 +00:00
if [ -e "$_home_dir/.config/profile" ] ; then
2020-09-04 20:49:28 +00:00
mv -v "$_home_dir/.config/profile" "$_home_dir/.config/profile-original-$(date +%s)"
2020-09-03 16:56:14 +00:00
fi
2020-09-04 20:19:35 +00:00
git clone ssh://git@git.rayelliott.dev:3222/dots/profile.git "$_home_dir/.config/profile"
2020-09-03 16:56:14 +00:00
"$_home_dir/.config/profile/install.sh"
if [ -e "$_home_dir/.config/tmux" ] ; then
2020-09-04 20:49:28 +00:00
mv -v "$_home_dir/.config/tmux" "$_home_dir/.config/tmux-original-$(date +%s)"
2020-09-03 16:56:14 +00:00
fi
2020-09-04 20:19:35 +00:00
git clone ssh://git@git.rayelliott.dev:3222/dots/tmux.git "$_home_dir/.config/tmux"
2020-09-03 16:56:14 +00:00
"$_home_dir/.config/tmux/install.sh"
if [ -e "$_home_dir/.config/zsh" ] ; then
2020-09-04 20:49:28 +00:00
mv -v "$_home_dir/.config/zsh" "$_home_dir/.config/zsh-original-$(date +%s)"
2020-09-03 16:56:14 +00:00
fi
2020-09-04 20:19:35 +00:00
git clone ssh://git@git.rayelliott.dev:3222/dots/zsh.git "$_home_dir/.config/zsh"
2020-09-03 16:56:14 +00:00
"$_home_dir/.config/zsh/install.sh"
EOSSH
ssh -T $ssh_root << EOSSH
2020-09-03 16:56:14 +00:00
chsh -s /usr/bin/zsh "$user"
EOSSH
2020-09-04 19:20:07 +00:00
echo "Configuring wakatime plugin .."
pwd
scp files/private/wakatime.cfg "$user@$domain:/home/$user/.wakatime.cfg"