mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-01 22:26:24 -07:00
Fix broken SQLite connection, update README
This commit is contained in:
parent
2651c38765
commit
4e67e072e5
10 changed files with 80 additions and 66 deletions
35
README.md
35
README.md
|
@ -1,27 +1,32 @@
|
|||
# Gochan
|
||||
Gochan
|
||||
=======
|
||||
A semi-standalone imageboard server written in Go
|
||||
|
||||
http://gochan.org
|
||||
|
||||
|
||||
## Installation
|
||||
# Installation
|
||||
|
||||
### Basic installation (from a release)
|
||||
## Basic installation (from a release)
|
||||
1. Extract the .tar.gz or the .zip file into a directory (for example, your home directory)
|
||||
2. Copy gochan.example.json to gochan.json and modify it to your liking.
|
||||
1. If you want to see debugging info/noncritical warnings, set verbosity to 1. If you want to see benchmarks as well, set it to 2.
|
||||
2. Make sure to set `DBname`, `DBusername`, and `DBpassword`, since these are required to connect to your MySQL database. Set `DomainRegex`,`SiteDomain`, since these are necessary in order to post and log in as a staff member without being rejected.
|
||||
3. If you're using nginx, copy gochan-fastcgi.nginx, or gochan-http.nginx if `UseFastCGI` is set to true to /etc/nginx/sites-enabled/, or the appropriate folder in Windows.
|
||||
4. If you're in Linux, you can optionally copy gochan.service to ~/.config/systemd/user/gochan.service and run `systemctl enable gochan.service` to have it run on login and `systemctl start gochan.service` to start it as a background service.
|
||||
1. If you aren't using a distro with systemd, you can start a screen session and run `./gochan`
|
||||
5. Go to http://[gochan url]/manage?action=boards, log in (default username/password is admin/password), create a board, and go to http://[gochan url]/manage?action=rebuildall
|
||||
1. For security reasons, you should probably go to http://[gochan url]/manage?action=staff to create a new admin user account and delete admin.
|
||||
2. Copy gochan.example.json to either gochan.json or (if you're in a UNIX-like OS) /etc/gochan/gochan.json and modify it as needed. See the Configuration section for more info.
|
||||
3. If you're using nginx, copy gochan-http.nginx, or gochan-fastcgi.nginx if `UseFastCGI` is set to true to /etc/nginx/sites-enabled/, or the appropriate folder in Windows.
|
||||
4. If you're using a Linux distribution with systemd, you can optionally copy gochan.service to /lib/systemd/system/gochan.service and run `systemctl enable gochan.service` to have it run on startup. Then run `systemctl start gochan.service` to start it as a background service.
|
||||
1. If you aren't using a distro with systemd, you can start a screen session and run `/path/to/gochan`
|
||||
5. Go to http://[gochan url]/manage?action=staff, log in (default username/password is admin/password), and create a new admin user (and any other staff users as necessary). Then delete the admin user for security.
|
||||
|
||||
### For developers (using Vagrant)
|
||||
## Configuration
|
||||
1. Make sure to set `DBtype`, `DBhost`, `DBname`, `DBusername`, and `DBpassword`, since these are required to connect to your SQL database. Valid `DBtype` values are "mysql", "postgres", and "sqlite3".
|
||||
1. To connect to a MySQL database, set `DBhost` to "tcp(ip:3306)" or a different port, if necessary.
|
||||
2. To connect to a PostgreSQL database, set `DBhost` to the IP address or hostname. Using a UNIX socket may work as well, but it is currently untested.
|
||||
3. To connect to a SQLite database, set `DBhost` to the path of the database file. It will be created if it does not already exist.
|
||||
2. Set `DomainRegex`,`SiteDomain`, since these are necessary in order to post and log in as a staff member.
|
||||
3. If you want to see debugging info/noncritical warnings, set verbosity to 1.
|
||||
|
||||
## For developers (using Vagrant)
|
||||
1. Install Vagrant and Virtualbox. Vagrant lets you create a virtual machine and run a custom setup/installation script to make installation easier and faster.
|
||||
2. From the command line, cd into vagrant/ and run `vagrant up`
|
||||
3. After it finishes installing the Ubuntu VM, follow the printed instructions.
|
||||
|
||||
### Theme development
|
||||
See `sass/README.md` for information on working with Sass and stylesheets.
|
||||
|
||||
# Theme development
|
||||
See [`sass/README.md`](sass/README.md) for information on working with Sass and stylesheets.
|
||||
|
|
25
build.sh
25
build.sh
|
@ -232,14 +232,14 @@ while [ -n "$1" ]; do
|
|||
documentroot=$installdir/html
|
||||
fi
|
||||
|
||||
cp $symarg $PWD/gochan $installdir/gochan
|
||||
cp $symarg $PWD/*.sql $installdir/
|
||||
cp $symarg -r $PWD/templates $installdir/templates/
|
||||
cp $symarg -f $PWD/gochan $installdir/gochan
|
||||
cp $symarg -f $PWD/*.sql $installdir/
|
||||
cp $symarg -rf $PWD/templates $installdir/templates/
|
||||
|
||||
cp gochan.example.json $installdir/
|
||||
cp -f gochan.example.json $installdir/
|
||||
if [ -f gochan.json ]; then
|
||||
echo "Copying config file to $installdir/gochan.json"
|
||||
cp $symarg $PWD/gochan.json $installdir/gochan.json
|
||||
cp $symarg -f $PWD/gochan.json $installdir/gochan.json
|
||||
fi
|
||||
mkdir -p $installdir/log
|
||||
|
||||
|
@ -248,17 +248,17 @@ while [ -n "$1" ]; do
|
|||
if [ -z "$documentroot" ]; then
|
||||
documentroot=/srv/gochan
|
||||
fi
|
||||
cp $symarg $PWD/gochan /usr/local/bin/gochan
|
||||
cp $symarg -f $PWD/gochan /usr/local/bin/gochan
|
||||
mkdir -p /usr/local/share/gochan
|
||||
cp $symarg $PWD/*.sql /usr/local/share/gochan/
|
||||
cp $symarg -r $PWD/templates /usr/local/share/gochan/templates/
|
||||
cp $symarg -f $PWD/*.sql /usr/local/share/gochan/
|
||||
cp $symarg -rf $PWD/templates /usr/local/share/gochan/templates/
|
||||
|
||||
echo "Creating /etc/gochan/ (if it doesn't already exist)"
|
||||
mkdir -p /etc/gochan
|
||||
cp gochan.example.json /etc/gochan/
|
||||
cp -f gochan.example.json /etc/gochan/
|
||||
if [ ! -f /etc/gochan/gochan.json ] && [ -f gochan.json ]; then
|
||||
echo "Copying gochan.json to /etc/gochan/gochan.json"
|
||||
cp $symarg $PWD/gochan.json /etc/gochan/gochan.json
|
||||
cp $symarg -f $PWD/gochan.json /etc/gochan/gochan.json
|
||||
fi
|
||||
echo "Creating /var/log/gochan (if it doesn't already exist)"
|
||||
mkdir -p /var/log/gochan
|
||||
|
@ -266,14 +266,13 @@ while [ -n "$1" ]; do
|
|||
|
||||
echo "Installing document root files and directories"
|
||||
mkdir -p $documentroot
|
||||
cp -r $symarg -f $PWD/html/css/ $documentroot/css/
|
||||
cp -r $symarg -f $PWD/html/javascript/ $documentroot/javascript/
|
||||
cp $symarg -rf $PWD/html/css/ $documentroot/css/
|
||||
cp $symarg -rf $PWD/html/javascript/ $documentroot/javascript/
|
||||
files=$PWD/html/*
|
||||
for f in $files; do
|
||||
if [ -f $f ]; then
|
||||
destfile=$documentroot/$(basename $f)
|
||||
echo "Installing $f to $destfile"
|
||||
# rm -f $destfile
|
||||
cp $symarg -f $f $destfile
|
||||
fi
|
||||
done
|
||||
|
|
|
@ -3,7 +3,7 @@ Description=gochan Daemon
|
|||
After=network.target
|
||||
|
||||
[Service]
|
||||
ExecStart=/home/vagrant/gochan/gochan
|
||||
ExecStart=/usr/local/bin/gochan
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
|
@ -50,7 +50,7 @@ CREATE TABLE IF NOT EXISTS DBPREFIXboards (
|
|||
section INT NOT NULL DEFAULT 1,
|
||||
max_file_size INT NOT NULL DEFAULT 4718592,
|
||||
max_pages SMALLINT NOT NULL DEFAULT 11,
|
||||
default_style VARCHAR(45) NOT NULL,
|
||||
default_style VARCHAR(45) NOT NULL DEFAULT '',
|
||||
locked BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
created_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
anonymous VARCHAR(45) NOT NULL DEFAULT 'Anonymous',
|
||||
|
@ -135,7 +135,7 @@ CREATE TABLE IF NOT EXISTS DBPREFIXsections (
|
|||
abbreviation VARCHAR(10) NOT NULL
|
||||
);
|
||||
|
||||
CREATE TEMP TABLE IF NOT EXISTS DBPREFIXsessions (
|
||||
CREATE TABLE IF NOT EXISTS DBPREFIXsessions (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
name CHAR(16) NOT NULL,
|
||||
sessiondata VARCHAR(45) NOT NULL,
|
||||
|
|
|
@ -126,21 +126,6 @@ func buildBoardPages(board *Board) (html string) {
|
|||
var stickied_threads []interface{}
|
||||
var nonstickied_threads []interface{}
|
||||
|
||||
// Check that the board's configured directory is indeed a directory
|
||||
results, err := os.Stat(path.Join(config.DocumentRoot, board.Dir))
|
||||
if err != nil {
|
||||
// Try creating the board's configured directory if it doesn't exist
|
||||
err = os.Mkdir(path.Join(config.DocumentRoot, board.Dir), 0777)
|
||||
if err != nil {
|
||||
html += handleError(1, "Failed creating /"+board.Dir+"/: "+err.Error())
|
||||
return
|
||||
}
|
||||
} else if !results.IsDir() {
|
||||
// If the file exists, but is not a folder, notify the user
|
||||
html += handleError(1, "Error: /"+board.Dir+"/ exists, but is not a folder.")
|
||||
return
|
||||
}
|
||||
|
||||
// Get all top level posts for the board.
|
||||
op_posts, err := getPostArr(map[string]interface{}{
|
||||
"boardid": board.ID,
|
||||
|
@ -363,11 +348,17 @@ func buildBoards(which ...int) (html string) {
|
|||
}
|
||||
for _, board := range boards {
|
||||
boardPath := path.Join(config.DocumentRoot, board.Dir)
|
||||
if _, err := os.Stat(boardPath); err != nil {
|
||||
// Board was most likely just recently created
|
||||
if err = os.Mkdir(boardPath, 0666); err != nil {
|
||||
html += handleError(0, "Error creating board directory: %s\n", err.Error()) + "<br />\n"
|
||||
}
|
||||
if err := os.Mkdir(boardPath, 0666); err != nil && !os.IsExist(err) {
|
||||
html += handleError(0, "Error creating board directories: %s\n", err.Error()) + "<br />\n"
|
||||
}
|
||||
if err := os.Mkdir(path.Join(boardPath, "res"), 0666); err != nil && !os.IsExist(err) {
|
||||
html += handleError(0, "Error creating board directories: %s\n", err.Error()) + "<br />\n"
|
||||
}
|
||||
if err := os.Mkdir(path.Join(boardPath, "src"), 0666); err != nil && !os.IsExist(err) {
|
||||
html += handleError(0, "Error creating board directories: %s\n", err.Error()) + "<br />\n"
|
||||
}
|
||||
if err := os.Mkdir(path.Join(boardPath, "thumb"), 0666); err != nil && !os.IsExist(err) {
|
||||
html += handleError(0, "Error creating board directories: %s\n", err.Error()) + "<br />\n"
|
||||
}
|
||||
|
||||
if board.EnableCatalog {
|
||||
|
|
|
@ -4,26 +4,39 @@ import (
|
|||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
var versionStr string
|
||||
var buildtimeString string // set in Makefile, format: YRMMDD.HHMM
|
||||
var buildtimeString string // set with build command, format: YRMMDD.HHMM
|
||||
|
||||
func main() {
|
||||
defer closeHandle(db)
|
||||
defer func() {
|
||||
if db != nil {
|
||||
println(0, "Cleaning up")
|
||||
execSQL("DROP TABLE " + config.DBprefix + "sessions")
|
||||
db.Close()
|
||||
}
|
||||
}()
|
||||
initConfig()
|
||||
printf(0, "Starting gochan v%s.%s, using verbosity level %d\n", versionStr, buildtimeString, config.Verbosity)
|
||||
connectToSQLServer()
|
||||
parseCommandLine()
|
||||
|
||||
printf(0, "Starting gochan v%s.%s, using verbosity level %d\n", versionStr, buildtimeString, config.Verbosity)
|
||||
println(0, "Loading and parsing templates...")
|
||||
if err := initTemplates("all"); err != nil {
|
||||
handleError(0, customError(err))
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
initServer()
|
||||
sc := make(chan os.Signal, 1)
|
||||
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
|
||||
go func() {
|
||||
initServer()
|
||||
}()
|
||||
<-sc
|
||||
}
|
||||
|
||||
func parseCommandLine() {
|
||||
|
|
|
@ -471,11 +471,16 @@ var manage_functions = map[string]ManageFunction{
|
|||
return
|
||||
}
|
||||
}
|
||||
|
||||
truncateSQL := "TRUNCATE " + config.DBprefix + "posts"
|
||||
if config.DBtype == "postgres" {
|
||||
var values []interface{} // only used for SQLite since it doesn't have a proper TRUNCATE
|
||||
if config.DBtype == "sqlite3" {
|
||||
truncateSQL = "DELETE FROM " + config.DBprefix + "posts; DELETE FROM sqlite_sequence WHERE name = ?;"
|
||||
values = append(values, config.DBprefix+"posts")
|
||||
} else if config.DBtype == "postgres" {
|
||||
truncateSQL += " RESTART IDENTITY"
|
||||
}
|
||||
if _, err = execSQL(truncateSQL); err != nil {
|
||||
if _, err = execSQL(truncateSQL, values...); err != nil {
|
||||
html += handleError(0, err.Error()) + "<br />\n"
|
||||
return
|
||||
}
|
||||
|
|
|
@ -44,10 +44,11 @@ func connectToSQLServer() {
|
|||
config.DBusername, config.DBpassword, config.DBhost, config.DBname)
|
||||
nilTimestamp = "0001-01-01 00:00:00"
|
||||
case "sqlite3":
|
||||
connStr = config.DBhost
|
||||
connStr = fmt.Sprintf("file:%s?mode=rwc&_auth&auth_user=%s&_auth_pass=%s&_journal_mode=WAL",
|
||||
config.DBhost, config.DBusername, config.DBpassword)
|
||||
nilTimestamp = "0001-01-01 00:00:00+00:00"
|
||||
default:
|
||||
handleError(0, "Invalid DBtype '%s' in gochan.json, valid values are 'mysql' and 'postgres'", config.DBtype)
|
||||
handleError(0, "Invalid DBtype '%s' in gochan.json, valid values are 'mysql', 'postgres', and 'sqlite3'", config.DBtype)
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
|
|
|
@ -101,18 +101,12 @@ fi
|
|||
EOF
|
||||
|
||||
chmod +x /home/vagrant/dbconnect.sh
|
||||
chmod +x /home/vagrant/buildgochan.sh
|
||||
|
||||
./build.sh dependencies
|
||||
./build.sh
|
||||
./build.sh install -s
|
||||
echo "Done installing"
|
||||
|
||||
if [ -d /lib/systemd ]; then
|
||||
ln -s /vagrant/gochan.service /lib/systemd/system/gochan.service
|
||||
systemctl enable gochan.service
|
||||
fi
|
||||
|
||||
cp gochan.example.json /etc/gochan/gochan.json
|
||||
|
||||
sed -i /etc/gochan/gochan.json \
|
||||
|
@ -136,6 +130,12 @@ elif [ "$DBTYPE" = "sqlite3" ]; then
|
|||
-e 's/"DBhost": ".*"/"DBhost": "gochan.db"/'
|
||||
fi
|
||||
|
||||
if [ -d /lib/systemd ]; then
|
||||
ln -s /vagrant/gochan.service /lib/systemd/system/gochan.service
|
||||
systemctl enable gochan.service
|
||||
systemctl start gochan.service
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "Server set up, please run \"vagrant ssh\" on your host machine."
|
||||
echo "Then browse to http://172.27.0.3/manage to complete installation."
|
||||
|
|
2
version
2
version
|
@ -1 +1 @@
|
|||
2.9.0
|
||||
2.9.1
|
Loading…
Add table
Add a link
Reference in a new issue