-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshellnice.sh
More file actions
executable file
·164 lines (131 loc) · 3.51 KB
/
Copy pathshellnice.sh
File metadata and controls
executable file
·164 lines (131 loc) · 3.51 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/bin/bash
set -x
IFS= read -r -d '' WELCOME << 'EOF'
_________.__ .__ .__ .__
/ _____/| |__ ____ | | | | ____ |__| ____ ____
\_____ \ | | \_/ __ \| | | | / \| | ____\/ __ \
/ \| Y \ ___/| |_| |_| | \ \ \__\ ___/
/_______ /|___| /\___ >____/____/___| /__|\___ >___ >
\/ \/ \/ \/ \/ \/
EOF
IFS= read -r -d '' HELP << 'EOF'
shellnice - makes your shell nice!
this will install zsh, oh-my-zsh, neovim and fastfetch.
usage: Shellnice.sh [flags]
flags:
-r reboots the machine at the end of everything
-e installs extended Toolset
-h display this text
EOF
SHELLSWAP=true
REBOOT=false
EXTENDED=false
main() {
## handle cli flags
while getopts "reh" opt; do
case $opt in
r) REBOOT=true;;
e) EXTENDED=true;;
h) echo "$HELP";exit;;
esac
done
## run the components:
apt update -y
install_basic_toolset
if [ "$EXTENDED" == true ]; then
install_extended_toolset
fi
if [ "$REBOOT" == true ]; then
reboot_routine
else
echo "swapping to zsh"
exec zsh -c "echo \"$WELCOME\"; echo 'installation complete. rerun with -r to reboot after install'; exec zsh -l"
fi
}
## the components
install_basic_toolset() {
echo 'installing basic packages ...'
## apt packages
while read -r target; do
echo "installing: $target"
apt install -y "$target"
done <<EOF
git
curl
zsh
tree
fastfetch
neovim
EOF
echo "running Postinstall commands"
CHSH=no sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended < /dev/null
apt -y upgrade
chsh -s $(which zsh) ${SUDO_USER:-$USER}
# ## all commands to be executed normally
# while read -r command; do
# eval "$command"
# done <<EOF
#CHSH=no sh -c "\$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
#apt -y upgrade
#chsh -s \$(which zsh) \${SUDO_USER:-\$USER}
#EOF
}
install_extended_toolset() {
echo 'installing extended packages...'
## all apt installs
while read -r target; do
echo "installing: $target"
apt install -y "$target"
done <<EOF
tmux
htop
iftop
broot
EOF
## all commands to be executed normally
while read -r command; do
eval "$command"
done <<EOF
apt -y upgrade
EOF
}
reboot_routine() {
local target_user="${SUDO_USER:-$USER}"
local target_home
target_home=$(getent passwd "$target_user" | cut -d: -f6)
local marker="$target_home/.config/.shellnice_welcome_shown"
local profile_script="/etc/profile.d/shellnice_welcome.sh"
# post_reboot_commands-Funktion als Text exportieren
local post_reboot_fn
post_reboot_fn=$(declare -f post_reboot_commands)
# Script nach /etc/profile.d/ schreiben — kein .bashrc anfassen
cat > "$profile_script" << SCRIPT
#!/bin/bash
# shellnice: einmalige Welcome-Message nach Setup-Reboot
# Liegt in /etc/profile.d/ und wird von jeder Login-Shell automatisch gesourct.
# Löscht sich selbst nach der Ausführung.
MARKER="$marker"
TARGET_USER="$target_user"
if [[ ! -f "\$MARKER" ]]; then
mkdir -p "\$(dirname \$MARKER)"
touch "\$MARKER"
chown "$target_user:$target_user" "\$MARKER"
cat << 'WELCOMEOF'
$WELCOME
WELCOMEOF
fastfetch
$post_reboot_fn
post_reboot_commands "\$TARGET_USER"
# nach Ausführung selbst entfernen — kein toter Code in profile.d
rm -f "$profile_script"
fi
SCRIPT
chmod +x "$profile_script"
echo "welcome script installed to $profile_script"
echo 'setup done — rebooting in 5 seconds. press ctrl+c to abort.'
sleep 5
reboot
}
{
main "$@"
}