-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
99 lines (81 loc) · 3.01 KB
/
install.sh
File metadata and controls
99 lines (81 loc) · 3.01 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
#!/bin/bash
# Make sure the script is run as root
if [ "$EUID" -ne 0 ]; then
echo "Please run as root (or use sudo)"
exit 1
fi
# Display a welcome message
echo "Welcome to the server setup script!"
echo ""
# Setup new user account (if desired)
read -p "Do you want to create a new user account? (Y/n): " NEW_USER
if [[ "$NEW_USER" =~ ^[Yy] ]]; then
read -p "Enter the username for the new user: " NEW_USERNAME
adduser "$NEW_USERNAME"
usermod -aG sudo "$NEW_USERNAME"
echo "New user account created."
echo ""
fi
# Update package list and install required packages
echo "Updating package list..."
apt-get update
echo "Installing nginx, MariaDB, PHP, and required PHP extensions..."
apt-get install -y nginx mariadb-server php-fpm php-mysql php-cli php-curl php-gd php-xml php-mbstring curl unzip
echo "Installing additional utilities: neovim, zsh, git, and certbot with nginx plugin..."
apt-get install -y neovim git certbot python3-certbot-nginx
# Setup custom MOTD
echo "Setting up custom MOTD..."
cp motd_update.sh /etc/update-motd.d/99-custom
chmod +x /etc/update-motd.d/99-custom
# Determine the non-root user (if running via sudo, use SUDO_USER; otherwise, current user)
if [ -n "$SUDO_USER" ]; then
USERNAME="$SUDO_USER"
else
USERNAME="$(whoami)"
fi
# Setup new ssh keys
echo "Setting up new SSH keys..."
ssh-keygen -t rsa -b 4096 -C "$USERNAME@$(hostname)" -f ~/.ssh/id_rsa -N ""
echo "New SSH keys have been generated."
echo ""
# Setup Global Git Config
echo "Setting up global git configuration..."
read -p "Enter your name: " GIT_NAME
read -p "Enter your email: " GIT_EMAIL
git config --global user.email "$GIT_EMAIL"
git config --global user.name "$GIT_NAME"
echo "Global git configuration set."
echo ""
# Secure MariaDB with a basic non-interactive process
echo "Let's secure your MariaDB installation."
read -s -p "Enter new password for MariaDB root user: " MYSQL_ROOT_PASS
echo ""
echo "Securing MariaDB..."
mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '$MYSQL_ROOT_PASS';"
mysql -e "DELETE FROM mysql.user WHERE User='';"
mysql -e "DROP DATABASE IF EXISTS test;"
mysql -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%';"
mysql -e "FLUSH PRIVILEGES;"
# Setup ZSH and oh-my-zsh if desired
read -p "Do you want to install and configure zsh and oh-my-zsh? (y/N): " ZSH
if [[ "$ZSH" =~ ^[Yy] ]]; then
USE_ZSH=true
echo "zsh and oh-my-zsh setup will proceed."
echo "Installing zsh..."
apt-get install -y zsh
echo "zsh installed."
# Install oh-my-zsh non-interactively for the current user
echo "Installing oh-my-zsh..."
export RUNZSH=no
export CHSH=no
sudo -u "$USERNAME" sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# Set zsh as the default shell for the non-root user
echo "Setting zsh as the default shell for $USERNAME..."
chsh -s "$(which zsh)" "$USERNAME"
else
USE_ZSH=false
echo "Skipping zsh and oh-my-zsh setup."
fi
export USE_ZSH
echo "Server setup complete! Next, run the wordpress_setup.sh script to install WordPress."
echo ""