-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathonCreateCommand.sh
executable file
·101 lines (90 loc) · 3.25 KB
/
onCreateCommand.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env bash
# Copyright (c) 2023 b-data GmbH.
# Distributed under the terms of the MIT License.
set -e
# Create user's private bin
mkdir -p "$HOME/.local/bin"
# Create user's projects and workspaces folder
mkdir -p "$HOME/projects"
mkdir -p "$HOME/workspaces"
# Copy scripts from skeleton directory if home directory is bind mounted
if [ ! -f "$HOME/.local/bin/dockerSystemPrune.sh" ]; then
if [ -f /etc/skel/.local/bin/dockerSystemPrune.sh ]; then
cp /etc/skel/.local/bin/dockerSystemPrune.sh "$HOME/.local/bin";
fi
fi
if [ ! -f "$HOME/.local/bin/checkForUpdates.sh" ]; then
if [ -f /etc/skel/.local/bin/checkForUpdates.sh ]; then
cp /etc/skel/.local/bin/checkForUpdates.sh "$HOME/.local/bin";
fi
fi
# Copy Bash-related files from root's backup directory
if [ "$(id -un)" == "root" ]; then
if [ ! -f /root/.bashrc ]; then
cp /var/backups/root/.bashrc /root;
fi
if [ ! -f /root/.profile ]; then
cp /var/backups/root/.profile /root;
fi
fi
# Copy Zsh-related files and folders from the untouched home directory
if [ "$(id -un)" == "root" ]; then
if [ ! -d /root/.oh-my-zsh ]; then
cp -R /home/*/.oh-my-zsh /root;
fi
if [ ! -f /root/.zshrc ]; then
cp /home/*/.zshrc /root;
fi
else
if [ ! -d "$HOME/.oh-my-zsh" ]; then
sudo cp -R /root/.oh-my-zsh "$HOME";
sudo chown -R "$(id -u)":"$(id -g)" "$HOME/.oh-my-zsh";
fi
if [ ! -f "$HOME/.zshrc" ]; then
sudo cp /root/.zshrc "$HOME";
sudo chown "$(id -u)":"$(id -g)" "$HOME/.zshrc";
fi
fi
if [ "$(command -v mojo)" ]; then
# Append the user's modular bin dir to PATH
if ! grep -q "user's modular bin dir" "$HOME/.bashrc"; then
echo MODULAR_HOME=\"\$HOME/.modular\" > /tmp/magicenv
(curl -ssL https://magic.modular.com || cat /var/tmp/magicenv.bak) \
| grep '^BIN_DIR' | tee -a /tmp/magicenv > /dev/null
. /tmp/magicenv
mkdir -p "${BIN_DIR}"
sed -i 's/\$HOME/\\$HOME/g' /tmp/magicenv
. /tmp/magicenv
echo -e "\n# Append the user's modular bin dir to PATH\nif [[ \"\$PATH\" != *\"${BIN_DIR}\"* ]] ; then\n PATH=\"\$PATH:${BIN_DIR}\"\nfi" >> "$HOME/.bashrc"
rm /tmp/magicenv
fi
if ! grep -q "user's modular bin dir" "$HOME/.zshrc"; then
echo MODULAR_HOME=\"\$HOME/.modular\" > /tmp/magicenv
(curl -ssL https://magic.modular.com || cat /var/tmp/magicenv.bak) \
| grep '^BIN_DIR' | tee -a /tmp/magicenv > /dev/null
. /tmp/magicenv
mkdir -p "${BIN_DIR}"
sed -i 's/\$HOME/\\$HOME/g' /tmp/magicenv
. /tmp/magicenv
echo -e "\n# Append the user's modular bin dir to PATH\nif [[ \"\$PATH\" != *\"${BIN_DIR}\"* ]] ; then\n PATH=\"\$PATH:${BIN_DIR}\"\nfi" >> "$HOME/.zshrc"
rm /tmp/magicenv
fi
fi
# If existent, prepend the user's private bin to PATH
if ! grep -q "user's private bin" "$HOME/.bashrc"; then
cat "/var/tmp/snippets/rc.sh" >> "$HOME/.bashrc"
fi
if ! grep -q "user's private bin" "$HOME/.zshrc"; then
cat "/var/tmp/snippets/rc.sh" >> "$HOME/.zshrc"
fi
# Enable Oh My Zsh plugins
sed -i "s/plugins=(git)/plugins=(docker docker-compose git git-lfs pip screen tmux vscode)/g" \
"$HOME/.zshrc"
# Remove old .zcompdump files
rm -f "$HOME"/.zcompdump*
# Fix for older versions
if [ -d /opt/TinyTeX ]; then
if [ "$(stat -c %G /opt/TinyTeX)" != "users" ]; then
sudo chown -R :users /opt/TinyTeX
fi
fi