-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·217 lines (187 loc) · 6.27 KB
/
setup.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
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#!/bin/bash
set -euo pipefail
USER=$(whoami)
STATE_FILE="/tmp/setup_state.txt"
# Function to check if a step has been completed
step_completed() {
grep -q "^$1$" "$STATE_FILE" 2>/dev/null
}
# Function to mark a step as completed
mark_step_completed() {
echo "$1" >> "$STATE_FILE"
}
# Add interactive mode option
interactive=false
# Parse command-line arguments
while [[ "$#" -gt 0 ]]; do
case $1 in
-i|--interactive) interactive=true ;;
*) echo "Unknown parameter: $1"; exit 1 ;;
esac
shift
done
# Function to prompt user in interactive mode
prompt_user() {
if [ "$interactive" = true ]; then
read -p "$1? (y/n): " choice
case "$choice" in
y|Y ) return 0 ;;
n|N ) return 1 ;;
* ) echo "Invalid input. Skipping..."; return 1 ;;
esac
else
return 0
fi
}
# Update and upgrade
if ! step_completed "update_upgrade"; then
echo "Installing Updates"
if sudo apt-get update && sudo apt-get -y full-upgrade >/dev/null; then
mark_step_completed "update_upgrade"
else
echo "Error: Failed to update and upgrade. Exiting."
exit 1
fi
else
echo "Updates already installed. Skipping."
fi
# Install packages
if ! step_completed "install_packages"; then
if prompt_user "Install Packages"; then
echo "Installing Packages"
if sudo apt-get -y install git vim pipenv curl speedtest-cli zsh samba samba-common-bin jq wireguard-tools openvpn >/dev/null; then
mark_step_completed "install_packages"
else
echo "Error: Failed to install packages. Exiting."
exit 1
fi
fi
else
echo "Packages already installed. Skipping."
fi
# Configure as Media Server
if ! step_completed "configure_media_server"; then
if prompt_user "Configure as Media Server"; then
echo "Installing Plex"
echo "deb https://downloads.plex.tv/repo/deb public main" | sudo tee /etc/apt/sources.list.d/plexmediaserver.list
curl https://downloads.plex.tv/plex-keys/PlexSign.key | sudo apt-key add -
if sudo apt-get update && sudo apt-get -y install qbittorrent qbittorrent-nox plexmediaserver >/dev/null; then
echo "Installing qbittorrent"
qbit_content="[Unit]
Description=qBittorrent
After=network.target
[Service]
Type=forking
User=$USER
Group=$USER
UMask=002
ExecStart=/usr/bin/qbittorrent-nox -d --webui-port=8080
Restart=on-failure
[Install]
WantedBy=multi-user.target
"
qbit_service="/etc/systemd/system/qbittorrent.service"
echo "$qbit_content" | sudo tee -a "$qbit_service"
echo "Content added to $qbit_service successfully."
cat $qbit_service
if sudo systemctl start qbittorrent && sudo systemctl enable qbittorrent; then
mark_step_completed "configure_media_server"
else
echo "Error: Failed to start or enable qbittorrent. Exiting."
exit 1
fi
else
echo "Error: Failed to install media server packages. Exiting."
exit 1
fi
fi
else
echo "Media server already configured. Skipping."
fi
# Configure Samba Server
if ! step_completed "configure_samba_server"; then
if prompt_user "Configure Samba Server"; then
echo "Configuring Samba Server"
smb_content="[PiDisk]
path = /home/$USER/Media
writeable = Yes
create mask = 0777
directory mask = 0777
public = no
"
smb_conf="/etc/samba/smb.conf"
if [ -f "$smb_conf" ]; then
echo "File $smb_conf already exists. Appending the content."
else
echo "Creating new file $smb_conf."
sudo touch "$smb_conf"
fi
echo "$smb_content" | sudo tee -a "$smb_conf"
echo "Content added to $smb_conf successfully."
cat $smb_conf
sudo smbpasswd -a "$USER"
sudo systemctl restart smbd
mark_step_completed "configure_samba_server"
fi
else
echo "Samba server already configured. Skipping."
fi
# Configure VPN
if ! step_completed "configure_vpn"; then
if prompt_user "Configure VPN"; then
echo "Cloning Important Repos"
git clone https://github.com/pia-foss/manual-connections
echo "Enter PIA Username:"
read -r pia_username
echo "Enter PIA Password:"
read -r pia_password
touch .env
# Export VPN Credentials
echo -e "\nexport PIA_USERNAME=$pia_username" | tee -a ".env"
echo -e "\nexport PIA_PASS=$pia_password" | tee -a ".env"
mark_step_completed "configure_vpn"
fi
else
echo "VPN already configured. Skipping."
fi
echo "Enter git config user.name"
read -r git_user_name
git config --global user.name "$git_user_name"
echo "Enter git config user.email"
read -r git_email
git config --global user.email "$git_email"
git config --global init.defaultBranch "main"
git config --global pull.rebase true
git config --global core.editor "vim"
# Configure SSH Key
ssh-keygen -t ed25519 -C "$USER@$(hostname).local" -f "/home/$USER/.ssh/id_ed25519" -P ""
touch ~/.ssh/authorized_keys
echo "Configuring ZSH"
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git "${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}"/plugins/zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-autosuggestions "${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}"/plugins/zsh-autosuggestions
zsh_content=$(cat <<'EOL'
LC_CTYPE=en_US.UTF-8
LC_ALL=en_US.UTF-8
export PATH="$HOME/bin:/usr/local/bin:$PATH"
export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME="robbyrussell"
plugins=(
git
history
common-aliases
zsh-autosuggestions
zsh-syntax-highlighting
)
source "$ZSH/oh-my-zsh.sh"
source "$HOME/.env"
EOL
)
echo "$zsh_content" > ~/.zshrc
echo "Added config to ~/.zshrc. Setting zsh as default shell"
echo "Installing Docker"
curl -sSL https://get.docker.com | sh
sudo usermod -aG docker $USER
echo "Setting the shell to zsh, please enter your password when prompted."
chsh -s /bin/zsh
echo "Setup complete!"