mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-02 15:06:23 -07:00
Don't create /etc/gochan or /var/log/gochan during vagrant provisioning, since gochan-install will do that
This commit is contained in:
parent
1a3877c807
commit
564d659e02
4 changed files with 89 additions and 64 deletions
79
build.py
79
build.py
|
@ -40,6 +40,21 @@ release_files = (
|
||||||
"README.md",
|
"README.md",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
INSTALL_SUCCESS_STR = """
|
||||||
|
gochan's files were successfully installed. To prepare a configuration file,
|
||||||
|
you can run gochan-installer and open the web interface at http://<your_site>/install.
|
||||||
|
This will generate a configuration file (which you can then edit) and prepare the database.
|
||||||
|
Alternatively, you can copy the example configuration file from examples/configs/gochan.example.json
|
||||||
|
to /etc/gochan/gochan.json and modify it as needed.
|
||||||
|
"""
|
||||||
|
|
||||||
|
SYSTEMD_INSTALL_STR = """
|
||||||
|
If your Linux distribution has systemd, you will also need to run the following commands:
|
||||||
|
cp examples/configs/gochan-<mysql|postgresql|sqlite3>.service /lib/systemd/system/gochan.service
|
||||||
|
systemctl daemon-reload
|
||||||
|
systemctl enable gochan.service
|
||||||
|
systemctl start gochan.service
|
||||||
|
"""
|
||||||
|
|
||||||
PATH_NOTHING = -1
|
PATH_NOTHING = -1
|
||||||
PATH_UNKNOWN = 0
|
PATH_UNKNOWN = 0
|
||||||
|
@ -157,7 +172,7 @@ def run_cmd(cmd, print_output=True, realtime=False, print_command=False):
|
||||||
stderr=subprocess.STDOUT)
|
stderr=subprocess.STDOUT)
|
||||||
output = ""
|
output = ""
|
||||||
status = 0
|
status = 0
|
||||||
if realtime: # print the command's output in real time, ignores print_output
|
if realtime and proc.stdout is not None: # print the command's output in real time, ignores print_output
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
realtime_output = proc.stdout.readline().decode("utf-8")
|
realtime_output = proc.stdout.readline().decode("utf-8")
|
||||||
|
@ -292,17 +307,18 @@ def install_executable(src_file, dest_dir, symlinks=False):
|
||||||
print(f"{src_file} and {dest_file} are the same file, skipping")
|
print(f"{src_file} and {dest_file} are the same file, skipping")
|
||||||
|
|
||||||
|
|
||||||
def install(prefix="/usr", document_root="/srv/gochan", symlinks=False, js_only=False, css_only=False, templates_only=False):
|
def install(prefix="/usr", document_root="/srv/gochan", symlinks=False, js_only=False, css_only=False, templates_only=False, quiet=False):
|
||||||
if gcos == "windows":
|
if gcos == "windows":
|
||||||
print("Installation is not currently supported for Windows, use the respective directory created by running `python build.py release`")
|
print("Installation is not currently supported for Windows, use the respective directory created by running `python build.py release`")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
mkdir(document_root)
|
mkdir(document_root)
|
||||||
mkdir(path.join(prefix, "share/gochan"))
|
mkdir(path.join(prefix, "share/gochan"))
|
||||||
print("Creating symbolic links: ", symlinks)
|
if (not quiet) and symlinks:
|
||||||
|
print("Creating symbolic links: ", symlinks)
|
||||||
|
|
||||||
start_dir = path.abspath(path.curdir)
|
start_dir = path.abspath(path.curdir)
|
||||||
done = False
|
done = False
|
||||||
if js_only is True:
|
if js_only:
|
||||||
# args contains --js, install the JavaScript files
|
# args contains --js, install the JavaScript files
|
||||||
os.chdir(path.join(start_dir,"html/"))
|
os.chdir(path.join(start_dir,"html/"))
|
||||||
if symlinks:
|
if symlinks:
|
||||||
|
@ -311,9 +327,10 @@ def install(prefix="/usr", document_root="/srv/gochan", symlinks=False, js_only=
|
||||||
copy("js/", document_root)
|
copy("js/", document_root)
|
||||||
os.chdir(start_dir)
|
os.chdir(start_dir)
|
||||||
done = True
|
done = True
|
||||||
print("JavaScript files installed")
|
if not quiet:
|
||||||
if css_only is True:
|
print("JavaScript files installed")
|
||||||
# args contains --js, install the CSS files
|
if css_only:
|
||||||
|
# args contains --css, install the CSS files
|
||||||
os.chdir(path.join(start_dir,"html/"))
|
os.chdir(path.join(start_dir,"html/"))
|
||||||
if symlinks:
|
if symlinks:
|
||||||
symlink("css/", path.join(document_root, "css"))
|
symlink("css/", path.join(document_root, "css"))
|
||||||
|
@ -321,9 +338,10 @@ def install(prefix="/usr", document_root="/srv/gochan", symlinks=False, js_only=
|
||||||
copy("css/", document_root)
|
copy("css/", document_root)
|
||||||
os.chdir(start_dir)
|
os.chdir(start_dir)
|
||||||
done = True
|
done = True
|
||||||
print("CSS files installed")
|
if not quiet:
|
||||||
if templates_only is True:
|
print("CSS files installed")
|
||||||
# args contains --js, install the templates
|
if templates_only:
|
||||||
|
# args contains --templates, install the templates
|
||||||
os.chdir(start_dir)
|
os.chdir(start_dir)
|
||||||
if symlinks:
|
if symlinks:
|
||||||
symlink("templates/", path.join(prefix, "share/gochan/templates"))
|
symlink("templates/", path.join(prefix, "share/gochan/templates"))
|
||||||
|
@ -331,20 +349,18 @@ def install(prefix="/usr", document_root="/srv/gochan", symlinks=False, js_only=
|
||||||
copy("templates/", path.join(prefix, "share/gochan"))
|
copy("templates/", path.join(prefix, "share/gochan"))
|
||||||
mkdir(path.join(prefix, "share/gochan/templates/override/"))
|
mkdir(path.join(prefix, "share/gochan/templates/override/"))
|
||||||
done = True
|
done = True
|
||||||
print("Templates installed")
|
if not quiet:
|
||||||
if done is True:
|
print("Templates installed")
|
||||||
print("Done installing specific stuff")
|
if done:
|
||||||
return
|
return
|
||||||
|
|
||||||
mkdir("/etc/gochan")
|
|
||||||
mkdir("/var/log/gochan")
|
|
||||||
|
|
||||||
for file in release_files:
|
for file in release_files:
|
||||||
try:
|
try:
|
||||||
if file.startswith("html/"):
|
if file.startswith("html/"):
|
||||||
trimmed = path.relpath(file, "html/")
|
trimmed = path.relpath(file, "html/")
|
||||||
os.chdir(path.join(start_dir, "html/"))
|
os.chdir(path.join(start_dir, "html/"))
|
||||||
print("copying", trimmed,"to", path.join(document_root, trimmed))
|
if not quiet:
|
||||||
|
print("copying", trimmed,"to", path.join(document_root, trimmed))
|
||||||
copy(trimmed, document_root)
|
copy(trimmed, document_root)
|
||||||
os.chdir(start_dir)
|
os.chdir(start_dir)
|
||||||
else:
|
else:
|
||||||
|
@ -360,22 +376,15 @@ def install(prefix="/usr", document_root="/srv/gochan", symlinks=False, js_only=
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
bin_dest_dir = path.join(prefix, "bin")
|
bin_dest_dir = path.join(prefix, "bin")
|
||||||
install_executable(gochan_exe, bin_dest_dir, symlinks)
|
install_executable(gochan_exe, bin_dest_dir, symlinks)
|
||||||
install_executable(installer_exe, bin_dest_dir, symlinks)
|
install_executable(installer_exe, bin_dest_dir, symlinks)
|
||||||
install_executable(migration_exe, bin_dest_dir, symlinks)
|
install_executable(migration_exe, bin_dest_dir, symlinks)
|
||||||
|
|
||||||
print(
|
if not quiet:
|
||||||
"gochan was successfully installed. If you haven't already, you should copy\n",
|
print(INSTALL_SUCCESS_STR)
|
||||||
"examples/configs/gochan.example.json to /etc/gochan/gochan.json (modify as needed)\n")
|
if gcos == "linux":
|
||||||
if gcos == "linux":
|
print(SYSTEMD_INSTALL_STR)
|
||||||
print(
|
|
||||||
"If your Linux distribution has systemd, you will also need to run the following commands:\n",
|
|
||||||
"cp examples/configs/gochan-[mysql|postgresql|sqlite3].service /lib/systemd/system/gochan.service\n",
|
|
||||||
"systemctl daemon-reload\n",
|
|
||||||
"systemctl enable gochan.service\n",
|
|
||||||
"systemctl start gochan.service\n")
|
|
||||||
|
|
||||||
|
|
||||||
def js(watch=False):
|
def js(watch=False):
|
||||||
|
@ -488,24 +497,26 @@ if __name__ == "__main__":
|
||||||
help="only install CSS")
|
help="only install CSS")
|
||||||
parser.add_argument("--templates",
|
parser.add_argument("--templates",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
help="install the template files")
|
help="only install the template files")
|
||||||
parser.add_argument("--prefix",
|
parser.add_argument("--prefix",
|
||||||
default="/usr",
|
default="/usr",
|
||||||
help="install gochan to this directory and its subdirectories")
|
help="install gochan to this directory and its subdirectories")
|
||||||
parser.add_argument("--documentroot",
|
parser.add_argument("--document-root",
|
||||||
default="/srv/gochan",
|
default="/srv/gochan",
|
||||||
help="install files in ./html/ to this directory to be requested by a browser")
|
help="only install files in ./html/ to this directory to be requested by a browser")
|
||||||
parser.add_argument("--symlinks",
|
parser.add_argument("--symlinks",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
help="create symbolic links instead of copying the files (may require admin/root privileges)")
|
help="create symbolic links instead of copying the files (may require admin/root privileges)")
|
||||||
|
parser.add_argument("--quiet", "-q",
|
||||||
|
action="store_true",
|
||||||
|
help="do not print any messages, only errors")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
install(args.prefix, args.documentroot, args.symlinks, args.js, args.css, args.templates)
|
install(args.prefix, args.document_root, args.symlinks, args.js, args.css, args.templates, args.quiet)
|
||||||
elif action == "js":
|
elif action == "js":
|
||||||
parser.add_argument("--watch", "-w",
|
parser.add_argument("--watch", "-w",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
help="automatically rebuild when you change a file (keeps running)")
|
help="automatically rebuild when you change a file (keeps running)")
|
||||||
parser.add_argument(
|
parser.add_argument("--eslint",
|
||||||
"--eslint",
|
|
||||||
action="store_true",
|
action="store_true",
|
||||||
help="Run eslint on the JavaScript code to check for possible problems")
|
help="Run eslint on the JavaScript code to check for possible problems")
|
||||||
parser.add_argument("--eslint-fix",
|
parser.add_argument("--eslint-fix",
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"runtime"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/gochan-org/gochan/pkg/building"
|
"github.com/gochan-org/gochan/pkg/building"
|
||||||
|
@ -43,9 +45,19 @@ func main() {
|
||||||
}()
|
}()
|
||||||
err := config.InitConfig()
|
err := config.InitConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fatalEv.Err(err).Caller().
|
msg := "Unable to load configuration"
|
||||||
Str("jsonLocation", config.JSONLocation()).
|
if errors.Is(err, config.ErrGochanConfigNotFound) {
|
||||||
Msg("Unable to load configuration")
|
msg += ", run gochan-install to generate a new configuration file, or copy gochan.example.json to "
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
msg += "the current directory"
|
||||||
|
} else {
|
||||||
|
msg += "one of the search paths"
|
||||||
|
}
|
||||||
|
msg += " and rename it to gochan.json"
|
||||||
|
}
|
||||||
|
fatalEv.Err(err).Caller()
|
||||||
|
gcutil.LogArray("searchPaths", config.StandardConfigSearchPaths, fatalEv)
|
||||||
|
fatalEv.Msg(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
uid, gid := config.GetUser()
|
uid, gid := config.GetUser()
|
||||||
|
|
|
@ -31,10 +31,10 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
uid int
|
uid int
|
||||||
gid int
|
gid int
|
||||||
|
ErrGochanConfigNotFound = errors.New("gochan.json not found")
|
||||||
initialSetupStatus InitialSetupStatus = InitialSetupStatusUnknown
|
initialSetupStatus InitialSetupStatus = InitialSetupStatusUnknown
|
||||||
)
|
)
|
||||||
|
|
||||||
// MissingField represents a field missing from the configuration file
|
// MissingField represents a field missing from the configuration file
|
||||||
|
@ -143,7 +143,7 @@ func loadConfig() (err error) {
|
||||||
}
|
}
|
||||||
cfgPath = gcutil.FindResource(StandardConfigSearchPaths...)
|
cfgPath = gcutil.FindResource(StandardConfigSearchPaths...)
|
||||||
if cfgPath == "" {
|
if cfgPath == "" {
|
||||||
return errors.New("gochan.json not found")
|
return ErrGochanConfigNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
cfgBytes, err := os.ReadFile(cfgPath)
|
cfgBytes, err := os.ReadFile(cfgPath)
|
||||||
|
|
|
@ -103,27 +103,27 @@ systemctl enable nginx
|
||||||
systemctl restart nginx &
|
systemctl restart nginx &
|
||||||
wait
|
wait
|
||||||
|
|
||||||
mkdir -p /etc/gochan
|
# mkdir -p /etc/gochan
|
||||||
cp /vagrant/examples/configs/gochan.example.json /vagrant/gochan.json
|
# cp /vagrant/examples/configs/gochan.example.json /vagrant/gochan.json
|
||||||
ln -s /vagrant/gochan.json /etc/gochan/gochan.json
|
# ln -s /vagrant/gochan.json /etc/gochan/gochan.json
|
||||||
sed -i /vagrant/gochan.json \
|
# sed -i /vagrant/gochan.json \
|
||||||
-e 's/"Port": 8080/"Port": 9000/' \
|
# -e 's/"Port": 8080/"Port": 9000/' \
|
||||||
-e 's/"UseFastCGI": false/"UseFastCGI": true/' \
|
# -e 's/"UseFastCGI": false/"UseFastCGI": true/' \
|
||||||
-e 's#"DocumentRoot": "html"#"DocumentRoot": "/srv/gochan"#' \
|
# -e 's#"DocumentRoot": "html"#"DocumentRoot": "/srv/gochan"#' \
|
||||||
-e 's#"TemplateDir": "templates"#"TemplateDir": "/usr/share/gochan/templates"#' \
|
# -e 's#"TemplateDir": "templates"#"TemplateDir": "/usr/share/gochan/templates"#' \
|
||||||
-e 's#"LogDir": "log"#"LogDir": "/var/log/gochan"#' \
|
# -e 's#"LogDir": "log"#"LogDir": "/var/log/gochan"#' \
|
||||||
-e "s/\"DBtype\": .*/\"DBtype\": \"$DBTYPE\",/" \
|
# -e "s/\"DBtype\": .*/\"DBtype\": \"$DBTYPE\",/" \
|
||||||
-e 's/"SiteHost": .*/"SiteHost": "192.168.56.3",/' \
|
# -e 's/"SiteHost": .*/"SiteHost": "192.168.56.3",/' \
|
||||||
-e 's/"DBpassword": .*/"DBpassword": "gochan",/' \
|
# -e 's/"DBpassword": .*/"DBpassword": "gochan",/' \
|
||||||
-e 's/"Verbosity": 0/"Verbosity": 1/'
|
# -e 's/"Verbosity": 0/"Verbosity": 1/'
|
||||||
|
|
||||||
if [ "$DBTYPE" = "postgresql" ]; then
|
# if [ "$DBTYPE" = "postgresql" ]; then
|
||||||
sed -i /etc/gochan/gochan.json \
|
# sed -i /etc/gochan/gochan.json \
|
||||||
-e 's/"DBhost": ".*"/"DBhost": "127.0.0.1"/'
|
# -e 's/"DBhost": ".*"/"DBhost": "127.0.0.1"/'
|
||||||
elif [ "$DBTYPE" = "sqlite3" ]; then
|
# elif [ "$DBTYPE" = "sqlite3" ]; then
|
||||||
sed -i /etc/gochan/gochan.json \
|
# sed -i /etc/gochan/gochan.json \
|
||||||
-e 's#"DBhost": ".*"#"DBhost": "/etc/gochan/gochan.db"#'
|
# -e 's#"DBhost": ".*"#"DBhost": "/etc/gochan/gochan.db"#'
|
||||||
fi
|
# fi
|
||||||
|
|
||||||
# a convenient script for connecting to the db, whichever type we're using
|
# a convenient script for connecting to the db, whichever type we're using
|
||||||
ln -s {/vagrant/tools,/home/vagrant}/dbconnect.sh
|
ln -s {/vagrant/tools,/home/vagrant}/dbconnect.sh
|
||||||
|
@ -146,7 +146,7 @@ npm install -g npm@latest
|
||||||
|
|
||||||
su - vagrant <<EOF
|
su - vagrant <<EOF
|
||||||
echo 'alias bbig="cd /vagrant && ./build.py && sudo ./build.py install && sudo -E ./gochan"' >> /home/vagrant/.bash_aliases
|
echo 'alias bbig="cd /vagrant && ./build.py && sudo ./build.py install && sudo -E ./gochan"' >> /home/vagrant/.bash_aliases
|
||||||
echo 'alias bbigi="cd /vagrant && ./build.py && sudo ./build.py install && sudo -E ./gochan-installer -template-dir /usr/share/gochan/templates/ -port 9000 -document-root /srv/gochan -fastcgi"' >> /home/vagrant/.bash_aliases
|
echo 'alias bbigi="cd /vagrant && ./build.py && sudo ./build.py install && sudo -E ./gochan-installer -template-dir /usr/share/gochan/templates/ -port 9000 -site-host 192.168.56.3 -document-root /srv/gochan -fastcgi"' >> /home/vagrant/.bash_aliases
|
||||||
mkdir -p /home/vagrant/go
|
mkdir -p /home/vagrant/go
|
||||||
source /home/vagrant/.bashrc
|
source /home/vagrant/.bashrc
|
||||||
cd /vagrant
|
cd /vagrant
|
||||||
|
@ -169,8 +169,10 @@ cat - <<EOF
|
||||||
Server set up. To access the virtual machine, run 'vagrant ssh'.
|
Server set up. To access the virtual machine, run 'vagrant ssh'.
|
||||||
To start the gochan server, run 'sudo systemctl start gochan.service'.
|
To start the gochan server, run 'sudo systemctl start gochan.service'.
|
||||||
To have gochan run at startup, run 'sudo systemctl enable gochan.service'
|
To have gochan run at startup, run 'sudo systemctl enable gochan.service'
|
||||||
|
To run the gochan installer, run gochan-installer -template-dir /usr/share/gochan/templates/ -port 9000 -document-root /srv/gochan -fastcgi
|
||||||
|
You can access the installer from a browser at http://192.168.56.3/install/
|
||||||
|
|
||||||
You can access it from a browser at http://192.168.56.3/
|
After the installer is done, you can run gochan and access it at http://192.168.56.3/
|
||||||
The first time gochan is run, it will create a simple /test/ board.
|
The first time gochan is run, it will create a simple /test/ board.
|
||||||
|
|
||||||
If you want to do frontend development, see frontend/README.md
|
If you want to do frontend development, see frontend/README.md
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue