ponysearch-docker/update.sh

94 lines
2.5 KiB
Bash
Raw Normal View History

#!/bin/sh
2019-08-06 12:40:01 +02:00
#
# Disclaimer: this is more a documentation than code to execute
#
2019-08-06 12:40:01 +02:00
# change if require
2021-10-01 09:42:00 +02:00
SERVICE_NAME="searxng-docker.service"
2019-07-11 17:13:31 +02:00
2019-08-06 12:40:01 +02:00
# change if require :
# fastforward : only fast-forward
# rebase : rebase with autostash, at your own risk
UPDATE_TYPE="fastforward"
READLINK="$(which readlink greadlink | tail -n1)"
BASE_DIR="$(dirname -- "`$READLINK -f -- "$0"`")"
2019-08-06 12:40:01 +02:00
cd -- "$BASE_DIR"
2019-08-06 12:40:01 +02:00
# check if git presence
2019-07-13 13:28:18 +02:00
if [ ! -x "$(which git)" ]; then
echo "git not found" 1>&2
exit 1
fi
2019-08-06 12:40:01 +02:00
# check if the current user owns the local git repository
git_owner=$(stat -c '%U' .git)
if [ "$git_owner" != "$(whoami)" ]; then
echo "The .git repository is own by $git_owner" 1>&2
exit 1
fi
# warning if the current branch is not master
current_branch=$(git rev-parse --abbrev-ref HEAD)
if [ "$current_branch" != "master" ]; then
echo "Warning: master won't be updated, only $current_branch"
fi
# git fetch first
git fetch origin master
# is everything already up-to-date ?
current_commit=$(git rev-parse $current_branch)
origin_master_commit=$(git rev-parse origin/master)
if [ "$current_commit" = "$origin_master_commit" ]; then
echo "Already up-to-date, commit $current_commit"
exit 0
fi
# docker stuff
2021-10-01 09:42:00 +02:00
SEARXNG_DOCKERCOMPOSE=$(grep "Environment=SEARXNG_DOCKERCOMPOSEFILE=" "$SERVICE_NAME" | awk -F\= '{ print $3 }')
2019-08-06 12:40:01 +02:00
. ./util.sh
if [ ! -x "$(which systemctl)" ]; then
echo "systemctl not found" 1>&2
exit 1
fi
# stop the systemd service now, because after the update
# the code might be out of sync with the current running services
2019-07-13 13:28:18 +02:00
systemctl stop "${SERVICE_NAME}"
2019-08-06 12:40:01 +02:00
# update
case "$UPDATE_TYPE" in
"fastforward")
git pull --ff-only origin master
;;
"rebase")
git pull --rebase --autostash origin master
;;
esac
2019-08-06 12:40:01 +02:00
# Check conflicts
2019-07-11 17:13:31 +02:00
if [ $(git ls-files -u | wc -l) -gt 0 ]; then
echo "There are git conflicts"
else
# update docker images
2019-08-06 12:40:01 +02:00
docker-compose -f $DOCKERCOMPOSEFILE pull
# remove dangling images
docker rmi $(docker images -f "dangling=true" -q)
2021-10-01 09:42:00 +02:00
# display SearxNG version
SEARXNG_IMAGE=$(cat $DOCKERCOMPOSEFILE | grep "searxng/searxng" | awk '{ print $2 }')
SEARXNG_VERSION=$(docker inspect -f '{{index .Config.Labels "org.label-schema.version"}}' $SEARXNG_IMAGE)
echo "SearXNG version: $SEARXNG_VERSION"
docker images --digests "searxng/*:latest"
2021-10-01 09:42:00 +02:00
# update SearxNG configuration
2019-07-11 17:13:31 +02:00
source ./.env
2021-10-01 09:42:00 +02:00
docker-compose -f $DOCKERCOMPOSEFILE run searxng ${SEARXNG_COMMAND} -d
2019-08-06 12:40:01 +02:00
# let the user see
2021-10-01 09:42:00 +02:00
echo "Use\nsystemctl start \"${SERVICE_NAME}\"\nto restart SearXNG"
2019-08-06 12:40:01 +02:00
fi