Skip to content

Commit

Permalink
修正安装脚本,添加危险权限提示。添加时间检查,避免copyright故障
Browse files Browse the repository at this point in the history
  • Loading branch information
qwe7002 committed Oct 11, 2018
1 parent 51736a5 commit 48f7768
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -20,7 +20,7 @@ SilverBlog is a lightweight blog project based on Python3.
* Has Android, IOS, WEB client.
* Full [GitHub Flavored Markdown](https://guides.github.com/features/mastering-markdown/) support

## how to install
## How to install
We support `freebsd`,`debian(ubuntu)`, `fedora`, `alpine`, `arch linux` for direct deployment. For other systems, please use Docker deployment.
You can install SilverBlog directly using the installation script:

Expand Down Expand Up @@ -66,7 +66,7 @@ This installation script uses the nginx + uwsgi execution mode by default. You c

[wiki](https://github.com/SilverBlogTeam/silverblog/wiki)

## start operation
## Start operation

You can run SilverBlog using tools such as Tmux or Screen. You just need to execute `python3 watch.py` to open your blog.

Expand Down
12 changes: 12 additions & 0 deletions common/install_module.py
Expand Up @@ -26,3 +26,15 @@ def install_package(package):
install_command.append("--user")
install_command.append(package)
main(install_command)


def uninstall_package(package):
try:
from pip._internal import main
except Exception:
from pip import main
install_command = ['uninstall']
if os.geteuid() != 0:
install_command.append("--user")
install_command.append(package)
main(install_command)
15 changes: 14 additions & 1 deletion init.py
@@ -1,6 +1,7 @@
import asyncio
import json
import os.path
import time

from flask import Flask, abort, redirect

Expand All @@ -15,7 +16,7 @@
cache_index = dict()
cache_post = dict()
i18n = dict()

last_build_year = time.localtime(time.time())[0]
@asyncio.coroutine
def async_json_loads(text):
return json.loads(text)
Expand Down Expand Up @@ -106,6 +107,12 @@ def redirect_301(file_name, page_index=1):
@app.route('/index/<int:page_index>', strict_slashes=False)
def index_route(page_index=1):
page_url = "/index/{0}/".format(page_index)
localtime = time.localtime(time.time())
if last_build_year != localtime[0]:
global last_build_year
last_build_year = localtime[0]
cache_index.clear()
cache_post.clear()
if page_url in cache_index:
console.log("info", "Get cache Success: {0}".format(page_url))
return cache_index[page_url]
Expand All @@ -131,6 +138,12 @@ def post_route(file_name=None):
if file_name is None or not os.path.exists("./document/{0}.md".format(file_name)):
abort(404)
page_url = "/post/{0}/".format(file_name)
localtime = time.localtime(time.time())
if last_build_year != localtime[0]:
global last_build_year
last_build_year = localtime[0]
cache_index.clear()
cache_post.clear()
if page_url in cache_post:
console.log("info", "Get cache Success: {0}".format(page_url))
return cache_post[page_url]
Expand Down
8 changes: 7 additions & 1 deletion install/docker_install.sh
Expand Up @@ -4,7 +4,12 @@ if test $(ps h -o comm -p $$) = "sh"; then
echo "Please use bash to execute this script."
exit 1
fi

if [ $UID -eq 0 ]; then
read -p "Running this script as root can damage your system. Continue to execute? (y/N) :" yn
if [ "$yn" != "Y" ] || [ "$yn" != "y" ]; then
exit 0
fi
fi
china_install=false
install_name="silverblog"

Expand Down Expand Up @@ -71,6 +76,7 @@ cat << EOF > docker-compose.yml
version: '3'
services:
${install_name}:
user: user_docker
image: "${docker_image}"
container_name: "${install_name}"
restart: on-failure:10
Expand Down
4 changes: 2 additions & 2 deletions install/install.sh
Expand Up @@ -133,7 +133,7 @@ fi

cd ..

read -p "Create a pm2 configuration file? (Y/N) :" yn
read -p "Create a pm2 configuration file? (y/N) :" yn

if [ "$yn" == "Y" ] || [ "$yn" == "y" ]; then
cat << EOF >pm2.json
Expand Down Expand Up @@ -161,7 +161,7 @@ cat << EOF >pm2.json
EOF
fi
if [ "$yn" != "Y" ] || [ "$yn" != "y" ]; then
read -p "Create a supervisord configuration file? (Y/N) :" yn
read -p "Create a supervisord configuration file? (y/N) :" yn
if [ "$yn" == "Y" ] || [ "$yn" == "y" ]; then
cat << EOF >supervisord.conf
[program:${install_name}-main]
Expand Down
4 changes: 4 additions & 0 deletions manage/theme.py
Expand Up @@ -26,6 +26,10 @@ def get_local_theme_list():
def install_theme(name, custom):
if not os.path.exists("./templates/static"):
os.mkdir("./templates/static")
if os.geteuid() == 0:
running_in_root = input('Running this script as root can damage your system. Continue to execute? [y/N]')
if running_in_root.lower() != 'y':
exit(0)
console.log("info", "Getting the theme installation script...")
install_script_url = "https://raw.githubusercontent.com/silverblogtheme/{}/master/install.sh".format(name)
if custom:
Expand Down
2 changes: 1 addition & 1 deletion upgrade/upgrade_from_2.py
Expand Up @@ -4,7 +4,7 @@

os.system("cd ./install && bash install_python_dependency.sh")
uninstall_dependency = input('Do you want to uninstall pypinyin now? [y/N]')
if uninstall_dependency.lower() == 'yes' or uninstall_dependency.lower() == 'y':
if uninstall_dependency.lower() == 'y':
os.system("sudo python3 -m pip uninstall pypinyin")
print("We modified the startup script, please redeploy the startup script.")
print("The template format has been modified. Please upgrade the template.")

0 comments on commit 48f7768

Please sign in to comment.