-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathpost_install.sh
executable file
·127 lines (94 loc) · 4.13 KB
/
post_install.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
#!/bin/sh
# Enable the service
sysrc -f /etc/rc.conf gitlab_enable=YES
sysrc -f /etc/rc.conf gitlab_pages_enable="YES"
sysrc -f /etc/rc.conf postgresql_enable="YES"
sysrc -f /etc/rc.conf redis_enable=YES
sysrc -f /etc/rc.conf nginx_enable=YES
sysrc -f /etc/rc.conf sshd_enable=YES
# Start the service
service postgresql initdb
service postgresql start
USER="git"
DB="gitlabhq_production"
# Save the config values
echo "$DB" > /root/dbname
echo "$USER" > /root/dbuser
export LC_ALL=C
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1 > /root/dbpassword
PASS=`cat /root/dbpassword`
# create user git
psql -d template1 -U pgsql -c "CREATE USER ${USER} CREATEDB SUPERUSER;"
# Create the GitLab production database & grant all privileges on database
psql -d template1 -U pgsql -c "CREATE DATABASE ${DB} OWNER ${USER};"
# Set a password on the postgres account
psql -d template1 -U pgsql -c "ALTER USER ${USER} WITH PASSWORD '${PASS}';"
# Connect as superuser to gitlab db and enable pg_trgm extension
psql -U pgsql -d ${DB} -c "CREATE EXTENSION IF NOT EXISTS pg_trgm;"
# Fix permission for postgres
echo "listen_addresses = '*'" >> /usr/local/pgsql/data/postgresql.conf
echo "host all all 0.0.0.0/0 md5" >> /usr/local/pgsql/data/pg_hba.conf
# Restart postgresql after config change
service postgresql restart
# Enable Redis socket
echo 'unixsocket /var/run/redis/redis.sock' >> /usr/local/etc/redis.conf
# Grant permission to the socket to all members of the redis group
echo 'unixsocketperm 770' >> /usr/local/etc/redis.conf
# Add git user to redis group
service redis start
pw groupmod redis -m git
# gitlab *really* wants things in /usr/local
mkdir -p /usr/local/git
# Set git users home to /local/git
pw usermod git -d /usr/local/git
# Make sure the .ssh dir exists
su -l git -c "mkdir -p /usr/local/git/.ssh"
# Make sure repositories directory exists with correct permissions
su -l git -c "mkdir -p /usr/local/git/repositories"
chown git /usr/local/git/repositories
chgrp git /usr/local/git/repositories
chmod 2770 /usr/local/git/repositories
# Set the hostname for gitlab instance
if [ -n "$IOCAGE_PLUGIN_IP" ] ; then
sed -i '' "s|host: localhost|host: ${IOCAGE_PLUGIN_IP}|g" /usr/local/www/gitlab-ce/config/gitlab.yml
fi
# Set db password for gitlab
sed -i '' "s|secure password|${PASS}|g" /usr/local/www/gitlab-ce/config/database.yml
# Set some permissions for git user
chown -R git:git /usr/local/share/gitlab-shell
chown -R git:git /usr/local/www/gitlab-ce
# remove the old Gemfile.lock to avoid problems with new gems
rm Gemfile.lock
# Run database migrations
su -l git -c "cd /usr/local/www/gitlab-ce && echo "yes" | rake gitlab:setup RAILS_ENV=production"
# Compile GetText PO files
su -l git -c "cd /usr/local/www/gitlab-ce && rake gettext:compile RAILS_ENV=production"
#Workaround to fix fetch failers
su -l git -c "cd /usr/local/www/gitlab-ce && rake yarn:install --har RAILS_ENV=production NODE_ENV=production"
# Update node dependencies and recompile assets
su -l git -c "cd /usr/local/www/gitlab-ce && rake yarn:install gitlab:assets:clean gitlab:assets:compile RAILS_ENV=production NODE_ENV=production"
# Clean up cache
su -l git -c "cd /usr/local/www/gitlab-ce && rake cache:clear RAILS_ENV=production"
# Enable push options
su -l git -c "git config --global receive.advertisePushOptions true"
# Configure Git global settings for git user
# 'autocrlf' is needed for the web editor
su -l git -c "git config --global core.autocrlf input"
# Disable 'git gc --auto' because GitLab already runs 'git gc' when needed
su -l git -c "git config --global gc.auto 0"
# Enable packfile bitmaps
su -l git -c "git config --global repack.writeBitmaps true"
# We need also give git permission to gitlab-shell
chown -R git:git /var/log/gitlab-shell/
echo "Starting nginx..."
service nginx start
echo "Starting gitlab..."
service gitlab start
echo "Starting gltlab pages..."
service gitlab_pages start
echo "Starting sshd..."
service sshd start
echo "Database Name: $DB" > /root/PLUGIN_INFO
echo "Database User: $USER" >> /root/PLUGIN_INFO
echo "Database Password: $PASS" >> /root/PLUGIN_INFO
echo "Please open the URL to set your password, Login Name is root." >> /root/PLUGIN_INFO