diff options
author | s7hoang | 2021-01-27 17:14:18 -0500 |
---|---|---|
committer | s7hoang | 2021-01-27 17:14:18 -0500 |
commit | 501605e151092f933149f424a47594e28c14b2ed (patch) | |
tree | ee1472adb1a4490a24595c04774637c22d358d12 | |
parent | 576c7a067a70c60026d6948fdf389ddcebdaa712 (diff) | |
download | aur-501605e151092f933149f424a47594e28c14b2ed.tar.gz |
Update To Work With Upstream
Squashed commit of the following:
commit 229ace46bf9142dd631ed625aa09c3bc64a8f166
Author: s7hoang <s7hoang@gmail.com>
Date: Wed Jan 27 16:57:48 2021 -0500
Remove Subdirectories
Apparently subdirs aren't allowed.
commit 1c7f588d87eaf26becdeed270c7fb1360bc1dfbb
Author: s7hoang <s7hoang@gmail.com>
Date: Wed Jan 27 16:10:59 2021 -0500
Guard The Awk File From Executing If Config Already Present
commit 65e34d408516399f76dec9b238c2020a80defcc2
Author: s7hoang <s7hoang@gmail.com>
Date: Wed Jan 27 16:19:30 2021 -0500
Add No-Script-Warn-Location For Python Deps
commit f5c460c8f3685752e82ac2b0458ca1451d546936
Author: s7hoang <s7hoang@gmail.com>
Date: Wed Jan 27 14:52:34 2021 -0500
Move Common Code To Function
I remember it was considered good practice to avoid custom functions
in the PKGBUILD at least, but it doesn't seem to be problematic for
the .install files.
if the requisite changes are already present then just exit
commit 1c3532b0290c964b8aa87f3bd33ace18b6cffe03
Author: s7hoang <s7hoang@gmail.com>
Date: Wed Jan 27 14:47:38 2021 -0500
Start Nginx On Post-Upgrade
Another thing missing when upgrading from old version to new
commit d06d3827cac4c7bdff11492ccef7a0c4f14a4dbd
Author: s7hoang <s7hoang@gmail.com>
Date: Wed Jan 27 14:45:52 2021 -0500
Add Install Python Dependencies On Post-Upgrade
Upgrading from the old version of this package is having issues since
it's different from the current version
commit e06eff04cd8da313bc262a560cea6d21d519fcb5
Author: s7hoang <s7hoang@gmail.com>
Date: Wed Jan 27 14:38:22 2021 -0500
Clarify Enabled Autostart For Nginx
commit 394b8f46e47eec8af9ad4a27c0aacc73218ed48f
Author: s7hoang <s7hoang@gmail.com>
Date: Wed Jan 27 14:36:53 2021 -0500
Fix Typo
commit 1f870f0e7c3a2ccfdccdff885a793af395bbe9a9
Author: s7hoang <s7hoang@gmail.com>
Date: Wed Jan 27 14:18:28 2021 -0500
Add Post Install Line For Checking Nginx Status
commit dcc08032b88e4c5e3220d96add68d9a069db7256
Author: s7hoang <s7hoang@gmail.com>
Date: Wed Jan 27 14:16:00 2021 -0500
Rename Variables For Conformity
commit c0e1106782450bdbee27f6cddd9176e6feadb6a8
Author: s7hoang <s7hoang@gmail.com>
Date: Wed Jan 27 14:15:50 2021 -0500
Update Post Install
commit a7dd10ddad92a510eae7d33fb6e98733e2e00aa5
Author: s7hoang <s7hoang@gmail.com>
Date: Wed Jan 27 14:14:55 2021 -0500
Update Post Install Plugin Paths
commit 6eda8b946a24aea3e2c5aefaab51942208e214d5
Author: s7hoang <s7hoang@gmail.com>
Date: Wed Jan 27 14:14:27 2021 -0500
Add Message About Nginx Config Append
commit 1faf4e47bb4ab1f7436dbae1218cc80a319886d8
Author: s7hoang <s7hoang@gmail.com>
Date: Wed Jan 27 13:58:09 2021 -0500
Set Variable To Local
commit 12a6d8b11e65e422730e7ea7f35c21da2ac2234d
Author: s7hoang <s7hoang@gmail.com>
Date: Wed Jan 27 13:53:22 2021 -0500
Attempt To Fix Call The Awk Script
Forgot to actually specify a file.
Remembered that you can't use a file as both input and output so we
have to backup the original file first.
It's a good idea to backup anyways.
Need to write a user reminder to check the nginx file.
commit 80dfe2c3214850019897b68cb2c8b708514b86c8
Author: s7hoang <s7hoang@gmail.com>
Date: Wed Jan 27 13:42:29 2021 -0500
Add Awk Script To Append Nginx Server Config
It's not append *exactly* since it has to preceed the closing '}' in
the right 'http' section.
commit c885f8dc3407b912b556b124e20fbc2d40ee95d2
Author: s7hoang <s7hoang@gmail.com>
Date: Wed Jan 27 13:11:18 2021 -0500
Move Nginx Config Append To Post Install
root permissions needed; post install has it.
commit cc8a73784e54286fbf262998ad7b6435267e70f8
Author: s7hoang <s7hoang@gmail.com>
Date: Wed Jan 27 13:09:11 2021 -0500
Add Nginx To Start
Maybe should add a message about it since that might be a security
thing.
commit ca22523ab18dd9151a371f7654ea86f405c1a9d0
Author: s7hoang <s7hoang@gmail.com>
Date: Wed Jan 27 13:08:35 2021 -0500
Move Dependency Install Above Execution Of Service
This is probably why things were dying -.-
commit b98838c729e548a64a6fd551b587dfa436ad6afd
Author: s7hoang <s7hoang@gmail.com>
Date: Wed Jan 27 13:06:44 2021 -0500
Remove Obsolete Install Script
Bundle Removed
commit c57921430b1c111cc4d8c26fb1e5dee58a8cb062
Author: s7hoang <s7hoang@gmail.com>
Date: Wed Jan 27 13:06:06 2021 -0500
Add Step For Nginx Config To Be Appended /etcs/
commit e21f60786d990719ef3aeed38cc4b7a25683e37c
Author: s7hoang <s7hoang@gmail.com>
Date: Wed Jan 27 13:59:55 2021 -0500
Remove Post Install Bundled Anki Instructions
bundled anki removed
commit dc3c90195901e8ca1fdbcf57ce9485c75d3fd3d5
Author: s7hoang <s7hoang@gmail.com>
Date: Wed Jan 27 12:58:07 2021 -0500
Remove Options Dependencies Of Bundled Anki
bundle is no longer present.
commit 2a8e297c0d0ba3b46f69b4babf6f8db6da64ccfd
Author: s7hoang <s7hoang@gmail.com>
Date: Wed Jan 27 12:52:16 2021 -0500
Change Server's Port To Run At 27702
nginx will be running at 27701 as per the instructions upstream.
commit f4017656f37d76ffc6cefef13e79e8fc9f8d889b
Author: s7hoang <s7hoang@gmail.com>
Date: Wed Jan 27 12:48:19 2021 -0500
Use The Requirements.Txt Package Instead Of Manually Specifying
Probably should've done this sooner.
commit ec5e5eb69f8d1634db489e6aa5be1e31a5784672
Author: s7hoang <s7hoang@gmail.com>
Date: Wed Jan 27 12:37:40 2021 -0500
Set recursive on cp
commit 6a017a7be2d42850e29f3ac735c7c5c4e68627d7
Author: s7hoang <s7hoang@gmail.com>
Date: Wed Jan 27 12:36:28 2021 -0500
Remove Build Step
No longer needed since the bundled-anki package was removed.
commit 80cf2af74130ddfaed769c7a7e91008a7d585b64
Author: s7hoang <s7hoang@gmail.com>
Date: Wed Jan 27 02:14:43 2021 -0500
Rejig PKGBUILD To Work With Upstream
For clarity purposes, individual plugin files were moved to
directories before hand; helps to reduce clutter.
Optional dependencies have not yet been removed as I would like to
verify that none of that is needed anymore with test installs.
Still need to rejig the post install stuff prior to test installs.
nginx is now a dependency for "request unpacking".
-rw-r--r-- | PKGBUILD | 59 | ||||
-rw-r--r-- | anki-sync-server.install | 120 | ||||
-rw-r--r-- | anki-sync-server.py | 3 | ||||
-rw-r--r-- | anki2.0.py | 3 | ||||
-rw-r--r-- | anki2.1.28.py | 5 | ||||
-rw-r--r-- | anki2.1.py (renamed from __init__.py) | 2 | ||||
-rw-r--r-- | install_anki_bundled.sh | 15 | ||||
-rwxr-xr-x | nginx_append_config.awk | 19 | ||||
-rw-r--r-- | nginx_config | 9 |
9 files changed, 135 insertions, 100 deletions
@@ -1,6 +1,6 @@ # Maintainer: s7hoang <s7hoang at gmail dot com> pkgname=anki-sync-server-git -pkgver=r295.0c6a86d +pkgver=r379.44ab07f pkgrel=1 pkgdesc="A sync server for anki using a forked version from github.com/ankicommunity (orig:dsnopek)" arch=('any') @@ -8,19 +8,9 @@ url="https://github.com/ankicommunity/anki-sync-server" license=('GPL') provides=('anki-sync-server') conflicts=('anki-sync-server') -depends=('python' 'python-pip') +depends=('python' 'python-pip' 'nginx') makedepends=('portaudio' 'git') -optdepends=('python-pyqt5: dependency of bundled anki client' -'python-pyqtwebengine: dependency of bundled anki client' -'python-beautifulsoup4: dependency of bundled anki client' -'python-send2trash: dependency of bundled anki client' -'python-pyaudio: dependency of bundled anki client' -'python-requests: dependency of bundled anki client' -'python-decorator: dependency of bundled anki client' -'python-markdown: dependency of bundled anki client' -'python-psutil: dependency of bundled anki client' -'mplayer: optional dependency of bundled anki client' -'python-webob: if you want to run the server as a user other than the supplied anki-sync-server user' +optdepends=( 'python-webob: if you want to run the server as a user other than the supplied anki-sync-server user' 'python-decorator: if you want to run the server as a user other than the supplied anki-sync-server user' ) install=anki-sync-server.install @@ -36,31 +26,34 @@ pkgver() { printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)" } -build(){ - #initialize anki-bundled (needed for the server to work) - cd "${_anki_dir}/anki-bundled" && git submodule update --init -} - prepare() { # move plugins and systemd file to src package - mkdir -p "${_anki_dir}/plugins/anki2.0" - mkdir -p "${_anki_dir}/plugins/anki2.1/ankisyncd" - mkdir -p "${_anki_dir}/plugins/systemd" - cp ../anki-sync-server.py "${_anki_dir}/plugins/anki2.0" - cp ../__init__.py "${_anki_dir}/plugins/anki2.1/ankisyncd" - cp ../anki-sync-server.service "${_anki_dir}/plugins/systemd" + local _plugins_="${_anki_dir}/plugins/" + mkdir -p "${_plugins_}" + mkdir -p "${_plugins_}/anki2.0/" + mkdir -p "${_plugins_}/anki2.1/anki-sync-server" + mkdir -p "${_plugins_}/anki2.1.28/anki-sync-server" + mkdir -p "${_plugins_}/nginx/" + mkdir -p "${_plugins_}/systemd/" + cp "../anki2.0.py" "${_plugins_}/anki2.0/anki-sync-server.py" + cp "../anki2.1.py" "${_plugins_}/anki2.1/anki-sync-server/__init__.py" + cp "../anki2.1.28.py" "${_plugins_}/anki2.1.28//anki-sync-server/__init__.py" + cp "../anki-sync-server.service" "${_plugins_}/systemd/" + cp "../nginx_config" "${_plugins_}/nginx/config" + cp "../nginx_append_config.awk" "${_plugins_}/nginx/append.awk" - cd "${_anki_dir}" # set plugins to use current ip address as plugins' target address - sed -i "2s/0\.0\.0\.0/$(ip route get 1.2.3.4 | awk '{print $7}')/" \ - plugins/anki2.0/anki-sync-server.py - sed -i "3s/0\.0\.0\.0/$(ip route get 1.2.3.4 | awk '{print $7}')/" \ - plugins/anki2.0/anki-sync-server.py - sed -i "3s/0\.0\.0\.0/$(ip route get 1.2.3.4 | awk '{print $7}')/" \ - plugins/anki2.1/ankisyncd/__init__.py + cd "${_anki_dir}" + _your_ip_=$(ip route get 1.2.3.4 | awk '{print $7}') + sed -i "2s/0\.0\.0\.0/${_your_ip_}/" plugins/anki2.0/anki-sync-server.py + sed -i "3s/0\.0\.0\.0/${_your_ip_})/" plugins/anki2.0/anki-sync-server.py + sed -i "3s/0\.0\.0\.0/${_your_ip_}/" plugins/anki2.1/anki-sync-server/__init__.py + sed -i "3s/0\.0\.0\.0/${_your_ip_}/" plugins/anki2.1.28/anki-sync-server/__init__.py + sed -i "7s/0\.0\.0\.0/${_your_ip_}/" plugins/nginx/config - # set current ip address as the server's ip address - sed "3s/0\.0\.0\.0/$(ip route get 1.2.3.4 | awk '{print $7}')/" ankisyncd.conf -i + # set current ip address as the server's ip address and chang port + sed "3s/0\.0\.0\.0/${_your_ip_}/" ankisyncd.conf -i + sed "4s/27701/27702/" ankisyncd.conf -i # set user and directory information for systemd service file # the user is going to be named the same thing as the package name (minus '-git') diff --git a/anki-sync-server.install b/anki-sync-server.install index 2997b2fbe941..127bcc5f008b 100644 --- a/anki-sync-server.install +++ b/anki-sync-server.install @@ -4,16 +4,21 @@ post_install() { chown -R anki-sync-server /opt/anki-sync-server chgrp -R anki-sync-server /opt/anki-sync-server + # install prerequisites as stated on the website + echo "installing python packages as anki-sync-server user..." + sudo -u anki-sync-server pip install -r /opt/anki-sync-server/requirements.txt --user --no-warn-script-location + + append_nginx_config + + #start nginx + systemctl enable nginx + systemctl start nginx + # link systemd service file ln -s /opt/anki-sync-server/plugins/systemd/anki-sync-server.service /etc/systemd/system/ systemctl enable anki-sync-server systemctl start anki-sync-server - # install prerequisites as stated on the website - echo "installing python packages as anki-sync-server user..." - sudo -u anki-sync-server pip install webob --user - sudo -u anki-sync-server pip install decorator --user - # post installation instructions cat << EOF ======================================================================= @@ -36,8 +41,12 @@ Plugin Installation: To have anki interface with the server, you'll need to copy the plugin from /opt/anki-sync-server/plugins to the relevant directory. +Anki 2.1.28 (and up): ~/.local/share/Anki/addons21 + ln -s /opt/anki-sync-server/plugins/anki2.1.28/anki-sync-server \\ + ~/.local/share/Anki2/addons21/ + Anki 2.1: ~/.local/share/Anki2/addons21/ - ln -s /opt/anki-sync-server/plugins/anki2.1/ankisyncd \\ + ln -s /opt/anki-sync-server/plugins/anki2.1/anki-sync-server \\ ~/.local/share/Anki2/addons21/ Anki 2.0: ~/Anki/addons @@ -49,7 +58,15 @@ or your OS equivalent. --------------- Run The Server: --------------- -To just run the server, go to: +The server should be set to auto start via systemctl and should be already running. +See: + + systemctl status anki-sync-server + systemctl status nginx + +for details. + +Otherwise, to run the server go to: /opt/anki-sync-server/ @@ -57,35 +74,19 @@ then run: sudo -u anki-sync-server python -m ankisyncd -if you run it as another user you may have to install some dependencies again: - - sudo pacman -S python2-webob python2-decorator +if you run it as another user you may have to install the dependencies again: -or: - - pip install --user webob decorator + pip install -r /opt/anki-sync-server/requirements.txt [--user] === (be aware you may have trouble with permissions on your auth.db if you run as different users!) === -The server is set to auto start via systemctl. -See: - - systemctl status anki-sync-server - -for details. - ------------------------- -Run Bundled Anki Client: ------------------------- -If you want to run the supplied anki client execute: - - /opt/anki-sync-server/anki-bundled/runanki +----- +NGINX +----- +/etc/nginx/nginx.conf has been modified and a backup has been saved to /etc/nginx/nginx.conf.pacsave. It would be a good idea to diff to see if anything has gone awry. -You'll need to install the listed requirements to get it running first. You can run the file +nginx.service is set to autostart. - sh install_anki_bundled.sh - -to do that. ======================================================================= EOF } @@ -112,40 +113,46 @@ pre_upgrade(){ cd "/opt/anki-sync-server" - auth="auth.db" - coll="collections" - sess="session.db" + local _auth_="auth.db" + local _coll_="collections" + local _sess_="session.db" - if [ -f "${auth}" ]; then - sudo mv -v "${auth}" "${auth}.BAK" + if [ -f "${_auth_}" ]; then + sudo mv -v "${_auth_}" "${_auth_}.BAK" fi - if [ -d "${coll}" ]; then - sudo mv -v "${coll}" "${coll}.BAK" + if [ -d "${_coll_}" ]; then + sudo mv -v "${_coll_}" "${_coll_}.BAK" fi - if [ -f "${sess}" ]; then - sudo mv -v "${sess}" "${sess}.BAK" + if [ -f "${_sess_}" ]; then + sudo mv -v "${_sess_}" "${_sess_}.BAK" fi } post_upgrade(){ + # install prerequisites as stated on the website + echo "installing python packages as anki-sync-server user..." + sudo -u anki-sync-server pip install -r /opt/anki-sync-server/requirements.txt --user + + append_nginx_config + cd "/opt/anki-sync-server" - auth="auth.db" - coll="collections" - sess="session.db" + local _auth_="auth.db" + local _coll_="collections" + local _sess_="session.db" - if [ -f "${auth}.BAK" ]; then - sudo mv -v "${auth}.BAK" "${auth}" + if [ -f "${_auth_}.BAK" ]; then + sudo mv -v "${_auth_}.BAK" "${_auth_}" fi - if [ -d "${coll}.BAK" ]; then - sudo mv -v "${coll}.BAK" "${coll}" + if [ -d "${_coll_}.BAK" ]; then + sudo mv -v "${_coll_}.BAK" "${_coll_}" fi - if [ -f "${sess}.BAK" ]; then - sudo mv -v "${sess}.BAK" "${sess}" + if [ -f "${_sess_}.BAK" ]; then + sudo mv -v "${_sess_}.BAK" "${_sess_}" fi sudo chown -R anki-sync-server /opt/anki-sync-server @@ -155,4 +162,21 @@ post_upgrade(){ sudo systemctl daemon-reload echo "starting anki-sync-server.service..." sudo systemctl start anki-sync-server + echo "starting nginx..." + sudo systemctl start nginx +} + +function append_nginx_config() { + # append nginx config to nginx config file + echo "appending nginx server config to /etc/nginx/nginx.conf" + local _config_dir_="/etc/nginx/" + local _pacsave_="${_config_dir_}/nginx.conf.pacsave" + local _config_="${_config_dir_}/nginx.conf" + if [ ! $(grep "anki-sync-server-request-unchunker" "${_config_}") ]; then + sudo cp "${_config_}" "${_pacsave_}" + sudo awk -f /opt/anki-sync-server/plugins/nginx/append.awk \ + "${_pacsave_}" > "${_config_}" + else + echo "nginx config aleady updated!" + fi } diff --git a/anki-sync-server.py b/anki-sync-server.py deleted file mode 100644 index 773fa2ac3753..000000000000 --- a/anki-sync-server.py +++ /dev/null @@ -1,3 +0,0 @@ -import anki.sync -anki.sync.SYNC_BASE = 'http://0.0.0.0:27701/' -anki.sync.SYNC_MEDIA_BASE = 'http://0.0.0.0:27701/msync/' diff --git a/anki2.0.py b/anki2.0.py new file mode 100644 index 000000000000..cbcb109fa031 --- /dev/null +++ b/anki2.0.py @@ -0,0 +1,3 @@ +import anki.sync +anki.sync.SYNC_BASE = 'http://0.0.0.0:27702/' +anki.sync.SYNC_MEDIA_BASE = 'http://0.0.0.0:27702/msync/' diff --git a/anki2.1.28.py b/anki2.1.28.py new file mode 100644 index 000000000000..fa03e266b50e --- /dev/null +++ b/anki2.1.28.py @@ -0,0 +1,5 @@ +import os + +addr = "http://0.0.0.0:27702/" # put your server address here +os.environ["SYNC_ENDPOINT"] = addr + "sync/" +os.environ["SYNC_ENDPOINT_MEDIA"] = addr + "msync/" diff --git a/__init__.py b/anki2.1.py index 6adb84d54363..1eac30427183 100644 --- a/__init__.py +++ b/anki2.1.py @@ -1,6 +1,6 @@ import anki.sync, anki.hooks, aqt -addr = "http://0.0.0.0:27701/" # put your server address here +addr = "http://0.0.0.0:27702/" # put your server address here anki.sync.SYNC_BASE = "%s" + addr def resetHostNum(): aqt.mw.pm.profile['hostNum'] = None diff --git a/install_anki_bundled.sh b/install_anki_bundled.sh deleted file mode 100644 index 7ada2672f48c..000000000000 --- a/install_anki_bundled.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh -cd /opt/anki-sync-server -sudo -u anki-sync-server git submodule update --init anki-bundled -cd anki-bundled -sudo pacman -S --asdeps python-beautifulsoup4 python-send2trash \ -python-pyaudio python-requests python-decorator \ -python-psutil python-distro python-markdown \ -python-pyqt5 python-pyqtwebengine -sudo -u anki-sync-server sh tools/build_ui.sh #for aqt dependency - -# mplayer is not included because I thought it was a lot of extra dependencies -# for functionality that seems very extra (video capability). If you need this -# you can install that yourself with: -# -# sudo pacman -S --asdeps mplayer diff --git a/nginx_append_config.awk b/nginx_append_config.awk new file mode 100755 index 000000000000..067ff1f298bc --- /dev/null +++ b/nginx_append_config.awk @@ -0,0 +1,19 @@ +#!/usr/bin/awk -f + +/^http {/ { + config_file = "/opt/anki-sync-server/plugins/nginx/config" + + print + while (getline nextLine && nextLine !~ "^}$") { + print nextLine + } + + while ((getline config < config_file)){ + print "\t" config + } + close(config) + print "}" + next +}; + +{print} diff --git a/nginx_config b/nginx_config new file mode 100644 index 000000000000..ba2583f667c9 --- /dev/null +++ b/nginx_config @@ -0,0 +1,9 @@ +server { + listen 27701; + server_name anki-sync-server-request-unchunker; + + location / { + proxy_http_version 1.0; + proxy_pass http://0.0.0.0:27702/; + } +} |