Giter Club home page Giter Club logo

sr.ht's Introduction

(fork of sr.ht)

Private file hosting with python/nginx

Differences from upstream

  • Fixed a few instances where page redirects would take you to the local IP of the sr.ht instance, which obviously isn't connectable from outside.
  • Removed most hardcoded branding and moved it to config strings.
  • Switched to simplex bootstrap theme
  • Some minor style fixes
  • Improvements to administration with some cli scripting
  • Removed the anime branding and replaced with a more sfw icon
  • Being able to delete files from the web interface

Running the site

Quick overview:

  1. Install dependencies
  2. Set up dependencies
  3. Clone the repository
  4. Configure the site
  5. Compile static assets
  6. Set up SQL
  7. Deployment

Install the dependencies

You'll need these things

  • Python 3 (python)
  • PostgreSQL (postgresql)
  • scss (ruby-sass)

The following ubuntu/debian packages would also be useful/required for some pip dependencies, equivalents should exist on your system

apt-get install build-essential libssl-dev libffi-dev python3-dev

Clone the repository

Find a place you want the code to live.

$ git clone git://github.com/optimumtact/sr.ht.git
$ cd sr.ht

Python dependencies I recommend using a virtual environment to host the sites dependencies and run it out of there

virtualenv -p python3 venv
source venv/bin/activate
pip install -r requirements.txt

The provided systemd files assume that the site is hosted in a virtualenv named venv

Set up services

I'll leave you to set up PostgreSQL however you please. Prepare a connection string that looks like this when you're done:

postgresql://username:password@hostname:port/database

We need to be able to create/alter/insert/update/delete in the database you give it.

Configure the site

$ cp alembic.ini.example alembic.ini
$ cp config.ini.example config.ini

Edit config.ini and alembic.ini to your liking.

Compile static assets

$ make

Run this again whenever you pull the code.

Deployment

What you do from here depends on your site-specific configuration. If you just want to run the site for development, run

python app.py

To run it in production, you probably want to use gunicorn behind an nginx proxy. There's a sample nginx config in the configs/ directory here, but you'll probably want to tweak it to suit your needs. Here's how you can run gunicorn, put this in your init scripts:

gunicorn app:app -b 127.0.0.1:8000

Note: you may have to install gunicorn first with

pip install gunicorn

The -b parameter specifies an endpoint to use. You probably want to bind this to localhost and proxy through from nginx. I'd also suggest blocking the port you choose from external access. It's not that gunicorn is bad, it's just that nginx is better.

When running in a production enviornment, run python app.py at least once and then read the SQL stuff below before you let it go for good.

nginx configuration is available in nginx/, modify it to suit your environment. nginx is required to run this website properly.

Becoming an admin and bootstrapping initial user

You can become an admin with the management cli script

$ cd /path/to/sr.ht/
$ python manage.py user create {yourusername} {password} {emailaddress}
$ python manage.py admin promote {youruser}

SQL Stuff

We use alembic for schema migrations between versions. The first time you run the application, the schema will be created. However, you need to tell alembic that you're already on the latest version

$ cd /path/to/sr.ht
$ bin/activate
$ bin/alembic -c alembic.ini stamp head

Congrats, you've got a schema in place. Run alembic upgrade head after pulling the code to update your schema to the latest version. Do this before you restart the site.

Customization

You can customize the appearance of the site with template overrides. Create a directory called overrides and copy templates from the templates directory into overrides. Modify them as you see fit, they will be used instead of the version from templates.

sr.ht's People

Contributors

ddevault avatar thereverend403 avatar optimumtact avatar ninja3047 avatar debetux avatar minus7 avatar

Watchers

James Cloos avatar Mike Ulan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.