mirror of
https://github.com/th3r00t/pyShelf.git
synced 2026-04-28 01:59:35 -04:00
Merge pull request #53 from MartenBE/docker
First working draft docker-compose
This commit is contained in:
1
.github/SUPPORT.md
vendored
1
.github/SUPPORT.md
vendored
@@ -83,3 +83,4 @@ Please contact us using any of the options below for support. Please be prepared
|
||||
### Live Support Options
|
||||
* Discord: [https://discord.gg/H9TbNJS](https://discord.gg/H9TbNJS)
|
||||
* IRC: [irc.freenode.net/pyShelf](irc://freenode.net/pyshelf)
|
||||
* Matrix.org: [#irc_#pyshelf:pyshelf.com](https://app.element.io/#/room/#irc_#pyshelf:pyshelf.com)
|
||||
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -130,6 +130,8 @@ config.backup.json
|
||||
uwsgi.ini
|
||||
installer.log
|
||||
pyshelf_nginx.conf
|
||||
!docker/pyshelf_nginx.conf
|
||||
.env
|
||||
tags
|
||||
TAGS
|
||||
config.json
|
||||
|
||||
20
Dockerfile
20
Dockerfile
@@ -1,20 +0,0 @@
|
||||
FROM archlinux:latest
|
||||
RUN pacman -Syy
|
||||
RUN pacman -Syu --noconfirm
|
||||
RUN pacman -S --noconfirm python python-pip git postgresql sudo gcc
|
||||
RUN sudo -u postgres initdb --locale=en_US.UTF-8 -E UTF8 -D /var/lib/postgres/data
|
||||
RUN useradd pyshelf && chpasswd pyshelf:pyshelf
|
||||
#RUN mkdir -p /srv/Books && mkdir -p /srv/http && mkdir -p /srv/logs/ && mkdir -p /run/postgresql && \
|
||||
# touch /srv/logs/pgsql.log && chown postgres.postgres /run/postgresql && \
|
||||
# chown http.pyshelf /srv/Books && chown http.pyshelf /srv/http && chown postgres.postgres /srv/logs/pgsql.log
|
||||
VOLUME /srv/Books ./Books
|
||||
VOLUME /srv/http .
|
||||
VOLUME /srv/logs ./logs
|
||||
VOLUME /var/lib/postgres/data ./pgdata
|
||||
RUN sudo -u postgres pg_ctl -D /var/lib/postgres/data -l /srv/logs/pgsql.log start
|
||||
RUN sudo -u postgres psql -f create_db.sql
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
WORKDIR /srv/http
|
||||
RUN pip install -r requirements.txt
|
||||
EXPOSE 80 8000
|
||||
CMD ["sh", "-c","/srv/http/entry.sh"]
|
||||
130
README.md
130
README.md
@@ -7,26 +7,34 @@
|
||||

|
||||
|
||||
|
||||
### You dont need a X server to host a website, or your Movie & Tv collection, so why should you need one to host ebooks?
|
||||
<i>Other solutiions require you to have access to an X server to at the very least generate your book database, pyShelf doesnt.We aim to provide a fully featured ebook server with minimal requirements, and no reliance on X whatsoever.</i>
|
||||
### You dont need an X server to host a website, or your Movie & Tv collection, so why should you need one to host ebooks?
|
||||
|
||||
_Other solutiions require you to have access to an X server to at the very least generate your book database, pyShelf doesnt.We aim to provide a fully featured ebook server with minimal requirements, and no reliance on X whatsoever._
|
||||
|
||||
Follow or influence development @ <p align="center"><b>
|
||||
<a href="https://discord.gg/H9TbNJS">Discord</a>
|
||||
| <a href="https://webchat.freenode.net/#pyshelf">IRC</a>
|
||||
| <a href="https://app.element.io/#/room/#irc_#pyshelf:pyshelf.com">Matrix.org</a>
|
||||
</b></p>
|
||||
|
||||
Follow or influence development @ <p align="center"><b> <a href="https://discord.gg/H9TbNJS">Discord</a> | <a href="https://webchat.freenode.net/#pyshelf">IRC</a> freenode.net @ #pyshelf</b></p>
|
||||
## Current Features
|
||||
* Custom Installer works only on Arch Based Distros
|
||||
|
||||
* Recursive Scanning
|
||||
* Fast database access
|
||||
* Django based frontend
|
||||
* [Django](https://www.djangoproject.com/) based frontend
|
||||
* Basic seaching via a SearchVector of author, title, & file_name fields.
|
||||
* Ebook Downloading
|
||||
* Collections
|
||||
|
||||
## Currently Supported Formats
|
||||
|
||||
* epub
|
||||
* mobi
|
||||
|
||||
|
||||
## 0.6.0 Patch Notes.
|
||||
|
||||
# New Features
|
||||
|
||||
* .mobi Yep mobis are now a thing!
|
||||
* Result set ordering
|
||||
* You can now choose to order your results:
|
||||
@@ -49,28 +57,31 @@ Follow or influence development @ <p align="center"><b> <a href="https://discord
|
||||
* [ ] Control panel
|
||||
* [ ] Book details
|
||||
* Whatever else :)
|
||||
|
||||
## Installation Example
|
||||
|
||||
<a href="https://vimeo.com/382292764" target="_blank">pyShelf Installation Video</a>
|
||||
|
||||
## Further Installation & Support Information
|
||||
|
||||
* [SUPPORT.md](https://github.com/th3r00t/pyShelf/blob/development/.github/SUPPORT.md)
|
||||
|
||||
### Pre-req Dependencies
|
||||
* gcc -- This will be installed by the new pre-installer script if its binary is not detected at /usr/bin/gcc
|
||||
Users on distros other then Arch should install gcc via their systems package manager prior to
|
||||
running the installer.
|
||||
* Python3
|
||||
|
||||
* gcc
|
||||
* python3
|
||||
* pip
|
||||
|
||||
# Installation
|
||||
This project is currently targeted towards Network Administrators, and other home
|
||||
enthusiasts whom I assume will know how to setup a Django app, and a
|
||||
Postgres server.
|
||||
|
||||
Once your environment is ready very little is required to get the system up and running
|
||||
This project is currently targeted towards Network Administrators, and other home
|
||||
enthusiasts whom I assume will know how to setup a [Django](https://www.djangoproject.com/) app, and a
|
||||
[PostgreSQL](https://www.postgresql.org/) server.
|
||||
|
||||
Once your environment is ready very little is required to get the system up and running:
|
||||
* From the main directory
|
||||
* setup configurations as discussed in [SUPPORT.md](https://github.com/th3r00t/pyShelf/blob/development/.github/SUPPORT.md)
|
||||
* `pip install -r requirments.txt`
|
||||
* `pip install -r requirements.txt`
|
||||
* `cd src`
|
||||
* `python manage.py migrate`
|
||||
* `cd ..`
|
||||
@@ -78,23 +89,8 @@ Once your environment is ready very little is required to get the system up and
|
||||
* `./makecollections`
|
||||
* Browse to the site as defined in your apache | nginx config
|
||||
|
||||
## Included installer
|
||||
<a href="https://vimeo.com/382292764" target="_blank">pyShelf Installation Video</a>
|
||||
## Installation & Support Information
|
||||
|
||||
The installer will only run correctly on arch based distros. This could be
|
||||
easily rectified to include other package managers, Members of the community
|
||||
are welcome to dig into the installer source and patch in support
|
||||
for other package managers.
|
||||
|
||||
There is some support for detection of the aptitude package manager
|
||||
installation already present in the source now, however it is not complete and
|
||||
should not be relied upon to be present in future releases unless completed by
|
||||
a member of the community,
|
||||
|
||||
The installer will walk you through all the configurations required by pyShelf to
|
||||
run if you are running on Arch linux.
|
||||
|
||||
## Further Installation & Support Information
|
||||
* [SUPPORT.md](https://github.com/th3r00t/pyShelf/blob/development/.github/SUPPORT.md)
|
||||
|
||||
## Development
|
||||
@@ -110,56 +106,72 @@ _Before advancing version numbers be sure to set PROJECT_NUMBER in doxygen.conf
|
||||
|
||||
## Configuration
|
||||
|
||||
All configuration is now handled by the installer.
|
||||
|
||||
Running via the Django test server might be possible, albeit not recomended.
|
||||
Running via the [Django](https://www.djangoproject.com/) test server might be possible, albeit not recomended.
|
||||
|
||||
## Docker
|
||||
|
||||
Installation for Docker is handled by docker-compose
|
||||
The official Docker image for pyShelf is [`pyshelf/pyshelf`](https://hub.docker.com/r/pyshelf/pyshelf). The easiest way to get pyShelf running is through `docker-compose`. Here is an example `docker-compose.yml`:
|
||||
|
||||
It will spin up two containers: one postgres, one for the Django application
|
||||
```
|
||||
version: "3.7"
|
||||
|
||||
Edit [docker/.env](docker/.env)
|
||||
services:
|
||||
db:
|
||||
image: "postgres"
|
||||
environment:
|
||||
- "POSTGRES_PASSWORD=pyshelf"
|
||||
- "POSTGRES_USER=pyshelf"
|
||||
- "POSTGRES_DB=pyshelf"
|
||||
volumes:
|
||||
- "pgdata:/var/lib/postgresql/data/"
|
||||
|
||||
`docker-compose -f docker/docker-compose.yml --env-file=docker/.env up -d`
|
||||
pyshelf:
|
||||
image: "pyshelf/pyshelf"
|
||||
ports:
|
||||
- "8080:8000"
|
||||
volumes:
|
||||
- "${LOCAL_BOOK_DIR}:/books"
|
||||
depends_on:
|
||||
- db
|
||||
|
||||
`docker exec -it -d docker_pyshelf_1 python3 manage.py migrate`
|
||||
volumes:
|
||||
pgdata:
|
||||
```
|
||||
|
||||
`docker exec -it -d docker_pyshelf_1 python3 manage.py runserver 0.0.0.0:8000`
|
||||
You'll also need a `.env` file wich sets the `LOCAL_BOOK_DIR` variable, for example:
|
||||
|
||||
IMPORT BOOKS
|
||||
```
|
||||
LOCAL_BOOK_DIR=/home/someone/books
|
||||
```
|
||||
|
||||
Once the .epub files are in the directory specified in [docker/.env](docker/.env)
|
||||
The Docker image is still new, so there could still be some issues and missing features. Feel free to create a bug-issue when you encounter a bug. Development of the Docker image is discussed in https://github.com/th3r00t/pyShelf/pull/53 . Currently the database needs to be [PostgreSQL](https://www.postgresql.org/) with the account details shown in the example `docker-compose.yml` .
|
||||
|
||||
`docker exec -it docker_pyshelf_1 /bin/bash`
|
||||
## In Progress
|
||||
|
||||
`cd /usr/src/app/ && python3 importBooks`
|
||||
### Organizational tools.
|
||||
|
||||
### Docker Future Enhancements
|
||||
|
||||
- [ ] Change method of importing books ssibly cron or using the Django code
|
||||
- [ ] Look into having the migration work without having to manually execute
|
||||
|
||||
|
||||
### In Progress
|
||||
|
||||
#### Organizational tools.
|
||||
- [x] Automated Collections
|
||||
- [ ] Manual Collections
|
||||
- [ ] Books Removal
|
||||
- [ ] Access Restrictions
|
||||
- [ ] Metadata Manipulation
|
||||
- [ ] Others?
|
||||
#### Improved cover image storage, and acquisition.
|
||||
#### OPDS Support
|
||||
#### Support for other formats
|
||||
|
||||
### Improved cover image storage, and acquisition.
|
||||
|
||||
### OPDS Support
|
||||
|
||||
### Support for other formats
|
||||
|
||||
- [x] .mobi
|
||||
- [ ] .pdf
|
||||
- [ ] .cbz
|
||||
- [ ] .zip (Zipped book folders, is this a new idea? (Consider storing your library folders zipped and retrieving a book on demand))
|
||||
|
||||
### Future Goals
|
||||
#### Terminal Backend for catalogue maintenance
|
||||
#### Calculate page count from total characters
|
||||
## Future Goals
|
||||
|
||||
### Terminal Backend for catalogue maintenance
|
||||
|
||||
### Calculate page count from total characters
|
||||
|
||||
* (Thanks to @Fireblend for the idea) https://github.com/th3r00t/pyShelf/issues/3
|
||||
|
||||
14
config.json
Normal file → Executable file
14
config.json
Normal file → Executable file
@@ -1 +1,13 @@
|
||||
{"TITLE": "pyShelf E-Book Server", "VERSION": "0.6.0", "BOOKPATH": "/home/raelon/Books", "DB_HOST": "localhost", "DB_PORT": "5432", "DATABASE": "pyshelf", "USER": "pyshelf", "PASSWORD": "pyshelf", "BOOKSHELF": "data/shelf.json", "ALLOWED_HOSTS": "*", "hostname": "localhost", "webport": "8000", "wsgiport": "8001", "SECRET": "r0m#@$d(cs^si9_jmm)z-z#6-4-(snoctd)l(4becso9k=dwvs"}
|
||||
{
|
||||
"TITLE": "pyShelf E-Book Server",
|
||||
"VERSION": "0.6.0",
|
||||
"BOOKPATH": "/books",
|
||||
"DB_HOST": "db",
|
||||
"DB_PORT": "5432",
|
||||
"DATABASE": "pyshelf",
|
||||
"USER": "pyshelf",
|
||||
"PASSWORD": "pyshelf",
|
||||
"BOOKSHELF": "data/shelf.json",
|
||||
"ALLOWED_HOSTS": "*",
|
||||
"SECRET": "r0m#@$d(cs^si9_jmm)z-z#6-4-(snoctd)l(4becso9k=dwvs"
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
CREATE USER pyshelf WITH PASSWORD 'pyshelf';
|
||||
CREATE DATABASE pyshelf;
|
||||
GRANT ALL PRIVILEGES ON DATABASE pyshelf TO pyshelf;
|
||||
13
database.sh
13
database.sh
@@ -1,13 +0,0 @@
|
||||
#!/bin/bash
|
||||
sudo -u postgres pg_ctl -D /var/lib/postgres/data -l /srv/logs/pgsql.log start &&
|
||||
sudo -u postgres psql -f create_db.sql &&
|
||||
rm /srv/http/database.sh &&
|
||||
echo "sudo -u postgres pg_ctl -D /var/lib/postgres/data -l /srv/logs/lgsql.log start" > /srv/http/database.sh &&
|
||||
chmod +x /srv/http/database.sh &&
|
||||
cd src && \
|
||||
python manage.py makemigrations && \
|
||||
python manage.py makemigrations interface && \
|
||||
python manage.py migrate && \
|
||||
python manage.py migrate interface && \
|
||||
cd ..
|
||||
echo "pyShelf Env Started"
|
||||
6
docker/.env
vendored
6
docker/.env
vendored
@@ -1,6 +0,0 @@
|
||||
LOCAL_BOOK_DIR=/home/user/pyShelf/Books
|
||||
PORT=8088
|
||||
POSTGRES_VER=12.2
|
||||
POSTGRES_USER=pyshelf
|
||||
POSTGRES_PASSWORD=pyshelf
|
||||
POSTGRES_DB=pyshelf
|
||||
40
docker/Dockerfile
vendored
40
docker/Dockerfile
vendored
@@ -1,20 +1,26 @@
|
||||
# docker build -t ubuntu1604py36
|
||||
FROM ubuntu:18.04
|
||||
FROM ubuntu
|
||||
|
||||
RUN apt-get update && apt-get install -y software-properties-common
|
||||
RUN add-apt-repository ppa:deadsnakes/ppa
|
||||
RUN apt-get update -y
|
||||
|
||||
RUN apt-get install -y build-essential python3.8 python3.8-dev python3-pip python3.8-venv && apt-get install -y git
|
||||
|
||||
# update pip
|
||||
RUN python3 -m pip install wheel
|
||||
RUN git clone https://github.com/hat/pyShelf.git /usr/src/app/
|
||||
RUN python3 -m pip install -r /usr/src/app/requirements.txt
|
||||
EXPOSE 8000
|
||||
|
||||
WORKDIR /usr/src/app/src/
|
||||
#RUN ../docker/scripts/wait-for-it.sh db:5432
|
||||
RUN python3 manage.py migrate
|
||||
#RUN python3 manage.py migrate interface
|
||||
CMD ["python3", "manage.py", "runserver", "0.0.0.0:8000"]
|
||||
RUN apt-get update -y
|
||||
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential python3 python3-dev python3-pip python3-venv nginx-full
|
||||
|
||||
COPY . /pyshelf
|
||||
|
||||
WORKDIR /pyshelf/
|
||||
RUN python3 -m pip install -r requirements.txt
|
||||
|
||||
COPY ./docker/pyshelf_nginx.conf /etc/nginx/sites-available/pyshelf_nginx.conf
|
||||
RUN ln -s /etc/nginx/sites-available/pyshelf_nginx.conf /etc/nginx/sites-enabled/
|
||||
|
||||
WORKDIR /pyshelf/
|
||||
ENTRYPOINT cd src/ \
|
||||
&& python3 manage.py makemigrations \
|
||||
&& python3 manage.py makemigrations interface \
|
||||
&& python3 manage.py migrate \
|
||||
&& python3 manage.py migrate interface \
|
||||
&& cd .. \
|
||||
&& python3 importBooks \
|
||||
&& python3 makeCollections \
|
||||
&& nginx -g "daemon on;" \
|
||||
&& uwsgi --ini uwsgi.ini
|
||||
6
docker/README.md
vendored
Normal file
6
docker/README.md
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
Use `docker build -t pyshelf/pyshelf -f ./docker/Dockerfile .` in the project root to build the pyshelf image.
|
||||
|
||||
Make sure the following files are in sync:
|
||||
* config.json
|
||||
* docker/pyshelf_nginx.conf
|
||||
* uwsgi.ini
|
||||
32
docker/development.docker-compose.yml
vendored
Normal file
32
docker/development.docker-compose.yml
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
version: "3.7"
|
||||
|
||||
# This file is used to test the docker image. To host pyShelf yourself for
|
||||
# production, please use the official pyShelf image on
|
||||
# https://hub.docker.com/r/pyshelf/pyshelf
|
||||
|
||||
# For development, use the following command in the root folder:
|
||||
# `docker-compose -f .\docker\development.docker-compose.yml up --build`
|
||||
|
||||
services:
|
||||
db:
|
||||
image: "postgres"
|
||||
environment:
|
||||
- "POSTGRES_PASSWORD=pyshelf"
|
||||
- "POSTGRES_USER=pyshelf"
|
||||
- "POSTGRES_DB=pyshelf"
|
||||
volumes:
|
||||
- "db_data:/var/lib/postgresql/data/"
|
||||
|
||||
pyshelf:
|
||||
build:
|
||||
context: ..
|
||||
dockerfile: ./docker/Dockerfile
|
||||
ports:
|
||||
- "8080:8000"
|
||||
volumes:
|
||||
- "${LOCAL_BOOK_DIR}:/books"
|
||||
depends_on:
|
||||
- db
|
||||
|
||||
volumes:
|
||||
db_data:
|
||||
30
docker/docker-compose.yml
vendored
30
docker/docker-compose.yml
vendored
@@ -1,30 +0,0 @@
|
||||
version: "3.7"
|
||||
services:
|
||||
db:
|
||||
image: "postgres:${POSTGRES_VER}"
|
||||
environment:
|
||||
- "POSTGRES_PASSWORD=${POSTGRES_PASSWORD}"
|
||||
- "POSTGRES_USER=${POSTGRES_USER}"
|
||||
- "POSTGRES_DB=${POSTGRES_DB}"
|
||||
volumes:
|
||||
- ./postgres_data/:/var/lib/postgresql/data/
|
||||
|
||||
pyshelf:
|
||||
build:
|
||||
context: ./
|
||||
dockerfile: Dockerfile
|
||||
volumes:
|
||||
- "${LOCAL_BOOK_DIR}:/usr/src/app/Books"
|
||||
# - "./cron/root:/etc/crontabs/root"
|
||||
# - "./scripts/wait-for-it.sh:/usr/src/app/src/"
|
||||
ports:
|
||||
- "${PORT}:8000"
|
||||
depends_on:
|
||||
- db
|
||||
|
||||
networks:
|
||||
default:
|
||||
driver: bridge
|
||||
ipam:
|
||||
config:
|
||||
- subnet: 10.20.20.0/24
|
||||
30
docker/pyshelf_nginx.conf
vendored
Normal file
30
docker/pyshelf_nginx.conf
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
upstream django {
|
||||
server unix:///tmp/pyshelf_wsgi.sock;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 8000;
|
||||
server_name localhost;
|
||||
access_log /var/log/nginx/pyshelf.access.log;
|
||||
error_log /var/log/nginx/pyshelf.error.log;
|
||||
charset utf-8;
|
||||
client_max_body_size 75M;
|
||||
|
||||
location /media {
|
||||
root /pyshelf/src/interface;
|
||||
}
|
||||
|
||||
location /static {
|
||||
root /pyshelf/src/interface;
|
||||
}
|
||||
|
||||
location /books {
|
||||
internal;
|
||||
alias /pyshelf;
|
||||
}
|
||||
|
||||
location / {
|
||||
uwsgi_pass django;
|
||||
include uwsgi_params;
|
||||
}
|
||||
}
|
||||
4
entry.sh
4
entry.sh
@@ -1,4 +0,0 @@
|
||||
#!/bin/bash
|
||||
#sh /srv/http/database.sh
|
||||
sudo -u postgres pg_ctl -D /var/lib/postgres/data -l /srv/logs/pgsql.log start &&
|
||||
#gunicorn pyShelf.wsgi 8000:8000
|
||||
@@ -1,4 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
eval python3 preinstall
|
||||
eval "pip install -r requirements.txt"
|
||||
eval python3 installer
|
||||
395
installer
395
installer
@@ -1,395 +0,0 @@
|
||||
#!/usr/bin/ env python3
|
||||
import json
|
||||
import os
|
||||
import pathlib
|
||||
import platform
|
||||
from django.core.management.utils import get_random_secret_key
|
||||
|
||||
import psutil
|
||||
from src.backend.lib.display import TerminalDisplay
|
||||
|
||||
log_file = "installer.log"
|
||||
messages = []
|
||||
|
||||
|
||||
class Configuration:
|
||||
def __init__(self):
|
||||
self._cp = pathlib.Path("config.json")
|
||||
self._data = self.open_file()
|
||||
self.system = platform.system()
|
||||
|
||||
def open_file(self):
|
||||
"""
|
||||
Try to open and then backup the configuration file.
|
||||
Fail and return false if initial configuration is not found.
|
||||
# TODO: More specific error handling
|
||||
"""
|
||||
try:
|
||||
with open(str(self._cp), "r") as read_file:
|
||||
data = json.load(read_file)
|
||||
with open("config.backup.json", "w") as backup_file:
|
||||
json.dump(data, backup_file)
|
||||
return data
|
||||
except Exception as e:
|
||||
f = open(str(self._cp),"w")
|
||||
f
|
||||
print(e)
|
||||
return False
|
||||
|
||||
def write_file(self, data):
|
||||
"""
|
||||
Write the provided data to the new configuration file
|
||||
"""
|
||||
with open(str(self._cp), "w") as write_file:
|
||||
json.dump(data, write_file)
|
||||
return True
|
||||
|
||||
|
||||
class RequiredServices:
|
||||
def check_ps(self, service_list):
|
||||
"""
|
||||
Check service_list against running processes
|
||||
by calling self.process_list, remove found
|
||||
services from the list and return
|
||||
"""
|
||||
# Get the matched processes
|
||||
_matches = self.process_list().intersection(set(service_list))
|
||||
for r in _matches:
|
||||
service_list.remove(r)
|
||||
return service_list
|
||||
|
||||
@staticmethod
|
||||
def process_list():
|
||||
"""
|
||||
Iterate running processes returning the name of each
|
||||
make it a set and return
|
||||
"""
|
||||
_processes = []
|
||||
for p in psutil.process_iter():
|
||||
_processes.append(p.name())
|
||||
return set(_processes)
|
||||
|
||||
@staticmethod
|
||||
def web_server_found(service_list):
|
||||
# Determine whether or not both possible webservers are missing
|
||||
_c = 0
|
||||
for r in service_list:
|
||||
if r == "nginx" or r == "httpd":
|
||||
_c = _c + 1
|
||||
if _c > 1:
|
||||
return False # Return false if neither are found
|
||||
else:
|
||||
return True # Return true if one is found
|
||||
|
||||
@staticmethod
|
||||
def db_server_found(service_list):
|
||||
_c = 0
|
||||
for r in service_list:
|
||||
if r == "postgres":
|
||||
_c = _c + 1
|
||||
if _c > 0:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
class SystemInstaller:
|
||||
def __init__(self):
|
||||
self.bin = self.get()
|
||||
self.site_dirs = ["/etc/nginx/sites-available", "/etc/nginx/sites-enabled"]
|
||||
self.nginx_conf = "pyshelf_nginx.conf"
|
||||
|
||||
def get(self):
|
||||
platfrm = platform.platform().split("-")
|
||||
if platfrm[0].lower() == "linux":
|
||||
installers = [
|
||||
{"bin": "apt", "options": [], "search": "search", "install": "install"},
|
||||
{"bin": "pacman", "options": [], "search": "-Ss", "install": "-S"},
|
||||
{"bin": "yum", "options": [], "search": "search", "install": "install"},
|
||||
{"bin": "docker", "options": []},
|
||||
]
|
||||
_paths = os.environ["PATH"].split(":")
|
||||
for p in _paths:
|
||||
for _installer in installers:
|
||||
_fp = p + "/" + str(_installer["bin"])
|
||||
if os.path.isfile(_fp):
|
||||
global messages
|
||||
messages = messages + [
|
||||
"Found system installer binary " + str(_installer["bin"])
|
||||
]
|
||||
return _installer
|
||||
|
||||
def copy_config(self, _file=None, _dirs=None):
|
||||
if _file is None:
|
||||
_file = self.nginx_conf
|
||||
if _dirs is None:
|
||||
_dirs = self.site_dirs
|
||||
|
||||
outfile = "/%s" % _file.__str__()
|
||||
if os.path.isdir(_dirs[0]):
|
||||
os.system("sudo cp %s %s" % (_file, _dirs[0] + outfile))
|
||||
else:
|
||||
os.system("sudo mkdir %s" % _dirs[0])
|
||||
os.system("sudo cp %s %s" % (_file, _dirs[0] + outfile))
|
||||
try:
|
||||
if os.path.isdir(_dirs[1]):
|
||||
ln_string = str(_dirs[0] + outfile + " " + _dirs[1] + outfile)
|
||||
os.system("sudo ln -s %s" % ln_string)
|
||||
|
||||
""" TODO check for sites-enabled, create it if it doesnt exist,
|
||||
then symlink the config """
|
||||
except Exception as e:
|
||||
pass
|
||||
return True
|
||||
|
||||
def make_nginx_config(self, answers):
|
||||
root = os.path.abspath(".")
|
||||
_fp = "pyshelf_nginx.conf"
|
||||
for r in answers:
|
||||
if r["name"] == "hostname":
|
||||
hostname = r["answer"]
|
||||
elif r["name"] == "webport":
|
||||
port = r["answer"]
|
||||
elif r["name"] == "wsgiport":
|
||||
wsgiport = r["answer"]
|
||||
nginx_conf_str = """
|
||||
# pyshelf_nginx.conf
|
||||
upstream django {server unix:///tmp/pyshelf_wsgi.sock;}
|
||||
server {
|
||||
listen %s;
|
||||
server_name %s;
|
||||
access_log /var/log/nginx/pyshelf.access.log;
|
||||
error_log /var/log/nginx/pyshelf.error.log;
|
||||
charset utf-8;
|
||||
client_max_body_size 75M;
|
||||
location /media {root %s/src/interface;}
|
||||
location /static {root %s/src/interface;}
|
||||
location /books {internal; alias %s;}
|
||||
location / {uwsgi_pass django; include %s/uwsgi_params;}
|
||||
}
|
||||
""" % (
|
||||
port,
|
||||
hostname,
|
||||
root,
|
||||
root,
|
||||
root,
|
||||
root,
|
||||
)
|
||||
with open(_fp, "w") as write_file:
|
||||
write_file.write(nginx_conf_str)
|
||||
global messages
|
||||
messages = messages + ["Generated new pyshelf_nginx.conf", nginx_conf_str]
|
||||
|
||||
def make_wsgi_config(self, answers):
|
||||
root = os.path.abspath(".")
|
||||
_fp = "uwsgi.ini"
|
||||
for r in answers:
|
||||
if r["name"] == "hostname":
|
||||
hostname = r["answer"]
|
||||
elif r["name"] == "wsgiport":
|
||||
wsgiport = r["answer"]
|
||||
wsgi_conf_str = """
|
||||
[uwsgi]
|
||||
chdir=%s/src
|
||||
module=frontend.wsgi
|
||||
master=True
|
||||
pidfile=/tmp/pyShelf.pid
|
||||
vacuum=True
|
||||
socket=/tmp/pyshelf_wsgi.sock
|
||||
chmod-socket=666
|
||||
""" % (
|
||||
root,
|
||||
)
|
||||
with open(_fp, "w") as write_file:
|
||||
write_file.write(wsgi_conf_str)
|
||||
global messages
|
||||
messages = messages + ["Generated uwsgi.ini", wsgi_conf_str]
|
||||
|
||||
def log(self):
|
||||
global log_file
|
||||
global messages
|
||||
with open(log_file, "w") as write_file:
|
||||
write_file.write(TerminalDisplay().banner_render())
|
||||
for message in messages:
|
||||
write_file.write(message + "\n")
|
||||
messages = messages + ["Log file written to " + log_file.__str__()]
|
||||
|
||||
|
||||
config = Configuration().open_file()
|
||||
sysinstall = SystemInstaller()
|
||||
installer = sysinstall.bin
|
||||
# Get user configuration options
|
||||
install_answers = TerminalDisplay().installer()
|
||||
for key in install_answers:
|
||||
config[key["name"]] = key["answer"]
|
||||
# config["USER"] = os.environ["USER"]
|
||||
config["USER"] = "pyshelf"
|
||||
config["SECRET"] = get_random_secret_key()
|
||||
# Write configuration
|
||||
Configuration().write_file(config)
|
||||
# Start checking for our list of required services
|
||||
service_list = ["postgres", "nginx", "httpd"]
|
||||
req = RequiredServices().check_ps(service_list)
|
||||
# Does user have either nginx || apache?
|
||||
if RequiredServices().web_server_found(req) is False:
|
||||
web_prompt = [
|
||||
{
|
||||
"message": " You must have either apache or nginx\n would you like \
|
||||
us to try and install nginx now? Enter for default 'no' > ",
|
||||
"options": "nginx",
|
||||
"name": "NGINX",
|
||||
"answer": None,
|
||||
"default": "no",
|
||||
}
|
||||
]
|
||||
install_prompt = TerminalDisplay().prompt(web_prompt)
|
||||
if install_prompt[0]["answer"] == "yes":
|
||||
if installer is None:
|
||||
installer = SystemInstaller().bin
|
||||
if installer["bin"] == "pacman":
|
||||
package = "nginx-mainline"
|
||||
else:
|
||||
package = "nginx"
|
||||
options = ""
|
||||
for o in installer["options"]:
|
||||
options = options + " " + o
|
||||
cmd = (
|
||||
"sudo "
|
||||
+ installer["bin"]
|
||||
+ " "
|
||||
+ installer["install"]
|
||||
+ " "
|
||||
+ options
|
||||
+ package
|
||||
)
|
||||
install_status = os.system(cmd)
|
||||
os.system("sudo systemctl start nginx")
|
||||
messages = messages + [
|
||||
"Nginx installed and started",
|
||||
"To enable autostart you must run",
|
||||
" sudo systemctl enable nginx",
|
||||
"\n",
|
||||
]
|
||||
# Does user have postgreSQL?
|
||||
if RequiredServices().db_server_found(req) is False:
|
||||
db_prompt = [
|
||||
{
|
||||
"message": " You must have PostgreSQL\n would you like us to try \
|
||||
and install it now? Enter for default 'no' > ",
|
||||
"options": "postgres",
|
||||
"name": "postgresql",
|
||||
"answer": None,
|
||||
"default": "no",
|
||||
}
|
||||
]
|
||||
install_prompt = TerminalDisplay().prompt(db_prompt)
|
||||
if install_prompt[0]["answer"] == "yes":
|
||||
if installer is None:
|
||||
installer = SystemInstaller().bin
|
||||
options = ""
|
||||
for o in installer["options"]:
|
||||
options = options + " " + o
|
||||
package = "postgresql"
|
||||
cmd = (
|
||||
"sudo "
|
||||
+ installer["bin"]
|
||||
+ " "
|
||||
+ installer["install"]
|
||||
+ " "
|
||||
+ options
|
||||
+ package
|
||||
)
|
||||
install_status = os.system(cmd)
|
||||
for r in install_answers:
|
||||
if r["name"] == "PASSWORD":
|
||||
sql_pass = r["answer"]
|
||||
|
||||
sql_user = config["USER"]
|
||||
# sql_user = "pyshelf"
|
||||
db_name = "pyshelf"
|
||||
psql_cmd = (
|
||||
"CREATE DATABASE %s; CREATE USER %s WITH PASSWORD '%s'; \
|
||||
GRANT ALL PRIVILEGES ON DATABASE %s TO %s;"
|
||||
% (db_name, sql_user, sql_pass, db_name, sql_user)
|
||||
)
|
||||
_sql_file = "/tmp/create_db.sql"
|
||||
with open(_sql_file, "w") as sql_file_open:
|
||||
sql_file_open.write(psql_cmd)
|
||||
sql_file_open.close()
|
||||
os.system(
|
||||
"sudo -u postgres initdb --locale=en_US.UTF-8 -E UTF8 \
|
||||
-D /var/lib/postgres/data"
|
||||
)
|
||||
os.system("sudo systemctl start postgresql")
|
||||
os.system("sudo -u postgres psql -f %s" % _sql_file)
|
||||
# os.system("sudo -u postgres psql -c \'%s\'"%psql_cmd)
|
||||
messages = messages + [
|
||||
"PostgreSQL installed and started",
|
||||
"To enable autostart you must run",
|
||||
" sudo systemctl enable nginx",
|
||||
"\n",
|
||||
"Database cluster initialized at /var/lib/postgres",
|
||||
"pyShelf database and user created",
|
||||
psql_cmd,
|
||||
]
|
||||
else:
|
||||
for r in install_answers:
|
||||
if r["name"] == "PASSWORD":
|
||||
sql_pass = r["answer"]
|
||||
sql_user = config["USER"]
|
||||
db_name = "pyshelf"
|
||||
psql_cmd = (
|
||||
"CREATE DATABASE %s; CREATE USER %s WITH PASSWORD '%s'; \
|
||||
GRANT ALL PRIVILEGES ON DATABASE %s TO %s;"
|
||||
% (db_name, sql_user, sql_pass, db_name, sql_user)
|
||||
)
|
||||
_sql_file = "/tmp/create_db.sql"
|
||||
with open(_sql_file, "w") as sql_file_open:
|
||||
sql_file_open.write(psql_cmd)
|
||||
sql_file_open.close()
|
||||
os.system("sudo systemctl start postgresql")
|
||||
os.system("sudo -u postgres psql -f %s" % _sql_file)
|
||||
# os.system("sudo -u postgres psql -c \'%s\'"%psql_cmd)
|
||||
messages = messages + [
|
||||
"pyShelf database and user created",
|
||||
psql_cmd,
|
||||
]
|
||||
|
||||
# Post install configurations
|
||||
sysinstall.make_nginx_config(install_answers)
|
||||
try:
|
||||
os.chdir("src/")
|
||||
os.system("python manage.py makemigrations")
|
||||
os.system("python manage.py makemigrations interface")
|
||||
os.system("python manage.py migrate")
|
||||
os.system("python manage.py migrate interface")
|
||||
os.chdir("../")
|
||||
except Exception as e:
|
||||
print("-" * 80)
|
||||
print(" E:" + e)
|
||||
try:
|
||||
copy_config = sysinstall.copy_config()
|
||||
if copy_config:
|
||||
messages = messages + [
|
||||
"pyShelf site config copied to sites-available, and symlinked to sites-enabled"
|
||||
]
|
||||
except Exception as e:
|
||||
messages = messages + [
|
||||
"nginx site config not copied",
|
||||
'A nginx config for your install has been created "pyshelf_nginx.conf"',
|
||||
]
|
||||
sysinstall.make_wsgi_config(install_answers)
|
||||
messages = messages + [
|
||||
"You should now import your books by running importBooks",
|
||||
"You can then start the interface with uwsgi --ini uwsgi.ini",
|
||||
]
|
||||
|
||||
# Display end screen
|
||||
sysinstall.log()
|
||||
TerminalDisplay().clear()
|
||||
TerminalDisplay().banner()
|
||||
for message in messages:
|
||||
print(" " + message)
|
||||
print()
|
||||
|
||||
TerminalDisplay().h_rule()
|
||||
33
preinstall
33
preinstall
@@ -1,33 +0,0 @@
|
||||
#!python
|
||||
import os
|
||||
from subprocess import run
|
||||
|
||||
|
||||
class RequiredPackages:
|
||||
def __init__(self, bins):
|
||||
self.required = bins
|
||||
self.to_be_installed = []
|
||||
self.locate()
|
||||
|
||||
def locate(self):
|
||||
for bin in self.required:
|
||||
if os.path.isfile(bin[1]):
|
||||
continue
|
||||
else:
|
||||
self.to_be_installed.append(bin[0])
|
||||
return self.to_be_installed
|
||||
|
||||
|
||||
# Package List
|
||||
|
||||
package_list = [["gcc", "/usr/bin/gcc"]]
|
||||
|
||||
packages, required_packages = "", RequiredPackages(package_list)
|
||||
for package in required_packages.to_be_installed:
|
||||
packages = packages + package + " "
|
||||
try:
|
||||
ret = run(["sudo", "pacman", "-S", packages[0:-1]])
|
||||
print(ret)
|
||||
except Exception as e:
|
||||
ret = run(["pacman", "-S", packages[0:-1]])
|
||||
print(ret)
|
||||
@@ -18,6 +18,6 @@ prompt_toolkit
|
||||
psutil
|
||||
pyfiglet
|
||||
mobi-python
|
||||
pudb
|
||||
uwsgi
|
||||
jsonpickle
|
||||
django-widget-tweaks
|
||||
|
||||
@@ -17,7 +17,6 @@ class Config:
|
||||
"""
|
||||
_cp = pathlib.Path.joinpath(root, self._fp)
|
||||
_data = self.open_file(_cp)
|
||||
breakpoint()
|
||||
self.book_path = _data["BOOKPATH"]
|
||||
self.TITLE = _data["TITLE"]
|
||||
self.VERSION = _data["VERSION"]
|
||||
|
||||
@@ -1,119 +0,0 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
|
||||
import pyfiglet
|
||||
from prompt_toolkit import prompt as prm
|
||||
|
||||
|
||||
class TerminalDisplay:
|
||||
def __init__(self):
|
||||
self.term = True
|
||||
self.w, self.y = os.get_terminal_size()[0], os.get_terminal_size()[1]
|
||||
self.home = os.environ["HOME"]
|
||||
try:
|
||||
self.user = os.environ["USER"]
|
||||
except KeyError:
|
||||
self.user = None
|
||||
self.version = "0.4.0"
|
||||
self.slogan = "The Installer Initiative"
|
||||
self.green = "\033[1;32m"
|
||||
self.blue = "\033[94m"
|
||||
self.clr_term = "\033[m"
|
||||
|
||||
def screen(self):
|
||||
return self.term
|
||||
|
||||
def installer(self):
|
||||
questions = [
|
||||
{
|
||||
"message": ' Input the absolute path to your ebooks\n Enter for default "~/Books" > ',
|
||||
"options": "",
|
||||
"name": "BOOKPATH",
|
||||
"answer": None,
|
||||
"default": self.home + "/Books",
|
||||
},
|
||||
{
|
||||
"message": ' Input your PostgreSQL server ip\n Enter for default "localhost" > ',
|
||||
"options": "localhost",
|
||||
"name": "DB_HOST",
|
||||
"answer": None,
|
||||
"default": "localhost",
|
||||
},
|
||||
{
|
||||
"message": ' Input your PostgreSQL server port\n Enter for default "5432" > ',
|
||||
"options": "5432",
|
||||
"name": "DB_PORT",
|
||||
"answer": None,
|
||||
"default": "5432",
|
||||
},
|
||||
{
|
||||
"message": ' Input your PostgreSQL password\n Enter for default "pyshelf" > ',
|
||||
"options": "pyshelf",
|
||||
"name": "PASSWORD",
|
||||
"answer": None,
|
||||
"default": "pyshelf",
|
||||
},
|
||||
{
|
||||
"message": ' Web ui hostname/ip\n Enter for default "localhost" > ',
|
||||
"options": "localhost",
|
||||
"name": "hostname",
|
||||
"answer": None,
|
||||
"default": "localhost",
|
||||
},
|
||||
{
|
||||
"message": ' Web ui port\n Enter for default "8000" > ',
|
||||
"options": "8000",
|
||||
"name": "webport",
|
||||
"answer": None,
|
||||
"default": "8000",
|
||||
},
|
||||
{
|
||||
"message": ' wsgi port\n Enter for default "8001 > ',
|
||||
"options": "8001",
|
||||
"name": "wsgiport",
|
||||
"answer": None,
|
||||
"default": "8001",
|
||||
},
|
||||
]
|
||||
return self.prompt(questions)
|
||||
|
||||
@staticmethod
|
||||
def clear():
|
||||
os.system("cls" if os.name == "nt" else "clear")
|
||||
|
||||
def prompt(self, questions):
|
||||
self.clear()
|
||||
answers = questions
|
||||
for answer in answers:
|
||||
self.banner()
|
||||
answer["answer"] = prm(answer["message"])
|
||||
if answer["answer"] == "":
|
||||
answer["answer"] = answer["default"]
|
||||
self.clear()
|
||||
return answers
|
||||
|
||||
def h_rule(self):
|
||||
print("\u2501" * self.w)
|
||||
|
||||
def banner(self):
|
||||
self.h_rule()
|
||||
title = pyfiglet.Figlet(font="cyberlarge")
|
||||
print(self.green + title.renderText("pyShelf") + self.clr_term)
|
||||
print(
|
||||
self.blue + " version " + self.version + self.clr_term + " " + self.slogan
|
||||
)
|
||||
self.h_rule()
|
||||
print()
|
||||
|
||||
def banner_render(self):
|
||||
title = pyfiglet.Figlet(font="cyberlarge")
|
||||
_banner = (
|
||||
title.renderText("pyShelf")
|
||||
+ "\nversion "
|
||||
+ self.version
|
||||
+ " "
|
||||
+ self.slogan
|
||||
+ "\n"
|
||||
)
|
||||
return _banner
|
||||
@@ -33,7 +33,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
# SECRET_KEY = "@(9b9jslgg41u1u=mr)-2*-n2x0vef0zsy39*z@sz18&tvow18"
|
||||
SECRET_KEY = CONFIG.SECRET
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = TEMPLATE_DEBUG = True
|
||||
DEBUG = TEMPLATE_DEBUG = False
|
||||
if DEBUG is True:
|
||||
from pudb.remote import set_trace
|
||||
ALLOWED_HOSTS = CONFIG.allowed_hosts
|
||||
|
||||
18
uwsgi.ini
18
uwsgi.ini
@@ -1,10 +1,8 @@
|
||||
|
||||
[uwsgi]
|
||||
chdir=/home/raelon/Projects/pyShelf/src
|
||||
module=frontend.wsgi
|
||||
master=True
|
||||
pidfile=/tmp/pyShelf.pid
|
||||
vacuum=True
|
||||
socket=/tmp/pyshelf_wsgi.sock
|
||||
chmod-socket=666
|
||||
|
||||
[uwsgi]
|
||||
chdir=/pyshelf/src
|
||||
module=frontend.wsgi
|
||||
master=True
|
||||
pidfile=/tmp/pyShelf.pid
|
||||
vacuum=True
|
||||
socket=/tmp/pyshelf_wsgi.sock
|
||||
chmod-socket=666
|
||||
17
uwsgi_params
17
uwsgi_params
@@ -1,17 +0,0 @@
|
||||
|
||||
uwsgi_param QUERY_STRING $query_string;
|
||||
uwsgi_param REQUEST_METHOD $request_method;
|
||||
uwsgi_param CONTENT_TYPE $content_type;
|
||||
uwsgi_param CONTENT_LENGTH $content_length;
|
||||
|
||||
uwsgi_param REQUEST_URI $request_uri;
|
||||
uwsgi_param PATH_INFO $document_uri;
|
||||
uwsgi_param DOCUMENT_ROOT $document_root;
|
||||
uwsgi_param SERVER_PROTOCOL $server_protocol;
|
||||
uwsgi_param REQUEST_SCHEME $scheme;
|
||||
uwsgi_param HTTPS $https if_not_empty;
|
||||
|
||||
uwsgi_param REMOTE_ADDR $remote_addr;
|
||||
uwsgi_param REMOTE_PORT $remote_port;
|
||||
uwsgi_param SERVER_PORT $server_port;
|
||||
uwsgi_param SERVER_NAME $server_name;
|
||||
Reference in New Issue
Block a user