1
|
#!/bin/bash
|
2
|
clear
|
3
|
echo " ______ _______ ______ __ __ ___ __ _ _______ ";
|
4
|
echo "| _ | | || | | |_| || || | | || | ";
|
5
|
echo "| | || | ___|| _ || || || |_| || ___| ";
|
6
|
echo "| |_||_ | |___ | | | || || || || |___ ";
|
7
|
echo "| __ || ___|| |_| || || || _ || ___| ";
|
8
|
echo "| | | || |___ | || ||_|| || || | | || |___ ";
|
9
|
echo "|___| |_||_______||______| |_| |_||___||_| |__||_______| ";
|
10
|
echo " ___ __ _ _______ _______ _______ ___ ___ _______ ______ ";
|
11
|
echo "| || | | || || || _ || | | | | || _ | ";
|
12
|
echo "| || |_| || _____||_ _|| |_| || | | | | ___|| | || ";
|
13
|
echo "| || || |_____ | | | || | | | | |___ | |_||_ ";
|
14
|
echo "| || _ ||_____ | | | | || |___ | |___ | ___|| __ |";
|
15
|
echo "| || | | | _____| | | | | _ || || || |___ | | | |";
|
16
|
echo "|___||_| |__||_______| |___| |__| |__||_______||_______||_______||___| |_|";
|
17
|
echo " ";
|
18
|
echo " R E D M I N E / m a r i a D B 1 1 i n s t a l l e r ";
|
19
|
echo " f o r D e b i a n 1 2 B o o k w o r m ";
|
20
|
echo " ";
|
21
|
echo " ";
|
22
|
|
23
|
# Function to prompt user input with default values
|
24
|
function prompt_with_default() {
|
25
|
local prompt_text=$1
|
26
|
local default_value=$2
|
27
|
local input
|
28
|
|
29
|
# Custom prompt with 'Default=' format
|
30
|
read -p "$prompt_text`echo $'\nDEFAULT='`[$default_value]> " input
|
31
|
# Use default value if no input is provided
|
32
|
echo ${input:-$default_value}
|
33
|
}
|
34
|
|
35
|
# Function to ask for and confirm variables
|
36
|
function get_user_inputs() {
|
37
|
# Interactive prompts with default values
|
38
|
DB_NAME=$(prompt_with_default "# 1. You can choose a database name." "redmine")
|
39
|
DB_USER=$(prompt_with_default "# 2. Now you can choose a database user." "redmine")
|
40
|
DB_PASSWORD=$(prompt_with_default "# 3. Please choose a database password." "DBPassword123")
|
41
|
ADMIN_PASSWORD=$(prompt_with_default "# 4. Please choose a Redmine initial admin password." "Password123")
|
42
|
REDMINE_VERSION=$(prompt_with_default "# 5. Please enter the Redmine version to install." "5.1.2")
|
43
|
REDMINE_DIR=$(prompt_with_default "# 6. Please choose a Redmine installation directory." "/var/www/redmine")
|
44
|
REDMINE_URL=$(prompt_with_default "# 7. Here you can modify the Source for the installation." "https://www.redmine.org/releases/redmine-$REDMINE_VERSION.tar.gz")
|
45
|
LOG_FILE=$(prompt_with_default "# 8. Please choose a path for the Logfile." "/var/log/redmine_installation.log")
|
46
|
}
|
47
|
|
48
|
# Function to confirm inputs
|
49
|
function confirm_inputs() {
|
50
|
echo "--------------------------------------------"
|
51
|
echo "Please review the following settings:"
|
52
|
echo "Database name: $DB_NAME"
|
53
|
echo "Database user: $DB_USER"
|
54
|
echo "Database password: $DB_PASSWORD"
|
55
|
echo "Admin password: $ADMIN_PASSWORD"
|
56
|
echo "Redmine version: $REDMINE_VERSION"
|
57
|
echo "Redmine directory: $REDMINE_DIR"
|
58
|
echo "Redmine URL: $REDMINE_URL"
|
59
|
echo "--------------------------------------------"
|
60
|
|
61
|
read -p "Are these settings correct? Then we continue with the setup of Apache, MySQL/mariaDB, phpmyadmin and Redmine. (y/n): " confirm
|
62
|
if [[ "$confirm" != "y" ]]; then
|
63
|
echo "Please enter the data again..."
|
64
|
return 1
|
65
|
fi
|
66
|
return 0
|
67
|
}
|
68
|
|
69
|
# Main loop to confirm or re-enter inputs
|
70
|
while true; do
|
71
|
get_user_inputs
|
72
|
confirm_inputs && break
|
73
|
done
|
74
|
|
75
|
# Remaining script...
|
76
|
log "Updating system..."
|
77
|
apt update && apt upgrade -y && apt install sudo -y
|
78
|
|
79
|
# Logging function
|
80
|
log() {
|
81
|
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a $LOG_FILE
|
82
|
}
|
83
|
|
84
|
# Update system
|
85
|
log "Updating system..."
|
86
|
apt update 2>&1 | tee -a $LOG_FILE
|
87
|
apt upgrade -y 2>&1 | tee -a $LOG_FILE
|
88
|
apt install sudo -y 2>&1 | tee -a $LOG_FILE
|
89
|
|
90
|
# Install dependencies
|
91
|
log "Installing necessary packages..."
|
92
|
apt install -y apache2 libapache2-mod-passenger mariadb-server mariadb-client \
|
93
|
libmariadb-dev build-essential libssl-dev libyaml-dev libxml2-dev \
|
94
|
libxslt1-dev libffi-dev zlib1g-dev libmagickwand-dev curl vim git wget php libapache2-mod-php php-mysql 2>&1 | tee -a $LOG_FILE
|
95
|
|
96
|
# Add MariaDB repository
|
97
|
log "Adding the MariaDB repository..."
|
98
|
apt-get install -y apt-transport-https curl 2>&1 | tee -a $LOG_FILE
|
99
|
mkdir -p /etc/apt/keyrings
|
100
|
curl -o /etc/apt/keyrings/mariadb-keyring.pgp 'https://mariadb.org/mariadb_release_signing_key.pgp' 2>&1 | tee -a $LOG_FILE
|
101
|
echo "deb [signed-by=/etc/apt/keyrings/mariadb-keyring.pgp] https://ftp.agdsn.de/pub/mirrors/mariadb/repo/11.4/debian bookworm main" | tee /etc/apt/sources.list.d/mariadb.list
|
102
|
apt-get update 2>&1 | tee -a $LOG_FILE
|
103
|
|
104
|
# Update MariaDB to version 11.4
|
105
|
log "Updating MariaDB to version 11.4..."
|
106
|
apt-get install -y mariadb-server 2>&1 | tee -a $LOG_FILE
|
107
|
|
108
|
# Start and secure MariaDB
|
109
|
log "Configuring MariaDB..."
|
110
|
systemctl start mariadb 2>&1 | tee -a $LOG_FILE
|
111
|
systemctl enable mariadb 2>&1 | tee -a $LOG_FILE
|
112
|
mysql_secure_installation <<EOF 2>&1 | tee -a $LOG_FILE
|
113
|
|
114
|
y
|
115
|
$DB_PASSWORD
|
116
|
$DB_PASSWORD
|
117
|
y
|
118
|
y
|
119
|
y
|
120
|
y
|
121
|
EOF
|
122
|
|
123
|
# Create database and user for Redmine
|
124
|
log "Creating database and user for Redmine..."
|
125
|
mysql -u root -p$DB_PASSWORD <<MYSQL_SCRIPT 2>&1 | tee -a $LOG_FILE
|
126
|
CREATE DATABASE $DB_NAME CHARACTER SET utf8mb4;
|
127
|
CREATE USER '$DB_USER'@'localhost' IDENTIFIED BY '$DB_PASSWORD';
|
128
|
GRANT ALL PRIVILEGES ON $DB_NAME.* TO '$DB_USER'@'localhost';
|
129
|
FLUSH PRIVILEGES;
|
130
|
EXIT;
|
131
|
MYSQL_SCRIPT
|
132
|
|
133
|
# Install phpMyAdmin
|
134
|
log "Installing phpMyAdmin..."
|
135
|
# Silently install phpMyAdmin
|
136
|
log "Silently installing phpMyAdmin with apache2 and dbconfig-common..."
|
137
|
|
138
|
# Set preconfiguration for phpMyAdmin
|
139
|
echo "phpmyadmin phpmyadmin/reconfigure-webserver multiselect apache2" | debconf-set-selections
|
140
|
echo "phpmyadmin phpmyadmin/dbconfig-install boolean true" | debconf-set-selections
|
141
|
echo "phpmyadmin phpmyadmin/app-password-confirm password $DB_PASSWORD" | debconf-set-selections
|
142
|
echo "phpmyadmin phpmyadmin/mysql/admin-pass password $DB_PASSWORD" | debconf-set-selections
|
143
|
echo "phpmyadmin phpmyadmin/mysql/app-pass password $DB_PASSWORD" | debconf-set-selections
|
144
|
echo "phpmyadmin phpmyadmin/password-confirm password $DB_PASSWORD" | debconf-set-selections
|
145
|
|
146
|
# Silently install phpMyAdmin
|
147
|
DEBIAN_FRONTEND=noninteractive apt install -y phpmyadmin 2>&1 | tee -a $LOG_FILE
|
148
|
|
149
|
# phpMyAdmin configuration
|
150
|
log "Configuring VirtualHost for phpMyAdmin..."
|
151
|
cat <<EOL > /etc/apache2/sites-available/phpmyadmin.conf
|
152
|
<VirtualHost *:12300>
|
153
|
|
154
|
ServerName localhost
|
155
|
|
156
|
<Directory /usr/share/phpmyadmin>
|
157
|
AllowOverride None
|
158
|
Require all granted
|
159
|
</Directory>
|
160
|
|
161
|
DocumentRoot /usr/share/phpmyadmin
|
162
|
|
163
|
Include /etc/phpmyadmin/apache.conf
|
164
|
|
165
|
ErrorLog ${APACHE_LOG_DIR}/phpmyadmin.error.log
|
166
|
CustomLog ${APACHE_LOG_DIR}/phpmyadmin.access.log combined
|
167
|
|
168
|
</VirtualHost>
|
169
|
EOL
|
170
|
|
171
|
# Enable port 12300
|
172
|
log "Enabling port 12300 for Apache..."
|
173
|
echo "Listen 12300" | tee -a /etc/apache2/ports.conf
|
174
|
|
175
|
a2disconf phpmyadmin 2>&1 | tee -a $LOG_FILE
|
176
|
a2ensite phpmyadmin 2>&1 | tee -a $LOG_FILE
|
177
|
systemctl reload apache2 2>&1 | tee -a $LOG_FILE
|
178
|
|
179
|
# Install Ruby
|
180
|
log "Installing Ruby and Bundler..."
|
181
|
apt install -y ruby-full 2>&1 | tee -a $LOG_FILE
|
182
|
gem install bundler 2>&1 | tee -a $LOG_FILE
|
183
|
|
184
|
# Download and configure Redmine
|
185
|
log "Downloading Redmine $REDMINE_VERSION..."
|
186
|
cd /var/www
|
187
|
wget $REDMINE_URL 2>&1 | tee -a $LOG_FILE
|
188
|
tar -xvzf redmine-$REDMINE_VERSION.tar.gz 2>&1 | tee -a $LOG_FILE
|
189
|
mv redmine-$REDMINE_VERSION redmine
|
190
|
chown -R www-data:www-data $REDMINE_DIR
|
191
|
chmod -R 755 $REDMINE_DIR
|
192
|
|
193
|
# Add Blankslate gem
|
194
|
log "Adding the Blankslate gem to the Gemfile..."
|
195
|
echo "gem 'blankslate', '~> 3.1.3'" | tee -a $REDMINE_DIR/Gemfile
|
196
|
|
197
|
# Configure Redmine database
|
198
|
log "Configuring Redmine database connection..."
|
199
|
cp $REDMINE_DIR/config/database.yml.example $REDMINE_DIR/config/database.yml
|
200
|
# First, remove the existing 'production' block
|
201
|
sed -i '/production:/,/^$/d' $REDMINE_DIR/config/database.yml
|
202
|
|
203
|
# Add new 'production' block
|
204
|
cat <<EOL >> $REDMINE_DIR/config/database.yml
|
205
|
production:
|
206
|
adapter: mysql2
|
207
|
database: $DB_NAME
|
208
|
host: localhost
|
209
|
username: $DB_USER
|
210
|
password: "$DB_PASSWORD"
|
211
|
encoding: utf8mb4
|
212
|
variables:
|
213
|
transaction_isolation: "READ-COMMITTED"
|
214
|
EOL
|
215
|
|
216
|
# Install Redmine gems
|
217
|
log "Installing necessary gems..."
|
218
|
cd $REDMINE_DIR
|
219
|
bundle install --without development test 2>&1 | tee -a $LOG_FILE
|
220
|
|
221
|
# Migrate Redmine database
|
222
|
log "Initializing Redmine database..."
|
223
|
bundle exec rake generate_secret_token 2>&1 | tee -a $LOG_FILE
|
224
|
RAILS_ENV=production bundle exec rake db:migrate 2>&1 | tee -a $LOG_FILE
|
225
|
RAILS_ENV=production bundle exec rake redmine:load_default_data <<EOF 2>&1 | tee -a $LOG_FILE
|
226
|
en
|
227
|
EOF
|
228
|
|
229
|
# Create directories and set permissions
|
230
|
log "Setting directory permissions..."
|
231
|
mkdir -p tmp tmp/pdf public/plugin_assets
|
232
|
chown -R www-data:www-data files log tmp public/plugin_assets
|
233
|
chmod -R 755 files log tmp public/plugin_assets
|
234
|
|
235
|
# Apache configuration for Redmine
|
236
|
log "Configuring Apache for Redmine..."
|
237
|
bash -c "cat > /etc/apache2/sites-available/redmine.conf" <<EOF
|
238
|
<VirtualHost *:80>
|
239
|
ServerAdmin admin@yourdomain.com
|
240
|
DocumentRoot $REDMINE_DIR/public
|
241
|
ServerName localhost
|
242
|
<Directory $REDMINE_DIR/public>
|
243
|
Require all granted
|
244
|
Options -MultiViews
|
245
|
</Directory>
|
246
|
ErrorLog \${APACHE_LOG_DIR}/redmine_error.log
|
247
|
CustomLog \${APACHE_LOG_DIR}/redmine_access.log combined
|
248
|
</VirtualHost>
|
249
|
EOF
|
250
|
|
251
|
a2dissite 000-default.conf 2>&1 | tee -a $LOG_FILE
|
252
|
a2ensite redmine.conf 2>&1 | tee -a $LOG_FILE
|
253
|
|
254
|
systemctl reload apache2 2>&1 | tee -a $LOG_FILE
|
255
|
|
256
|
# Change Redmine admin user password
|
257
|
log "Changing the admin password..."
|
258
|
RAILS_ENV=production bundle exec rails runner "user = User.find_by_login('admin'); user.password = '$ADMIN_PASSWORD'; user.password_confirmation = '$ADMIN_PASSWORD'; user.save!" 2>&1 | tee -a $LOG_FILE
|
259
|
|
260
|
log "Installation completed!"
|
261
|
log "Access Redmine at http://<your_server_ip>."
|
262
|
log "Username: admin"
|
263
|
log "Password: $ADMIN_PASSWORD"
|
264
|
echo " "
|
265
|
log "Access phpmyadmin at http://<your_server_ip>:12300."
|
266
|
log "Username: $DB_USER"
|
267
|
log "Password: $DB_PASSWORD"
|
268
|
echo " "
|
269
|
log "Installation made by allmycookies(c)2024"
|