Simplify keyserver install

This commit is contained in:
Bob Mottram 2017-07-28 21:06:46 +01:00
parent ad4b4c61fd
commit 79b5bd818e
1 changed files with 11 additions and 128 deletions

View File

@ -33,8 +33,6 @@ VARIANTS='full full-vim'
IN_DEFAULT_INSTALL=0
SHOW_ON_ABOUT=1
KEYSERVER_SKS_REPO="https://bitbucket.org/skskeyserver/sks-keyserver"
KEYSERVER_SKS_COMMIT='0106ba2'
KEYSERVER_WEB_REPO="https://github.com/mattrude/pgpkeyserver-lite"
KEYSERVER_WEB_COMMIT='a038cb79b927c99bf7da62f20d2c6a2f20374339'
KEYSERVER_PORT=11371
@ -61,33 +59,7 @@ function reconfigure_keyserver {
echo -n ''
}
function upgrade_keyserver_sks {
CURR_KEYSERVER_SKS_COMMIT=$(get_completion_param "keyserver commit")
if [[ "$CURR_KEYSERVER_SKS_COMMIT" == "$KEYSERVER_SKS_COMMIT" ]]; then
return
fi
if grep -q "keyserver domain" $COMPLETION_FILE; then
KEYSERVER_DOMAIN_NAME=$(get_completion_param "keyserver domain")
fi
# update to the next commit
function_check set_repo_commit
set_repo_commit $INSTALL_DIR/keyserver "keyserver commit" "$KEYSERVER_SKS_COMMIT" $KEYSERVER_SKS_REPO
cd $INSTALL_DIR/keyserver
make dep
make all
if [ ! "$?" = "0" ]; then
echo $'Unable to build sks-keyserver'
exit 836252
fi
make install
chown -R keyserver:keyserver /var/lib/sks
}
function upgrade_keyserver_web {
function upgrade_keyserver {
CURR_KEYSERVER_WEB_COMMIT=$(get_completion_param "keyserver web commit")
if [[ "$CURR_KEYSERVER_WEB_COMMIT" == "$KEYSERVER_WEB_COMMIT" ]]; then
return
@ -104,11 +76,6 @@ function upgrade_keyserver_web {
chown -R www-data:www-data /var/www/$KEYSERVER_DOMAIN_NAME/htdocs
}
function upgrade_keyserver {
upgrade_keyserver_sks
upgrade_keyserver_web
}
function backup_local_keyserver {
echo -n ''
}
@ -126,10 +93,8 @@ function restore_remote_keyserver {
}
function remove_keyserver {
systemctl stop keyserver
systemctl disable keyserver
rm /etc/systemd/system/keyserver.service
systemctl daemon-reload
systemctl stop sks
apt-get -qy remove sks
read_config_param "KEYSERVER_DOMAIN_NAME"
nginx_dissite $KEYSERVER_DOMAIN_NAME
@ -150,20 +115,9 @@ function remove_keyserver {
remove_completion_param "install_keyserver"
sed -i '/keyserver/d' $COMPLETION_FILE
if [ -f /usr/bin/keyserver-start ]; then
rm /usr/bin/keyserver-start
fi
if [ -f /usr/bin/keyserver-stop ]; then
rm /usr/bin/keyserver-stop
fi
cd $INSTALL_DIR/keyserver
make uninstall
if [ -d /var/lib/sks ]; then
rm -rf /var/lib/sks
fi
rm -rf $INSTALL_DIR/keyserver
groupdel -f keyserver
userdel -r keyserver
}
function install_interactive_keyserver {
@ -201,7 +155,7 @@ function keyserver_import_keys {
cd /var/lib/sks
echo $'Building the keyserver database from the downloaded dump'
echo '2' | /usr/local/bin/sks_build.sh
sks build
}
function configure_interactive_keyserver {
@ -227,33 +181,16 @@ function configure_interactive_keyserver {
}
function install_keyserver {
apt-get -qy install build-essential gcc ocaml libdb-dev wget
apt-get -qy install build-essential gcc ocaml libdb-dev wget sks
sks build
chown -Rc debian-sks: /var/lib/sks/DB
sed -i 's|initstart=.*|initstart=yes|g' /etc/default/sks
systemctl restart sks
if [ ! -d /var/www/$KEYSERVER_DOMAIN_NAME ]; then
mkdir /var/www/$KEYSERVER_DOMAIN_NAME
fi
if [ ! -d $INSTALL_DIR ]; then
mkdir -p $INSTALL_DIR
fi
cd $INSTALL_DIR
if [ -d /repos/keyserver ]; then
mkdir $INSTALL_DIR/keyserver
cp -r -p /repos/keyserver/. $INSTALL_DIR/keyserver
cd $INSTALL_DIR/keyserver
git pull
else
git_clone $KEYSERVER_SKS_REPO keyserver
fi
if [ ! -d $INSTALL_DIR/keyserver ]; then
echo $"$INSTALL_DIR/keyserver not found"
exit 835274
fi
cd $INSTALL_DIR/keyserver
git checkout $KEYSERVER_SKS_COMMIT -b $KEYSERVER_SKS_COMMIT
set_completion_param "keyserver commit" "$KEYSERVER_SKS_COMMIT"
cd /var/www/$KEYSERVER_DOMAIN_NAME
if [ -d /var/www/$KEYSERVER_DOMAIN_NAME/htdocs ]; then
rm -rf /var/www/$KEYSERVER_DOMAIN_NAME/htdocs
@ -276,26 +213,6 @@ function install_keyserver {
git checkout $KEYSERVER_WEB_COMMIT -b $KEYSERVER_WEB_COMMIT
set_completion_param "keyserver web commit" "$KEYSERVER_WEB_COMMIT"
cd $INSTALL_DIR/keyserver
if [ ! -f Makefile.local.unused ]; then
echo $'Unused makefile not found'
exit 72398
fi
cp Makefile.local.unused Makefile.local
sed -i 's|LIBDB=.*|LIBDB=-ldb-5.3.1|g' Makefile.local
make dep
make all
if [ ! "$?" = "0" ]; then
echo $'Unable to build sks-keyserver'
exit 8356328
fi
make install
if [ ! -f /usr/local/bin/sks_build.sh ]; then
echo $'/usr/local/bin/sks_build.sh not found'
exit 238460
fi
USER_EMAIL_ADDRESS=$MY_USERNAME@$HOSTNAME
GPG_ID=$(su -m root -c "gpg --list-keys $USER_EMAIL_ADDRESS | sed -n '2p' | sed 's/^[ \t]*//'" - $MY_USERNAME)
@ -329,39 +246,10 @@ function install_keyserver {
echo 'stat_hour: 12' >> $sksconf_file
echo '' >> $sksconf_file
echo 'max_matches: 500' >> $sksconf_file
chown debian-sks: $sksconf_file
KEYSERVER_ONION_HOSTNAME=$(add_onion_service keyserver 80 ${KEYSERVER_ONION_PORT})
echo '#!/bin/sh' > /usr/bin/keyserver-start
echo 'cd /var/lib/sks' >> /usr/bin/keyserver-start
echo 'echo -n \ sks_db' >> /usr/bin/keyserver-start
echo '$DAEMON db &' >> /usr/bin/keyserver-start
echo 'echo -n \ sks_recon' >> /usr/bin/keyserver-start
echo '$DAEMON recon &' >> /usr/bin/keyserver-start
chmod +x /usr/bin/keyserver-start
echo '#!/bin/sh' > /usr/bin/keyserver-stop
echo 'killall sks' >> /usr/bin/keyserver-stop
echo 'sleep 5' >> /usr/bin/keyserver-stop
chmod +x /usr/bin/keyserver-stop
echo '[Unit]' > /etc/systemd/system/keyserver.service
echo 'Description=SKS Keyserver' >> /etc/systemd/system/keyserver.service
echo 'After=syslog.target network.target nginx.target' >> /etc/systemd/system/keyserver.service
echo '' >> /etc/systemd/system/keyserver.service
echo '[Service]' >> /etc/systemd/system/keyserver.service
echo 'User=keyserver' >> /etc/systemd/system/keyserver.service
echo 'Group=keyserver' >> /etc/systemd/system/keyserver.service
echo "WorkingDirectory=/var/lib/sks" >> /etc/systemd/system/keyserver.service
echo "ExecStart=/usr/bin/keyserver-start" >> /etc/systemd/system/keyserver.service
echo "ExecStop=/usr/bin/keyserver-stop" >> /etc/systemd/system/keyserver.service
echo 'Restart=always' >> /etc/systemd/system/keyserver.service
echo 'RestartSec=10' >> /etc/systemd/system/keyserver.service
echo '' >> /etc/systemd/system/keyserver.service
echo '[Install]' >> /etc/systemd/system/keyserver.service
echo 'WantedBy=multi-user.target' >> /etc/systemd/system/keyserver.service
chmod +x /etc/systemd/system/keyserver.service
keyserver_nginx_site=/etc/nginx/sites-available/$KEYSERVER_DOMAIN_NAME
if [[ $ONION_ONLY == "no" ]]; then
function_check nginx_http_redirect
@ -455,20 +343,15 @@ function install_keyserver {
chown root:root /etc/ssl/private/${KEYSERVER_DOMAIN_NAME}.key
fi
groupadd keyserver
useradd -c "SKS Keyserver system account" -d /var/lib/sks -m -r -g keyserver keyserver
chown -R keyserver:keyserver /var/lib/sks
chown -R www-data:www-data /var/www/$KEYSERVER_DOMAIN_NAME/htdocs
function_check nginx_ensite
nginx_ensite $KEYSERVER_DOMAIN_NAME
systemctl enable keyserver
systemctl daemon-reload
systemctl start keyserver
systemctl restart nginx
set_completion_param "keyserver domain" "$KEYSERVER_DOMAIN_NAME"
set_completion_param "keyserver onion domain" "$KEYSERVER_ONION_HOSTNAME"
APP_INSTALLED=1
}