Skip to content

Commit 8fa25bd

Browse files
committed
Fix multi-user setup
1 parent 40ec656 commit 8fa25bd

4 files changed

Lines changed: 94 additions & 45 deletions

File tree

1-BasicSetUp.sh

Lines changed: 56 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -57,29 +57,41 @@ sudo sed -i '/zsh/d' /etc/shells 2>/dev/null || true
5757

5858
spatialPrint "Setting up Zsh + Zim now"
5959
execute sudo apt-get install zsh -y
60-
sudo mkdir -p /opt/.zsh/ && sudo chmod ugo+w /opt/.zsh/
60+
sudo mkdir -p /opt/.zsh/ && sudo chmod a+rw -R /opt/.zsh/
6161
export ZIM_HOME=/opt/.zsh/zim
62+
export ZIM_CONFIG_FILE=/opt/.zsh/zim/zimrc
6263
curl -fsSL https://raw.githubusercontent.com/zimfw/install/master/install.zsh | zsh
6364
# Change default shell to zsh
64-
command -v zsh | sudo tee -a /etc/shells
6565
sudo chsh -s "$(command -v zsh)" "${USER}"
6666
sudo useradd -D -s /bin/zsh
6767

68+
69+
# Append 'zmodule steeef' to the zimrc configuration file
70+
echo "zmodule steeef" | sudo tee -a /opt/.zsh/zim/zimrc >/dev/null
71+
sudo chmod -R a+rw /opt/.zsh/
72+
6873
execute sudo apt-get install aria2 -y
6974

7075
# Create bash aliases
7176
cp ./config_files/bash_aliases /opt/.zsh/bash_aliases >/dev/null # Suppress error messages in case the file already exists
7277
rm -f ~/.bash_aliases
7378
ln -s /opt/.zsh/bash_aliases ~/.bash_aliases
7479

80+
# Set ZIM_CONFIG_FILE at the start of ~/.zshrc, then append existing content, then the rest
81+
tmp_zshrc="$(mktemp)"
82+
echo "ZIM_CONFIG_FILE=/opt/.zsh/zim/zimrc" > "$tmp_zshrc"
83+
cat ~/.zshrc >> "$tmp_zshrc"
7584
{
85+
echo ""
86+
echo ""
7687
echo "if [ -f ~/.bash_aliases ]; then"
7788
echo " source ~/.bash_aliases"
7889
echo "fi"
79-
90+
echo ""
8091
echo "# Switching to 256-bit colour by default so that zsh-autosuggestion's suggestions are not suggested in white, but in grey instead"
8192
echo "export TERM=xterm-256color"
82-
} >> ~/.zshrc
93+
} >> "$tmp_zshrc"
94+
mv "$tmp_zshrc" ~/.zshrc
8395

8496
# Now create shortcuts
8597
execute sudo apt-get install run-one xbindkeys wmctrl xdotool -y
@@ -178,33 +190,50 @@ fi
178190

179191

180192
## Install zellij
181-
wget https://github.com/zellij-org/zellij/releases/download/v0.43.1/zellij-x86_64-unknown-linux-musl.tar.gz
182-
tar -xvf zellij-x86_64-unknown-linux-musl.tar.gz
183-
chmod +x zellij
184-
sudo mv zellij /usr/local/bin/
185-
rm -rf ./zellij*
193+
if [ -x "$(command -v zellij)" ]; then
194+
echo "Zellij already installed, skipping it"
195+
else
196+
wget https://github.com/zellij-org/zellij/releases/download/v0.43.1/zellij-x86_64-unknown-linux-musl.tar.gz
197+
tar -xvf zellij-x86_64-unknown-linux-musl.tar.gz
198+
chmod +x zellij
199+
sudo mv zellij /usr/local/bin/
200+
rm -rf ./zellij*
201+
fi
186202

187203
## Install Neovim with all essential lazyvim plugins
188-
189-
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
190-
sudo apt install -y build-essential "lua5.1" luarocks ripgrep fd-find fzf nodejs
191-
mkdir -p ~/.local/bin
192-
ln -s $(which fdfind) ~/.local/bin/fd
193-
rm -rf ~/.local/share/nvim/
194-
rm -rf ~/.config/nvim/
204+
if [ -x "$(command -v nvim)" ] && [ -d ~/.config/nvim ]; then
205+
echo "Neovim and LazyVim already installed, skipping installation"
206+
else
207+
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
208+
sudo apt install -y nodejs
209+
sudo apt install -y build-essential "lua5.1" luarocks ripgrep fd-find fzf
210+
211+
mkdir -p ~/.local/bin
212+
if [ ! -L ~/.local/bin/fd ]; then
213+
ln -s $(which fdfind) ~/.local/bin/fd
214+
fi
215+
216+
rm -rf ~/.local/share/nvim/
217+
rm -rf ~/.config/nvim/
218+
219+
sudo add-apt-repository ppa:neovim-ppa/unstable -y
220+
sudo apt update
221+
sudo apt install -y neovim
222+
223+
git clone https://github.com/LazyVim/starter ~/.config/nvim
224+
rm -rf ~/.config/nvim/.git
225+
fi
195226

196227
## Install nerd fonts
197-
sudo mkdir -p /usr/local/share/fonts
198-
wget -O /tmp/VictorMono.zip \
199-
https://github.com/ryanoasis/nerd-fonts/releases/latest/download/VictorMono.zip
200-
sudo unzip /tmp/VictorMono.zip -d /usr/local/share/fonts/VictorMono
201-
sudo fc-cache -fv
202-
203-
sudo add-apt-repository ppa:neovim-ppa/unstable -y
204-
sudo apt update
205-
sudo apt install -y neovim
206-
git clone https://github.com/LazyVim/starter ~/.config/nvim
207-
rm -rf ~/.config/nvim/.git
228+
if [ -d /usr/local/share/fonts/VictorMono ]; then
229+
echo "Nerd fonts (VictorMono) already installed, skipping installation"
230+
else
231+
sudo mkdir -p /usr/local/share/fonts
232+
wget -O /tmp/VictorMono.zip \
233+
https://github.com/ryanoasis/nerd-fonts/releases/latest/download/VictorMono.zip
234+
sudo unzip /tmp/VictorMono.zip -d /usr/local/share/fonts/VictorMono
235+
sudo fc-cache -fv
236+
fi
208237

209238

210239
# Force GDM to use Xorg (X11) instead of Wayland (skip in CI - no display manager)

README.md

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,7 @@ Then execute them in the terminal in the sequence of filenames using `./1-BasicS
3939
<br>
4040

4141
## Notes
42-
* If you are using this script to set up a computer with many users,
43-
* You need to run these scripts using **only one** user, say `first_user`. But make sure you have **logged in at least once** into the new user so that the home directory of the other user is instantiated.
44-
* We need to copy the configuration files to the new user, say `new_user`. From `first_user`'s account, run the following after entering the username of the `new_user` in the second line of this snippet
45-
```bash
46-
cd ~
47-
export NEW_USER=<username_of_new_user>
48-
sudo cp /opt/.zsh/bash_aliases /home/$NEW_USER/.bash_aliases
49-
sudo cp -r ~/.zim/ /home/$NEW_USER/.zim
50-
sudo cp ~/.zimrc /home/$NEW_USER/.zimrc
51-
sudo cp ~/.zlogin /home/$NEW_USER/.zlogin
52-
sudo cp ~/.zshrc /home/$NEW_USER/.zshrc
53-
sudo cp ~/.zshenv /home/$NEW_USER/.zshenv
54-
55-
sudo cp ~/.xbindkeysrc /home/$NEW_USER
56-
57-
sudo chown -R $NEW_USER: /home/$NEW_USER/.zim /home/$NEW_USER/.bash_aliases /home/$NEW_USER/.zimrc /home/$NEW_USER/.zlogin /home/$NEW_USER/.zshrc /home/$NEW_USER/.xbindkeysrc /home/$NEW_USER/.config/tilda /home/$NEW_USER/.tmux.conf*
58-
```
42+
* **Adding a new OS user:** If setting up multiple users on the OS, try to use the script `./add_new_user.sh` in this repo. It will set the correct settings for them to also benefit from zsh, conda, etc.
5943
* Make sure that your system time and date is correct and synchronized before running the scripts, otherwise this will cause failure while trying to download the packages.
6044
* These scripts are written and tested on the following configurations:
6145
* Ubuntu 24.04 (Noble) and 26.04 (Oracular) LTS releases

add_new_user.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
# Argument Data Validation
4+
if [[ $# -ne 1 ]]; then
5+
echo "Please pass the username as an argument"
6+
exit 1
7+
fi
8+
USERNAME=$1
9+
10+
# Check if user already exists
11+
if id "$USERNAME" &>/dev/null; then
12+
echo "User $USERNAME already exists"
13+
exit 1
14+
fi
15+
16+
# Create the user, and set the default password
17+
sudo useradd -m -s /bin/zsh "$USERNAME"
18+
19+
# Add the user to the docker group
20+
sudo usermod -aG docker "$USERNAME"
21+
22+
# Copy the configuration files
23+
USER_HOMEDIR=$(getent passwd "$USERNAME" | cut -d: -f6)
24+
sudo mkdir -p "$USER_HOMEDIR/.config"
25+
sudo cp ~/.zshrc ~/.xbindkeysrc "$USER_HOMEDIR"
26+
sudo cp /opt/.zsh/bash_aliases "$USER_HOMEDIR/.bash_aliases"
27+
sudo cp -r ~/.config/nvim/ "$USER_HOMEDIR/.config"
28+
29+
sudo ln -s "$USER_HOMEDIR" /home 2>/dev/null || true
30+
31+
# Change user folder permission, and disable others from reading it
32+
sudo chown "$USERNAME:$USERNAME" -R "$USER_HOMEDIR"
33+
sudo chmod o-rwX -R "$USER_HOMEDIR"
34+
35+
# Force user to change password on first login
36+
sudo chage -d 0 "$USERNAME"

config_files/bash_aliases

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ alias glog="git log --graph --abbrev-commit --decorate --format=format:'%C(bold
88
alias update="sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y"
99
alias aria="aria2c --file-allocation=none -c -x 10 -s 10"
1010
alias cat="batcat -p"
11-
alias vi = "nvim"
11+
alias vi="nvim"

0 commit comments

Comments
 (0)