2 # Copyright (C) 2016 Ian Kelling
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
18 # Automated phabricator setup. Not currently using it,
19 # but it worked last time I tried it.
21 if [[ -s ~
/.bashrc
]];then . ~
/.bashrc
;fi
30 alt_domain
=fastmail.wiki
33 domain
=phab.iankelling.org
34 alt_domain
=iankellingusercontent.org
39 pass
=`cat /p/c/machine_specific/$HOSTNAME/phabricator_admin`
40 webroot
=/usr
/share
/phabricator
/webroot
43 email
=ian@iankelling.org
46 fbin
() { bin
=$1; shift; sudo
/usr
/share
/phabricator
/bin
/$bin "$@"; }
47 fsetd
() { fbin config
set --database "$@"; }
49 # phabricator complained about wanting arcanist first
50 pi arcanist
/unstable mercurial
52 # duplicated in mediawiki setup. todo fix that.
53 s DEBIAN_FRONTEND
=noninteractive pi mysql-server
54 cd # mysql_secure_installation writes some temp files to the current dir,
55 # so we need to make sure it's writable.
56 if echo exit|mysql
-u root
-p"$dbpass"; then
57 echo -e "$dbpass\nn\n\n\n\n" | mysql_secure_installation
59 echo -e "\n\n$dbpass\n$dbpass\n\n\n\n\n" | mysql_secure_installation
62 mysql
-u root
-p$dbpass <<EOF
63 grant all privileges on \`phabricator\\_%\`.* to 'phabricator'@localhost identified by '$pass';
67 s debconf-set-selections
<<EOF
68 phabricator phabricator/pwd_check password $pass
69 phabricator phabricator/phabricator_mysql_pwd password $pass
70 phabricator phabricator/webserver select None
71 phabricator phabricator/phabricator_mysql_user string phabricator
72 phabricator phabricator/mysql_host string localhost
73 # Domain name or subdomain name used by phabricator:
74 phabricator phabricator/domain_name string $domain
79 pi phabricator
/unstable
81 # debian sets http, but we want https
82 s
sed -i --follow-symlinks 's/http:/https:/' /usr
/share
/phabricator
/conf
/local
/local.json
85 acme-tiny-wrapper
$domain
86 acme-tiny-wrapper
$alt_domain
88 for x
in $domain $alt_domain; do
89 web-conf
-r $webroot - $x <<EOF
91 RewriteRule ^/rsrc/(.*) - [L,QSA]
92 RewriteRule ^/favicon.ico - [L,QSA]
93 RewriteRule ^/php5-fcgi - [L]
94 RewriteRule ^(.*)\$ /index.php?__path__=\$1 [B,L,QSA]
95 <Directory "$webroot">
102 # Before I figured out how to setup the admin in the script,
103 # this would limit the site to localhost,
104 # and access it through an ssh tunnel until its secure.
105 #phab-site -p 127.0.0.1:443
107 # settings are stored in conf/local/local.json.
108 # some settings could also be stored in the database with
109 # --database arg. database has higher priority than
112 # if you need to restart phabricator, just ser restart apache2
113 # https://secure.phabricator.com/book/phabricator/article/restarting/
115 # to reset things, you can do.
116 # fbin storage destroy; pu phabricator; phab-sel; pi phabricator/unstable
117 # # but under debian, prolly better to purge, cause db gets created on install
120 # On first run went to the website, registered manually, then
121 # went through the gui setup items to get the configuration below.
127 # expect's exits with 0 by default on timeout of an expect command.
128 # You can modify this, but it was simpler to use an irregular code to detect
131 # The expect lines use shell type globbing. They are not actually
132 # needed, but they make the script likely to fail if the questions
133 # content changes drastically, and make the script self documenting.
135 # adds a short delay after each send for more reliable operation
136 # (reference: comment in any autoexpect generated script)
137 set force_conservative 0
138 spawn "/usr/share/phabricator/bin/accountadmin"
139 # If we've already set our user, detect different prompt and exit
140 # expect basics: when the last alternative matches, there is no need
141 # to specify an action, we just continue.
144 -nocase "enter a username" exit
148 expect -nocase timeout {exit 1} "username"
150 expect -nocase timeout {exit 1} "create*y/n"
152 expect -nocase timeout {exit 1} "name"
154 expect -nocase timeout {exit 1} "email"
156 expect -nocase timeout {exit 1} "password"
158 expect -nocase timeout {exit 1} "bot"
160 expect -nocase timeout {exit 1} "admin"
162 expect -nocase timeout {exit 1} "save"
170 # this tipped me over to using a debian package
171 # https://secure.phabricator.com/T4181
173 fsetd auth.require-approval false
175 # phabricator recommends going from 16 to at least 32
176 sudo
sed -ri 's/(^\s*max_allowed_packet)[[:space:]=].*/\1 = 100M/' /etc
/mysql
/my.cnf
180 key
="$1" value
="$2" section
="$3" file="$4"
181 sudo
sed -ri "/ *\[$section\]/,/^ *\[[^]]+\]/{/^\s*$key[[:space:]=]/d};/ *\[$section\]/a $key = $value" "$file"
184 setd
() { setini
"$@" mysqld
/etc
/mysql
/my.cnf
; }
186 # error instead of data corruption:
187 setd sql_mode STRICT_ALL_TABLES
188 setd ft_stopword_file
/usr
/share
/phabricator
/resources
/sql
/stopwords.txt
189 setd ft_min_word_len
3
190 # mysql full text search for word1 word2 will and them instead of or them:
191 setd ft_boolean_syntax
"' |-><()~*:\"\"&^'"
192 # default is 128M. recommended starting point is 40% of ram.
193 setd innodb_buffer_pool_size
1600M
195 # this files stopwork, and min_word_len
196 mysql
-u root
-p$dbpass <<'EOF'
197 REPAIR TABLE phabricator_search.search_documentfield;
200 fsetd pygments.enabled true
201 fbin config
set security.alternate-file-domain https
://$alt_domain
203 setini opcache.validate_timestamps
'"0"' opcache
/etc
/php
5/apache
2/php.ini
204 setini post_max_size
100M PHP
/etc
/php
5/apache
2/php.ini
206 fsetd metamta.default-address phabricator@
$domain
207 fsetd metamta.domain
$domain
212 # Not sure if this is needed. while developing this script, mysql went down
213 # for a bit and the daemons died.
216 # todo, setup inbound email:
217 # https://secure.phabricator.com/book/phabricator/article/configuring_inbound_email/
220 # https://secure.phabricator.com/book/phabricator/article/diffusion_hosting/
221 # unmatchable password, allows login only via ssh, sudo, etc.
223 # I tried having no home dir, (-d /nonexistent),
224 # but I got an error message on test sshing,
225 sudo useradd
-p '*' -m --system -s /bin
/sh vcs ||
[[ $?
== 9 ]]
227 # you'd think the debian package would set this. todo: check on a fresh
229 fbin config
set phd.user phabricator
230 fbin config
set diffusion.ssh-user vcs
232 option
="ALL=(phabricator) SETENV: NOPASSWD:"
233 www_files
=$
(which git hg|
sed ':a;N;s/\n/, /;ta')
234 vcs_files
=$
(which git git-upload-pack git-receive-pack hg|
sed ':a;N;s/\n/, /;ta')
235 [[ $www_files && $vcs_files ]] ||
exit 1
236 www_files
="$www_files, /usr/lib/git-core/git-http-backend"
237 sudo
dd of
=/etc
/sudoers.d
/phabricator
<<EOF
238 www-data $option $www_files
239 vcs $option $vcs_files
242 # Found this due to red x in the ui after setting up a test repo.
243 # todo: debian package should do this for us. see also:
244 # https://phab.iank.bid/config/edit/environment.append-paths/
245 sudo lnf
/usr
/lib
/git-core
/git-http-backend
/usr
/share
/phabricator
/support
/bin
247 fbin config
set diffusion.allow-http-auth true
249 # couldn't find a really appropriate place for it. It needs parent dir
250 # permissions to be root:root.
251 file=/usr
/share
/phabricator-local-ssh-hook.sh
252 # from /usr/share/phabricator/resources/sshd/phabricator-ssh-hook.sh
253 sudo
dd of
=$file <<'EOF'
255 # For debugging, you can temporarily do:
256 # exec >/tmp/plog 2>&1
257 # This script executes as the vcs user
258 if [ "$1" != vcs ]; then exit 1; fi
259 exec "/usr/share/phabricator/bin/ssh-auth" $@
263 sudo
dd of
=/etc
/ssh
/sshd_config.phabricator
<<EOF
264 AuthorizedKeysCommand $file
265 AuthorizedKeysCommandUser vcs
271 AllowAgentForwarding no
272 AllowTcpForwarding no
275 PasswordAuthentication no
276 AuthorizedKeysFile none
278 PidFile /var/run/sshd-phabricator.pid
281 sudo
dd of
=/etc
/systemd
/system
/phabricator-ssh.service
<<'EOF'
283 Description=OpenBSD Secure Shell server for phabricator repos
284 After=network.target auditd.service
285 ConditionPathExists=!/etc/ssh/sshd_not_to_be_run
288 ExecStart=/usr/sbin/sshd -f /etc/ssh/sshd_config.phabricator
289 ExecReload=/bin/kill -HUP $MAINPID
294 WantedBy=multi-user.target
297 sudo systemctl daemon-reload
299 # got this error upon ssh, figured out a solution.
300 # [2016-06-10 06:40:15] EXCEPTION: (AphrontInvalidCredentialsQueryException) #1045: Access denied for user 'root'@'localhost' (using password: NO) at [<phutil>/src/aphront/storage/connection/mysql/AphrontBaseMySQLDatabaseConnection.php:306]
301 # arcanist(), phabricator(), phutil()
303 s usermod
-a -G vcs www-data
304 s usermod
-a -G vcs iank
305 s usermod
-a -G vcs phabricator
306 s chown root
:vcs
/usr
/share
/phabricator
/conf
/local
/local.json
307 fbin config
set diffusion.ssh-port
$ssh_port
309 fsetd policy.allow-public true
317 # todo, finish next steps here:
318 # notably, backup/restore
319 # https://secure.phabricator.com/book/phabricator/article/configuration_guide/
322 fbin auth recover iank
325 # go to link above, then
326 # https://$domain/auth/config/new/
327 # and add username/pass auth provider.
332 # beginnings of automating those last manual steps:
335 # for setting the auto provider, we can use the api.
336 #arc set-config default https://$domain
338 # but first we have to generate an api key by getting
339 # https://phab.iank.bid/conduit/login/
340 # to do that, we've got to login to the url login.
341 # We've got to post to a url on the login page,
342 # then record 2 cookies: phuser and phsid
343 # It also does a 302 for us to do 2 more pages related to auth/login.
345 # we need to post to the right url (didn't record it, with these params)
347 #allowRegistration:"1"
355 # phabricator/ $ ./bin/repository edit rT --as iank --local-path ...