Use runit instead of init for important services, drop users and groups

using separate user/group for octoprint turned to be a major PITA - when
you tried to make a backup of the octoprint configuration via the
octoprint UI, it seems that it was trying to move the whole
/var/lib/octoprint directory which of course did not work due to
permissions.

Anyway, this is not a multiuser/multipurpose server, not worth to
mess around with users.

There is one user which can be used to log in and su to root:
login: printer
password: printer

Same credentials are set for the web server.

Octoprint sits behind lighttpd, i.e. https://ip/octoprint/ will
internally proxy to the octoprint server which only listens on localhost.

TODO:
* do not start klipper/octoprint by default yet, the web UI should
  guide the user through an initial setup; octoprint should be optional
  anyway.

* root ssh login will be disabled later

* first time dhparam key generation takes way too long

* web UI config wizard

* build MCU firmware
This commit is contained in:
Sergey 'Jin' Bostandzhyan
2020-06-21 22:32:01 +02:00
parent 08b25c9cdb
commit 94108a7ef1
27 changed files with 1030 additions and 328 deletions

View File

@@ -1,6 +1,8 @@
DISTRO = "klipper-linux"
MACHINE = "tinker-board-s"
#BBMULTICONFIG = "avr"
PRSERV_HOST = "localhost:0"
PACKAGE_CLASSES = " package_ipk "

View File

@@ -31,7 +31,8 @@
RUNIT_SERVICE_PN ?= "${PN}"
RUNIT_SERVICE_AUTOSTART ?= "1"
RUNIT_SERVICE_DIR ?= "/var/service"
RDEPENDS_${PN}_append = "busybox busybox-runit"
runit_service_prerm() {
@@ -47,19 +48,14 @@ if [ "x$D" = "x" ]; then
fi # live image check
}
runit_service_postinst() {
if [ "x$D" = "x" ]; then
runit_service_postinst_ontarget() {
# only link when autostart is true, but otherwise do not modify existing
# rootfs configuration, i.e. dont force disable
if [ "${RUNIT_SERVICE_AUTOSTART}" -eq "1" ]; then
if [ -d "/etc/runit/${RUNIT_SERVICE_NAME}" ] && [ ! -f "/etc/runit/${RUNIT_SERVICE_NAME}/down" ]; then
# If the logging service has been reconfigured, it must be restarted
# as well. Restarting(sv restart) the service alone does not help.
# The easiest way is to shutdown the runsv which terminates all it's
# children, then let runsvdir restart it automatically
sv force-shutdown /etc/runit/${RUNIT_SERVICE_NAME} || true
fi # service "down" file
fi # autostart service?
fi # live image check
if [ -d "/etc/runit/${RUNIT_SERVICE_NAME}" ] && [ ! -L "${RUNIT_SERVICE_DIR}/${RUNIT_SERVICE_NAME}" ]; then
ln -s "/etc/runit/${RUNIT_SERVICE_NAME}" "${RUNIT_SERVICE_DIR}/${RUNIT_SERVICE_NAME}"
fi
fi
}
runit_service_postrm() {
@@ -82,7 +78,7 @@ python __anonymous() {
PACKAGESPLITFUNCS_prepend = "populate_packages_runit_service "
populate_packages_runit_service[vardeps] += "runit_service_prerm runit_service_postinst runit_service_postrm"
populate_packages_runit_service[vardeps] += "runit_service_prerm runit_service_postinst_ontarget runit_service_postrm"
python populate_packages_runit_service() {
def runit_service(pkg, service):
@@ -90,11 +86,11 @@ python populate_packages_runit_service() {
localdata.setVar("RUNIT_SERVICE_NAME", service)
bb.data.update_data(localdata)
postinst = d.getVar('pkg_postinst_%s' % pkg, True)
postinst = d.getVar('pkg_postinst_ontarget_%s' % pkg, True)
if not postinst:
postinst = '#!/bin/sh\n'
postinst += localdata.getVar('runit_service_postinst', True)
d.setVar('pkg_postinst_%s' % pkg, postinst)
postinst += localdata.getVar('runit_service_postinst_ontarget', True)
d.setVar('pkg_postinst_ontarget_%s' % pkg, postinst)
prerm = d.getVar('pkg_prerm_%s' % pkg, True)
if not prerm:

View File

@@ -1,3 +1,19 @@
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
SRC_URI += "file://tunegroups.cfg"
SRC_URI += "\
file://runit.cfg \
file://runit.init \
"
PACKAGES =+ "${PN}-runit"
INITSCRIPT_PACKAGES += "${PN}-runit"
FILES_${PN}-runit = "${sysconfdir}/init.d/runit"
INITSCRIPT_NAME_${PN}-runit = "runit"
INITSCRIPT_PARAMS_${PN}-runit = "defaults 80"
do_install_append() {
install -d ${D}${localstatedir}/service
install -d ${D}${sysconfdir}/init.d
install ${WORKDIR}/runit.init ${D}${sysconfdir}/init.d/runit
}

View File

@@ -0,0 +1,6 @@
# Runit Utilities
#
CONFIG_RUNSV=y
CONFIG_RUNSVDIR=y
CONFIG_SV=y
CONFIG_SV_DEFAULT_SERVICE_DIR="/var/service"

View File

@@ -0,0 +1,55 @@
#!/bin/sh
# Imported from:
# https://git.digitalstrom.org/dss-oe/dss-oe/blob/master/yocto/dS/meta-digitalstrom-devel/recipes-core/runit/files/runit.sh
# License: MIT
NAME="runsvdir"
DESC="runit service supervisor"
DAEMON=runsvdir
case "$1" in
start)
if [ ! -d /etc/runit ]; then
mkdir -p /etc/runit
fi
echo "Stopping running services..."
for i in $(ls /etc/runit)
do
if [[ -f "/etc/runit/$i/supervise/stat" ]]; then
if [[ "`cat /etc/runit/$i/supervise/stat`" == "run" ]]; then
echo "Stopping $i..."
sv force-stop $i
fi
fi
done
RUNSV_PROCS=$(pidof runsv)
if [ $? -eq 0 ]; then
kill $RUNSV_PROCS
fi
echo -n "Starting $DESC: "
if ! start-stop-daemon --oknodo --start --background --exec $DAEMON -- /etc/runit 'log: ...........................................................................................................................................................................................................................................................................................................................................................................................................' ; then
echo "failed."
exit 1
fi
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
RUNSV_PROCS=$(pidof runsv)
if [ $? -eq 0 ]; then
kill $RUNSV_PROCS
fi
start-stop-daemon --oknodo --stop --exec $DAEMON
echo "$NAME."
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart}" >&2
exit 1
;;
esac
exit 0

View File

@@ -1,3 +0,0 @@
CONFIG_FEATURE_ADDUSER_TO_GROUP=y
CONFIG_FEATURE_CHECK_NAMES=y
CONFIG_FEATURE_DEL_USER_FROM_GROUP=y

View File

@@ -12,8 +12,7 @@ IMAGE_ROOTFS_EXTRA_SPACE = "204800"
inherit extrausers
EXTRA_USERS_PARAMS = "\
useradd -p \$6\$75uXvknClpLLmi\$SaSiPB9qALjsPn3W43Kn7rtAcW9Gz/fqKJYzAiGBestRPR8t8NyBUvC8OO49T61usTCQZgkDqBfh3GGApWuLP0 printer ; \
usermod -a -G klipper,octoprint printer ; \
useradd -p \$6\$75uXvknClpLLmi\$SaSiPB9qALjsPn3W43Kn7rtAcW9Gz/fqKJYzAiGBestRPR8t8NyBUvC8OO49T61usTCQZgkDqBfh3GGApWuLP0 klipper ; \
"
create_extlinux_config() {

View File

@@ -11,4 +11,18 @@ RDEPENDS_${PN} = "\
kernel-devicetree \
klipper \
octoprint \
lighttpd \
avahi-daemon \
avahi-autoipd \
tzdata \
tzdata-africa \
tzdata-americas \
tzdata-antarctica \
tzdata-antarctica \
tzdata-asia \
tzdata-atlantic \
tzdata-australia \
tzdata-europe \
tzdata-pacific \
ntp \
"

View File

@@ -0,0 +1,42 @@
From 22afc5d9aaa215c3c87ba21c77d47da44ab3b113 Mon Sep 17 00:00:00 2001
From: Alexander Kanavin <alex.kanavin@gmail.com>
Date: Fri, 26 Aug 2016 18:20:32 +0300
Subject: [PATCH] Use pkg-config for pcre dependency instead of -config script.
RP 2014/5/22
Upstream-Status: Pending
Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com>
---
configure.ac | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/configure.ac b/configure.ac
index 5383cec..c29a902 100644
--- a/configure.ac
+++ b/configure.ac
@@ -651,10 +651,18 @@ AC_ARG_WITH([pcre],
)
AC_MSG_RESULT([$WITH_PCRE])
-if test "$WITH_PCRE" != no; then
- if test "$WITH_PCRE" != yes; then
- PCRE_LIB="-L$WITH_PCRE/lib -lpcre"
- CPPFLAGS="$CPPFLAGS -I$WITH_PCRE/include"
+if test "$WITH_PCRE" != "no"; then
+ PKG_CHECK_MODULES(PCREPKG, [libpcre], [
+ PCRE_LIB=${PCREPKG_LIBS}
+ CPPFLAGS="$CPPFLAGS ${PCREPKG_CFLAGS}"
+ ], [
+ AC_MSG_ERROR([pcre pkgconfig not found, install the pcre-devel package or build with --without-pcre])
+ ])
+
+ if test x"$PCRE_LIB" != x; then
+ AC_DEFINE([HAVE_LIBPCRE], [1], [libpcre])
+ AC_DEFINE([HAVE_PCRE_H], [1], [pcre.h])
+ AC_SUBST(PCRE_LIB)
else
AC_PATH_PROG([PCRECONFIG], [pcre-config])
if test -n "$PCRECONFIG"; then
--
2.15.0

View File

@@ -0,0 +1,126 @@
#!/bin/sh
#
# htdigest.sh
# http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ModAuth
#
export PATH="/bin:/usr/bin:/usr/sbin:$PATH"
# when input ctrl-c, remove lockfile and exit
trap '[ $lockstart -eq 1 ] && unlock $pfile && exit 0 || exit 0' INT
pfile="/etc/lighttpd.user"
lockstart=0
remove=0
errmsg() {
echo "$1" 1>&2
}
user_check() {
check_user=$1
grep "^${check_user}:" ${pfile} >& /dev/null
return $?
}
lock() {
lockfile="$1"
lockfile="${lockfile}.lock"
[ -f "${lockfile}" ] && {
errmsg "WARNING: lock file ${lockfile} is already exists"
errmsg " Wait minites for end of previous working ..."
}
while [ -f "${lockfile}" ]; do echo >& /dev/null ; done
touch ${lockfile}
lockstart=1
}
unlock() {
lockfile="$1"
lockfile="${lockfile}.lock"
[ -f "${lockfile}" ] && rm -f ${lockfile} && lockstart=0
}
usage() {
errmsg
errmsg "lightdigest: lighttpd htdigest password generation program"
errmsg "Scripted by JoungKyun.Kim <http://oops.org>"
errmsg
errmsg "Usage: $0 -[hd] -u user -p pass -r realm [-f password_file]"
errmsg "Options:"
errmsg " -h print this help messages"
errmsg " -u user username"
errmsg " -p pass password"
errmsg " -r realm realm name"
errmsg " -f filename password file [default: /etc/lighttpd/conf.d/lighttpd.user]"
errmsg " -d remove user"
errmsg
[ $lockstart -eq 1 ] && rm -f ${pfile}.lock
exit 1
}
opts=$(getopt df:hp:r:u: $*)
[ $? != 0 ] && usage
set -- ${opts}
for i
do
case "$i" in
-d) remove=1; shift;;
-f) pfile="$2"; shift; shift;;
-p) pass="$2"; shift; shift;;
-r) realm="$2"; shift; shift;;
-u) user="$2"; shift; shift;;
--) shift; break;
esac
done
[ -z "$user" ] && errmsg "ERROR: User is none!!" && usage
[ ${remove} -eq 0 -a -z "${realm}" ] && errmsg "ERROR: Realm is none!!" && usage
if [ -z "${pass}" -a ${remove} -eq 0 ]; then
echo -n "Input new password : "
read newpass
echo -n "Reinput password for confirm : "
read renewpass
if [ "${newpass}" != "${renewpass}" ]; then
errmsg "ERROR: Password is not match"
exit 1
fi
pass=${newpass}
fi
lock ${pfile}
if [ ${remove} -eq 0 ]; then
# User Add Mode
hash=$(echo -n "${user}:${realm}:${pass}" | md5sum | cut -b -32)
user_check ${user}
already=$?
# [ -f "${pfile}" ] && cp -af ${pfile} ${pfile}.bak
if [ ${already} -eq 0 ]; then
# already exists
sed -i "s/^${user}:.*$/${user}:${realm}:${hash}/g" ${pfile}
else
# add new user
echo "${user}:${realm}:${hash}" >> ${pfile}
fi
else
echo "Removing..."
# User Remove Mode
tmp_htdigest="/tmp/lighttpd-htdiges.tmp.$$"
# cp -af ${pfile} ${pfile}.bak
grep -v "^${user}:" ${pfile} > ${tmp_htdigest}
mv -f ${tmp_htdigest} ${pfile}
fi
unlock ${pfile}
exit 0

View File

@@ -0,0 +1,145 @@
# lighttpd server configuration
server.modules = (
"mod_access",
"mod_accesslog",
"mod_auth",
"mod_cgi",
"mod_openssl",
"mod_proxy",
"mod_redirect",
"mod_setenv")
server.document-root = "/www/pages/"
server.errorlog = "/var/log/lighttpd/lighttpd.error.log"
index-file.names = ( "index.html" )
mimetype.assign = (
".pdf" => "application/pdf",
".sig" => "application/pgp-signature",
".spl" => "application/futuresplash",
".class" => "application/octet-stream",
".ps" => "application/postscript",
".torrent" => "application/x-bittorrent",
".dvi" => "application/x-dvi",
".gz" => "application/x-gzip",
".pac" => "application/x-ns-proxy-autoconfig",
".swf" => "application/x-shockwave-flash",
".tar.gz" => "application/x-tgz",
".tgz" => "application/x-tgz",
".zip" => "application/zip",
".mp3" => "audio/mpeg",
".m3u" => "audio/x-mpegurl",
".wma" => "audio/x-ms-wma",
".wax" => "audio/x-ms-wax",
".ogg" => "application/ogg",
".wav" => "audio/x-wav",
".gif" => "image/gif",
".jpg" => "image/jpeg",
".jpeg" => "image/jpeg",
".png" => "image/png",
".xbm" => "image/x-xbitmap",
".xpm" => "image/x-xpixmap",
".xwd" => "image/x-xwindowdump",
".css" => "text/css",
".html" => "text/html",
".htm" => "text/html",
".js" => "text/javascript",
".json" => "application/json",
".asc" => "text/plain",
".c" => "text/plain",
".cpp" => "text/plain",
".log" => "text/plain",
".conf" => "text/plain",
".text" => "text/plain",
".txt" => "text/plain",
".dtd" => "text/xml",
".xml" => "text/xml",
".mpeg" => "video/mpeg",
".mpg" => "video/mpeg",
".mov" => "video/quicktime",
".qt" => "video/quicktime",
".avi" => "video/x-msvideo",
".asf" => "video/x-ms-asf",
".asx" => "video/x-ms-asf",
".wmv" => "video/x-ms-wmv",
".bz2" => "application/x-bzip",
".tbz" => "application/x-bzip-compressed-tar",
".tar.bz2" => "application/x-bzip-compressed-tar",
".crt" => "application/x-x509-ca-cert"
)
accesslog.filename = "/var/log/lighttpd/lighttpd.access.log"
debug.log-request-handling = "disable"
## deny access the file-extensions
#
# ~ is for backupfiles from vi, emacs, joe, ...
# .inc is often used for code includes which should in general not be part
# of the document-root
url.access-deny = ( "~", ".inc" )
$HTTP["url"] =~ "\.pdf$" {
server.range-requests = "disable"
}
##
# which extensions should not be handle via static-file transfer
#
# .php, .pl, .fcgi are most often handled by mod_fastcgi or mod_cgi
static-file.exclude-extensions = ( ".sh" )
# always redirect to https
$SERVER["socket"] == ":80" {
$HTTP["remoteip"] != "127.0.0.1" {
$HTTP["host"] =~ "(.*)" {
url.redirect = ( "^/(.*)" => "https://%1/$1" )
}
}
}
#### CGI module
$HTTP["url"] =~ "^/cgi-bin/" {
# disable directory listings
dir-listing.activate = "disable"
# only allow cgi's in this directory
cgi.assign = ( ".sh" => "/bin/sh" )
}
#### use self signed certificate
ssl.engine = "enable"
ssl.pemfile = "/etc/ssl/certs/localcert.pem"
#### https://syslink.pl/cipherlist/
ssl.honor-cipher-order = "enable"
ssl.cipher-list = "EECDH+AESGCM:EDH+AESGCM"
ssl.dh-file = "/etc/lighttpd/dhparam.pem" # openssl dhparam -out /etc/lighttpd/dhparam.pem 4096
setenv.add-response-header = (
"Strict-Transport-Security" => "max-age=63072000; includeSubDomains; preload",
"X-Frame-Options" => "DENY",
"X-Content-Type-Options" => "nosniff"
)
ssl.use-sslv2 = "disable"
ssl.use-sslv3 = "disable"
ssl.openssl.ssl-conf-cmd = ("Protocol" => "-TLSv1.1, -TLSv1, -SSLv3") # v1.4.48 or up
ssl.ec-curve = "secp384r1"
#### auth
auth.backend = "htdigest"
auth.backend.htdigest.userfile = "/etc/lighttpd/lighttpd.user"
auth.require = (
"/" =>
(
"method" => "digest",
"realm" => "klipper",
"require" => "user=printer"
)
)
#### redirect to to octoprint
$HTTP["url"] =~ "^/octoprint/" {
proxy.server = ( "" => ( ( "host" => "127.0.0.1", "port" => 5000 ) ) )
setenv.add-request-header = ( "X-Script-Name" => "/octoprint/" )
}

View File

@@ -0,0 +1,8 @@
#!/bin/sh
CONFIG=/etc/lighttpd/lighttpd.conf
mkdir -p /var/log/lighttpd
mkdir -p /var/run/lighttpd
exec 2>&1
exec /usr/sbin/lighttpd -D -f $CONFIG

View File

@@ -0,0 +1 @@
printer:klipper:8e6fa75a2a3d867ffedbed31908ee5e8

View File

@@ -0,0 +1,101 @@
# recipe imported from Poky
SUMMARY = "Lightweight high-performance web server"
HOMEPAGE = "http://www.lighttpd.net/"
BUGTRACKER = "http://redmine.lighttpd.net/projects/lighttpd/issues"
LICENSE = "BSD-3-Clause"
LIC_FILES_CHKSUM = "file://COPYING;md5=e4dac5c6ab169aa212feb5028853a579"
SECTION = "net"
RDEPENDS_${PN} = "\
lighttpd-module-access \
lighttpd-module-accesslog \
lighttpd-module-auth \
lighttpd-module-authn-file \
lighttpd-module-cgi \
lighttpd-module-dirlisting \
lighttpd-module-indexfile \
lighttpd-module-openssl \
lighttpd-module-proxy \
lighttpd-module-redirect \
lighttpd-module-setenv \
lighttpd-module-staticfile \
create-certificate \
"
SRC_URI = "http://download.lighttpd.net/lighttpd/releases-1.4.x/lighttpd-${PV}.tar.xz \
file://lighttpd.conf \
file://htdigest.sh \
file://lighttpd.user \
file://lighttpd.run \
file://0001-Use-pkg-config-for-pcre-dependency-instead-of-config.patch \
"
SRC_URI[md5sum] = "be4bda2c28bcbdac6eb941528f6edf03"
SRC_URI[sha256sum] = "6a0b50e9c9d5cc3d9e48592315c25a2d645858f863e1ccd120507a30ce21e927"
PACKAGECONFIG = "openssl pcre zlib"
PACKAGECONFIG[ipv6] = "--enable-ipv6,--disable-ipv6"
PACKAGECONFIG[mmap] = "--enable-mmap,--disable-mmap"
PACKAGECONFIG[libev] = "--with-libev,--without-libev,libev"
PACKAGECONFIG[mysql] = "--with-mysql,--without-mysql,mariadb"
PACKAGECONFIG[ldap] = "--with-ldap,--without-ldap,openldap"
PACKAGECONFIG[attr] = "--with-attr,--without-attr,attr"
PACKAGECONFIG[valgrind] = "--with-valgrind,--without-valgrind,valgrind"
PACKAGECONFIG[openssl] = "--with-openssl,--without-openssl,openssl"
PACKAGECONFIG[krb5] = "--with-krb5,--without-krb5,krb5"
PACKAGECONFIG[pcre] = "--with-pcre,--without-pcre,libpcre"
PACKAGECONFIG[zlib] = "--with-zlib,--without-zlib,zlib"
PACKAGECONFIG[bzip2] = "--with-bzip2,--without-bzip2,bzip2"
PACKAGECONFIG[webdav-props] = "--with-webdav-props,--without-webdav-props,libxml2 sqlite3"
PACKAGECONFIG[webdav-locks] = "--with-webdav-locks,--without-webdav-locks,util-linux"
PACKAGECONFIG[gdbm] = "--with-gdbm,--without-gdbm,gdbm"
PACKAGECONFIG[memcache] = "--with-memcached,--without-memcached,libmemcached"
PACKAGECONFIG[lua] = "--with-lua,--without-lua,lua"
EXTRA_OECONF += "--enable-lfs --without-fam"
inherit autotools pkgconfig gettext runit-service
RUNIT_SERVICES = "lighttpd"
RUNIT_PACKAGES = "lighttpd"
do_install_append() {
install -d ${D}${sysconfdir}/runit/lighttpd ${D}${sysconfdir}/lighttpd
install -d ${D}${sysconfdir}/lighttpd.d ${D}/www/pages/
install -d ${D}${bindir}
install -m 0755 ${WORKDIR}/lighttpd.run ${D}${sysconfdir}/runit/lighttpd/run
install -m 0644 ${WORKDIR}/lighttpd.conf ${D}${sysconfdir}/lighttpd
#For FHS compliance, create symbolic links to /var/log and /var/tmp for logs and temporary data
ln -sf ${localstatedir}/log ${D}/www/logs
ln -sf ${localstatedir}/tmp ${D}/www/var
install -m 0755 -d ${D}${bindir}
install -m 0755 -d ${D}/www/pages
install -m 0644 ${WORKDIR}/lighttpd.user ${D}${sysconfdir}/lighttpd/lighttpd.user
install -m 0755 ${WORKDIR}/htdigest.sh ${D}${bindir}/htdigest.sh
}
FILES_${PN} += "${sysconfdir} /www"
CONFFILES_${PN} = "${sysconfdir}/lighttpd/lighttpd.user"
PACKAGES_DYNAMIC += "^lighttpd-module-.*"
python populate_packages_prepend () {
lighttpd_libdir = d.expand('${libdir}')
do_split_packages(d, lighttpd_libdir, r'^mod_(.*)\.so$', 'lighttpd-module-%s', 'Lighttpd module for %s', extra_depends='')
}
pkg_postinst_ontarget_${PN}() {
#!/bin/sh
if [ ! -s /etc/lighttpd/dhparam.pem ]; then
openssl dhparam -out /etc/lighttpd/dhparam.pem 4096
fi
}

View File

@@ -0,0 +1,430 @@
From a0f142543f907f0f65a19f6d0df217a526ebda57 Mon Sep 17 00:00:00 2001
From: Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>
Date: Sun, 21 Jun 2020 02:38:00 +0200
Subject: [PATCH] Use setuptools for packaging
This allows to cross compile the C parts of klippy, instead of being
forced to build it directly on the target.
---
MANIFEST.in | 2 ++
klippy/__init__.py | 5 +++++
klippy/chelper/__init__.py | 19 +------------------
klippy/extras/bed_screws.py | 2 +-
klippy/extras/bed_tilt.py | 2 +-
klippy/extras/bltouch.py | 2 +-
klippy/extras/bus.py | 2 +-
klippy/extras/delta_calibrate.py | 2 +-
klippy/extras/extruder_stepper.py | 2 +-
klippy/extras/force_move.py | 2 +-
klippy/extras/manual_probe.py | 2 +-
klippy/extras/manual_stepper.py | 2 +-
klippy/extras/probe.py | 2 +-
klippy/extras/replicape.py | 2 +-
klippy/extras/sx1509.py | 2 +-
klippy/extras/z_tilt.py | 2 +-
klippy/kinematics/cartesian.py | 2 +-
klippy/kinematics/corexy.py | 2 +-
klippy/kinematics/delta.py | 2 +-
klippy/kinematics/extruder.py | 2 +-
klippy/kinematics/polar.py | 2 +-
klippy/kinematics/rotary_delta.py | 2 +-
klippy/kinematics/winch.py | 2 +-
klippy/klippy.py | 2 +-
klippy/toolhead.py | 2 +-
setup.py | 29 +++++++++++++++++++++++++++++
26 files changed, 59 insertions(+), 40 deletions(-)
create mode 100644 MANIFEST.in
create mode 100644 klippy/__init__.py
create mode 100644 setup.py
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 00000000..8e306491
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,2 @@
+include klippy/extras/display/menu.cfg
+include klippy/extras/display/display.cfg
diff --git a/klippy/__init__.py b/klippy/__init__.py
new file mode 100644
index 00000000..bd206ac5
--- /dev/null
+++ b/klippy/__init__.py
@@ -0,0 +1,5 @@
+# Package definition for the extras directory
+#
+# Copyright (C) 2018 Kevin O'Connor <kevin@koconnor.net>
+#
+# This file may be distributed under the terms of the GNU GPLv3 license.
diff --git a/klippy/chelper/__init__.py b/klippy/chelper/__init__.py
index 1a4b2d74..63f1ba07 100644
--- a/klippy/chelper/__init__.py
+++ b/klippy/chelper/__init__.py
@@ -162,20 +162,6 @@ def get_mtimes(srcdir, filelist):
out.append(t)
return out
-# Check if the code needs to be compiled
-def check_build_code(srcdir, target, sources, cmd, other_files=[]):
- src_times = get_mtimes(srcdir, sources + other_files)
- obj_times = get_mtimes(srcdir, [target])
- if not obj_times or max(src_times) > min(obj_times):
- logging.info("Building C code module %s", target)
- srcfiles = [os.path.join(srcdir, fname) for fname in sources]
- destlib = os.path.join(srcdir, target)
- res = os.system(cmd % (destlib, ' '.join(srcfiles)))
- if res:
- msg = "Unable to build C code module (error=%s)" % (res,)
- logging.error(msg)
- raise Exception(msg)
-
FFI_main = None
FFI_lib = None
pyhelper_logging_callback = None
@@ -185,8 +171,6 @@ def get_ffi():
global FFI_main, FFI_lib, pyhelper_logging_callback
if FFI_lib is None:
srcdir = os.path.dirname(os.path.realpath(__file__))
- check_build_code(srcdir, DEST_LIB, SOURCE_FILES, COMPILE_CMD
- , OTHER_FILES)
FFI_main = cffi.FFI()
for d in defs_all:
FFI_main.cdef(d)
@@ -208,12 +192,11 @@ HC_COMPILE_CMD = "gcc -Wall -g -O2 -o %s %s -lusb"
HC_SOURCE_FILES = ['hub-ctrl.c']
HC_SOURCE_DIR = '../../lib/hub-ctrl'
HC_TARGET = "hub-ctrl"
-HC_CMD = "sudo %s/hub-ctrl -h 0 -P 2 -p %d"
+HC_CMD = "hub-ctrl -h 0 -P 2 -p %d"
def run_hub_ctrl(enable_power):
srcdir = os.path.dirname(os.path.realpath(__file__))
hubdir = os.path.join(srcdir, HC_SOURCE_DIR)
- check_build_code(hubdir, HC_TARGET, HC_SOURCE_FILES, HC_COMPILE_CMD)
os.system(HC_CMD % (hubdir, enable_power))
diff --git a/klippy/extras/bed_screws.py b/klippy/extras/bed_screws.py
index c10a791f..ee5a13ca 100644
--- a/klippy/extras/bed_screws.py
+++ b/klippy/extras/bed_screws.py
@@ -3,7 +3,7 @@
# Copyright (C) 2019 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
-import homing
+from klippy import homing
def parse_coord(config, param):
pair = config.get(param).strip().split(',', 1)
diff --git a/klippy/extras/bed_tilt.py b/klippy/extras/bed_tilt.py
index dd75655a..83b65908 100644
--- a/klippy/extras/bed_tilt.py
+++ b/klippy/extras/bed_tilt.py
@@ -4,7 +4,7 @@
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import logging
-import mathutil
+from klippy import mathutil
from . import probe
class BedTilt:
diff --git a/klippy/extras/bltouch.py b/klippy/extras/bltouch.py
index 50e27e0e..ba0beb7d 100644
--- a/klippy/extras/bltouch.py
+++ b/klippy/extras/bltouch.py
@@ -4,7 +4,7 @@
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import logging
-import homing
+from klippy import homing
from . import probe
SIGNAL_PERIOD = 0.020
diff --git a/klippy/extras/bus.py b/klippy/extras/bus.py
index 7c6ae440..91c84a4e 100644
--- a/klippy/extras/bus.py
+++ b/klippy/extras/bus.py
@@ -3,7 +3,7 @@
# Copyright (C) 2018,2019 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
-import mcu
+from klippy import mcu
def resolve_bus_name(mcu, param, bus):
# Find enumerations for the given bus
diff --git a/klippy/extras/delta_calibrate.py b/klippy/extras/delta_calibrate.py
index c927eb5e..c7f252a2 100644
--- a/klippy/extras/delta_calibrate.py
+++ b/klippy/extras/delta_calibrate.py
@@ -4,7 +4,7 @@
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import math, logging, collections
-import mathutil
+from klippy import mathutil
from . import probe
# A "stable position" is a 3-tuple containing the number of steps
diff --git a/klippy/extras/extruder_stepper.py b/klippy/extras/extruder_stepper.py
index 9678472a..a05fc91b 100644
--- a/klippy/extras/extruder_stepper.py
+++ b/klippy/extras/extruder_stepper.py
@@ -4,7 +4,7 @@
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import logging
-import stepper
+from klippy import stepper
class ExtruderStepper:
def __init__(self, config):
diff --git a/klippy/extras/force_move.py b/klippy/extras/force_move.py
index 647b0b33..b2247833 100644
--- a/klippy/extras/force_move.py
+++ b/klippy/extras/force_move.py
@@ -4,7 +4,7 @@
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import math, logging
-import chelper
+from klippy import chelper
BUZZ_DISTANCE = 1.
BUZZ_VELOCITY = BUZZ_DISTANCE / .250
diff --git a/klippy/extras/manual_probe.py b/klippy/extras/manual_probe.py
index 663f3c8e..f696a0ae 100644
--- a/klippy/extras/manual_probe.py
+++ b/klippy/extras/manual_probe.py
@@ -4,7 +4,7 @@
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import logging, bisect
-import homing
+from klippy import homing
class ManualProbe:
def __init__(self, config):
diff --git a/klippy/extras/manual_stepper.py b/klippy/extras/manual_stepper.py
index 5807c04c..965dcbf2 100644
--- a/klippy/extras/manual_stepper.py
+++ b/klippy/extras/manual_stepper.py
@@ -3,7 +3,7 @@
# Copyright (C) 2019 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
-import stepper, homing, chelper
+from klippy import stepper, homing, chelper
from . import force_move
ENDSTOP_SAMPLE_TIME = .000015
diff --git a/klippy/extras/probe.py b/klippy/extras/probe.py
index 02d1b5b9..b60f9271 100644
--- a/klippy/extras/probe.py
+++ b/klippy/extras/probe.py
@@ -4,7 +4,7 @@
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import logging
-import pins, homing
+from klippy import pins, homing
from . import manual_probe
HINT_TIMEOUT = """
diff --git a/klippy/extras/replicape.py b/klippy/extras/replicape.py
index 9236264f..26d37069 100644
--- a/klippy/extras/replicape.py
+++ b/klippy/extras/replicape.py
@@ -4,7 +4,7 @@
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import logging, os
-import pins, mcu
+from klippy import pins, mcu
from . import bus
REPLICAPE_MAX_CURRENT = 3.84
diff --git a/klippy/extras/sx1509.py b/klippy/extras/sx1509.py
index 7a4f24db..475857d9 100644
--- a/klippy/extras/sx1509.py
+++ b/klippy/extras/sx1509.py
@@ -3,7 +3,7 @@
# Copyright (C) 2018 Florian Heilmann <Florian.Heilmann@gmx.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
-import pins
+from klippy import pins
from . import bus
# Word registers
diff --git a/klippy/extras/z_tilt.py b/klippy/extras/z_tilt.py
index 577b7e70..8a49df47 100644
--- a/klippy/extras/z_tilt.py
+++ b/klippy/extras/z_tilt.py
@@ -4,7 +4,7 @@
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import logging
-import mathutil
+from klippy import mathutil
from . import probe
class ZAdjustHelper:
diff --git a/klippy/kinematics/cartesian.py b/klippy/kinematics/cartesian.py
index df57edce..b400bd1d 100644
--- a/klippy/kinematics/cartesian.py
+++ b/klippy/kinematics/cartesian.py
@@ -4,7 +4,7 @@
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import logging
-import stepper, homing
+from klippy import stepper, homing
class CartKinematics:
def __init__(self, toolhead, config):
diff --git a/klippy/kinematics/corexy.py b/klippy/kinematics/corexy.py
index f04b3009..2da29c97 100644
--- a/klippy/kinematics/corexy.py
+++ b/klippy/kinematics/corexy.py
@@ -4,7 +4,7 @@
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import logging, math
-import stepper, homing
+from klippy import stepper, homing
class CoreXYKinematics:
def __init__(self, toolhead, config):
diff --git a/klippy/kinematics/delta.py b/klippy/kinematics/delta.py
index 885ce940..1c334547 100644
--- a/klippy/kinematics/delta.py
+++ b/klippy/kinematics/delta.py
@@ -4,7 +4,7 @@
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import math, logging
-import stepper, homing, mathutil
+from klippy import stepper, homing, mathutil
# Slow moves once the ratio of tower to XY movement exceeds SLOW_RATIO
SLOW_RATIO = 3.
diff --git a/klippy/kinematics/extruder.py b/klippy/kinematics/extruder.py
index 3a03b606..e36c02f1 100644
--- a/klippy/kinematics/extruder.py
+++ b/klippy/kinematics/extruder.py
@@ -4,7 +4,7 @@
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import math, logging
-import stepper, homing, chelper
+from klippy import stepper, homing, chelper
class PrinterExtruder:
def __init__(self, config, extruder_num):
diff --git a/klippy/kinematics/polar.py b/klippy/kinematics/polar.py
index e3ee3241..f2643552 100644
--- a/klippy/kinematics/polar.py
+++ b/klippy/kinematics/polar.py
@@ -4,7 +4,7 @@
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import logging, math
-import stepper, homing
+from klippy import stepper, homing
class PolarKinematics:
def __init__(self, toolhead, config):
diff --git a/klippy/kinematics/rotary_delta.py b/klippy/kinematics/rotary_delta.py
index 415a2e7f..ff62ba49 100644
--- a/klippy/kinematics/rotary_delta.py
+++ b/klippy/kinematics/rotary_delta.py
@@ -4,7 +4,7 @@
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import math, logging
-import stepper, homing, mathutil, chelper
+from klippy import stepper, homing, mathutil, chelper
class RotaryDeltaKinematics:
def __init__(self, toolhead, config):
diff --git a/klippy/kinematics/winch.py b/klippy/kinematics/winch.py
index 04e2d498..4de65d58 100644
--- a/klippy/kinematics/winch.py
+++ b/klippy/kinematics/winch.py
@@ -3,7 +3,7 @@
# Copyright (C) 2018-2019 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
-import stepper, mathutil
+from klippy import stepper, mathutil
class WinchKinematics:
def __init__(self, toolhead, config):
diff --git a/klippy/klippy.py b/klippy/klippy.py
index 84450aea..091dbc3c 100644
--- a/klippy/klippy.py
+++ b/klippy/klippy.py
@@ -106,7 +106,7 @@ class Printer:
if default is not configfile.sentinel:
return default
raise self.config_error("Unable to load module '%s'" % (section,))
- mod = importlib.import_module('extras.' + module_name)
+ mod = importlib.import_module('klippy.extras.' + module_name)
init_func = 'load_config'
if len(module_parts) > 1:
init_func = 'load_config_prefix'
diff --git a/klippy/toolhead.py b/klippy/toolhead.py
index 617186f6..d3e680d3 100644
--- a/klippy/toolhead.py
+++ b/klippy/toolhead.py
@@ -250,7 +250,7 @@ class ToolHead:
self.extruder = kinematics.extruder.DummyExtruder()
kin_name = config.get('kinematics')
try:
- mod = importlib.import_module('kinematics.' + kin_name)
+ mod = importlib.import_module('klippy.kinematics.' + kin_name)
self.kin = mod.load_kinematics(self, config)
except config.error as e:
raise
diff --git a/setup.py b/setup.py
new file mode 100644
index 00000000..8d407ace
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,29 @@
+from setuptools import setup, find_packages, Extension
+
+c_helper = Extension('klippy/chelper/c_helper',
+ define_macros = [('MAJOR_VERSION', '1'),
+ ('MINOR_VERSION', '0')],
+ sources = [ 'klippy/chelper/itersolve.c',
+ 'klippy/chelper/kin_cartesian.c',
+ 'klippy/chelper/kin_corexy.c',
+ 'klippy/chelper/kin_delta.c',
+ 'klippy/chelper/kin_extruder.c',
+ 'klippy/chelper/kin_polar.c',
+ 'klippy/chelper/kin_rotary_delta.c',
+ 'klippy/chelper/kin_winch.c',
+ 'klippy/chelper/pyhelper.c',
+ 'klippy/chelper/serialqueue.c',
+ 'klippy/chelper/stepcompress.c',
+ 'klippy/chelper/trapq.c' ])
+
+setup(
+ name = 'klipper',
+ version = '0.8.0+git',
+ description = 'Klipper 3D Printing Firmware',
+ packages=find_packages(),
+ include_package_data = True,
+ entry_points = { "console_scripts": [ "klippy = klippy.klippy:main" ] },
+ url = "https://www.klipper3d.org/",
+ ext_modules = [ c_helper ]
+)
+
--
2.25.4

View File

@@ -1,57 +0,0 @@
#!/bin/sh
# System startup script for Klipper 3d-printer host code
### BEGIN INIT INFO
# Provides: klipper
# Required-Start: $local_fs
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Klipper daemon
# Description: Starts the Klipper daemon.
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
DESC="klipper daemon"
NAME="klipper"
DEFAULTS_FILE=/etc/default/klipper
PIDFILE=/var/run/klipper.pid
LOGDIR=/var/log/klipper
mkdir -p $LOGDIR
chown -R klipper.klipper $LOGDIR
PRINTER_CONFIG="printer.cfg"
# Read defaults file
[ -r $DEFAULTS_FILE ] && . $DEFAULTS_FILE
case "$1" in
start) echo -n "Starting klipper" $NAME
start-stop-daemon --start --quiet --exec klippy \
--background --pidfile $PIDFILE --make-pidfile \
--chuid klipper:klipper \
-- /etc/klipper/$PRINTER_CONFIG -l /var/log/klipper.log
echo " $?"
;;
stop) echo -n "Stopping klipper" $NAME
if [ -s $PIDFILE ]; then
kill -INT $(cat $PIDFILE)
RETVAL=$?
[ $RETVAL -eq 0 ] && [ -e "$PIDFILE" ] && rm -f $PIDFILE
echo " $RETVAL"
fi
;;
restart) echo -n "Restarting klipper" $NAME
$0 stop
$0 start
;;
reload|force-reload)
echo -n "Reloading configuration not supported" $NAME
echo 1
;;
*) echo "Usage: /etc/init.d/klipper {start|stop|restart|reload|force-reload}"
exit 2
;;
esac
exit 0

View File

@@ -0,0 +1,30 @@
#!/bin/sh
DAEMON=/usr/bin/klippy
LOGDIR=/var/log/klipper
DEFAULTS_FILE=/etc/default/klipper
mkdir -p $LOGDIR
PRINTER_CONFIG_DIR="/etc/klipper"
mkdir -p $PRINTER_CONFIG_DIR
# Read defaults file
if [ -r $DEFAULTS_FILE ]; then
source $DEFAULTS_FILE
fi
PRINTER_CONFIG="$PRINTER_CONFIG_DIR/printer.cfg"
OPTIONS="$PRINTER_CONFIG -l $LOGDIR/klipper.log"
if [ ! -x $DAEMON ] || [ ! -s $PRINTER_CONFIG ]; then
echo "$0: $DAEMON or $PRINTER_CONFIG not found!"
sleep 10
exit 1
fi
exec 2>&1
exec $DAEMON $OPTIONS

View File

@@ -3,18 +3,16 @@ HOMEPAGE = "https://www.klipper3d.org/"
LICENSE = "GPL-3.0"
LIC_FILES_CHKSUM = "file://COPYING;md5=d32239bcb673463ab874e80d47fae504"
inherit setuptools update-rc.d pkgconfig useradd
inherit setuptools pkgconfig runit-service
# setting "DEPENDS =" will break setuptools, make sure to append
DEPENDS += "libusb"
SRC_URI = "\
git://github.com/KevinOConnor/klipper.git;protocol=https \
file://0001-Attempt-to-package-klippy-using-setuptools.patch \
file://0002-Assume-hub-ctrl-is-installed-on-the-system-and-is-in.patch \
file://0003-Make-sure-to-also-distribute-menu.cfg.patch \
file://klipper.init \
file://0001-Use-setuptools-for-packaging.patch \
file://klipper.default \
file://klipper.run \
"
SRCREV = "${AUTOREV}"
@@ -28,38 +26,28 @@ RDEPENDS_${PN} = "\
python-cffi \
python-greenlet \
python-jinja2 \
udev \
"
FILES_${PN} += "${sysconfdir} ${localstatedir}"
CONFFILES_${PN} += "${sysconfdir}/klipper/printer.cfg"
INITSCRIPT_NAME = "klipper"
INITSCRIPT_PARAMS = "start 80 2 3 4 5 . stop 90 2 3 4 5 ."
USERADD_PACKAGES = "${PN}"
GROUPADD_PARAM_${PN} = "klipper"
USERADD_PARAM_${PN} = "--system -d ${localstatedir}/lib/klipper/ -g klipper klipper"
RUNIT_SERVICES = "klipper"
do_compile() {
${CC} ${CFLAGS} ${LDFLAGS} -o ${B}/hub-ctrl ${S}/lib/hub-ctrl/hub-ctrl.c `pkg-config --cflags --libs libusb`
}
pkg_postinst_ontarget_${PN}_append () {
chown -R klipper.klipper $D${sysconfdir}/klipper
}
do_install_append() {
install -m 0755 -d ${D}${sysconfdir}/klipper
install -m 0755 -d ${D}${sysconfdir}/default
install -m 0644 ${WORKDIR}/klipper.default ${D}${sysconfdir}/default/klipper
install -m 0755 -d ${D}${sysconfdir}/init.d
install -m 0755 ${WORKDIR}/klipper.init ${D}${sysconfdir}/init.d/klipper
install -m 0755 -d ${D}${sysconfdir}/runit/klipper
install -m 0755 ${WORKDIR}/klipper.run ${D}${sysconfdir}/runit/klipper/run
install -m 0755 -d ${D}${bindir}
install -m 0755 ${B}/hub-ctrl ${D}${bindir}/hub-ctrl
install -d ${D}${localstatedir}/lib/klipper/sdcard
install -d ${D}${localstatedir}/lib/klipper/config
install -m 0644 ${S}/config/*.cfg ${D}${localstatedir}/lib/klipper/config
chmod -R g+rw ${D}${localstatedir}/lib/klipper
}

View File

@@ -11,7 +11,6 @@ inherit allarch
RDEPENDS_${PN} = "openssl openssl-misc openssl-bin busybox cronie"
SRC_URI = "file://create-cert \
file://create-certificate.confbackup \
file://create-certificate.cron \
"

View File

@@ -1,7 +0,0 @@
#!/bin/sh
REL=/etc/ssl/certs/
cd $REL
mkdir -p $STAGING/$REL
cp dsscert.pem dssprivkey.pem dsscertreq.csr $STAGING/$REL

View File

@@ -5,10 +5,10 @@ serial:
timeout: {}
plugins:
pluginmanager:
pip: /usr/bin/pip-sudo
pip: /usr/bin/pip
pip_force_user: true
softwareupdate:
pip_command: /usr/bin/pip-sudo
pip_command: /usr/bin/pip
_config_version: 6
checks:
octoprint:
@@ -17,12 +17,14 @@ plugins:
prerelease_channel: null
notify_users: false
server:
reverseProxy:
prefixHeader: X-Script-Name
onlineCheck:
enabled: false
pluginBlacklist:
enabled: true
commands:
serverRestartCommand: /etc/init.d/octoprint restart
serverRestartCommand: sv restart octoprint
systemRestartCommand: shutdown -r now
systemShutdownCommand: shutdown -h now
system:

View File

@@ -1,23 +0,0 @@
# Configuration for /etc/init.d/octoprint
# base directory to use
BASEDIR=/var/lib/octoprint
# configuration file to use
CONFIGFILE=/etc/octoprint/config.yaml
# On what port to run daemon, default is 5000
PORT=5000
# What arguments to pass to octoprint, usually no need to touch this
DAEMON_ARGS="--port=$PORT"
# Umask of files octoprint generates, Change this to 000 if running octoprint as its own, separate user
UMASK=022
# Process priority, 0 here will result in a priority 20 process.
# -2 ensures Octoprint has a slight priority over user processes.
NICELEVEL=-2
# Should we run at startup?
START=yes

View File

@@ -1,157 +0,0 @@
#!/bin/sh
### BEGIN INIT INFO
# Provides: octoprint
# Required-Start: $local_fs networking
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: OctoPrint daemon
# Description: Starts the OctoPrint daemon with the user specified in
# /etc/default/octoprint.
### END INIT INFO
# Author: Sami Olmari & Gina Häußge
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="OctoPrint Daemon"
NAME="OctoPrint"
PKGNAME=octoprint
PIDFILE=/var/run/$PKGNAME.pid
SCRIPTNAME=/etc/init.d/$PKGNAME
DEFAULTS=/etc/default/$PKGNAME
DAEMON=/usr/bin/octoprint
LOGDIR=/var/log/octoprint
mkdir -p $LOGDDIR
chown -R octoprint.octoprint $LOGDIR
# Read configuration variable file if it is present
[ -r $DEFAULTS ] && . $DEFAULTS
# Exit if the DAEMON is not set
if [ -z "$DAEMON" ]
then
echo "Not starting $PKGNAME, DAEMON not set in /etc/default/$PKGNAME."
exit 0
fi
# Exit if the DAEMON is not installed
[ -x "$DAEMON" ] || exit 0
if [ -z "$START" -o "$START" != "yes" ]
then
echo "Not starting $PKGNAME, edit /etc/default/$PKGNAME to start it."
exit 0
fi
COMMAND_ARGS=
if [ -n "$BASEDIR" ]
then
COMMAND_ARGS="--basedir $BASEDIR $COMMAND_ARGS"
fi
if [ -n "$CONFIGFILE" ]
then
COMMAND_ARGS="--config $CONFIGFILE $COMMAND_ARGS"
fi
COMMAND_ARGS="--logging $LOGDIR $COMMAND_ARGS"
#
# Function to verify if a pid is alive
#
is_alive()
{
pid=`cat $1` > /dev/null 2>&1
kill -0 $pid > /dev/null 2>&1
return $?
}
#
# Function that starts the daemon/service
#
do_start()
{
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
is_alive $PIDFILE
RETVAL="$?"
if [ $RETVAL != 0 ]; then
start-stop-daemon --start --background --quiet --pidfile $PIDFILE \
--make-pidfile --chuid octoprint \
--exec $DAEMON --nicelevel=$NICELEVEL \
-- serve $COMMAND_ARGS $DAEMON_ARGS
RETVAL="$?"
fi
}
#
# Function that stops the daemon/service
#
do_stop()
{
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE
RETVAL="$?"
[ "$RETVAL" = "2" ] && return 2
rm -f $PIDFILE
[ "$RETVAL" = "0" ] && return 0 || return 1
}
case "$1" in
start)
[ "$VERBOSE" != no ] && echo -n "Starting $DESC $NAME "
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && echo 0 ;;
2) [ "$VERBOSE" != no ] && echo 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && echo -n "Stopping $DESC $NAME "
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && echo 0 ;;
2) [ "$VERBOSE" != no ] && echo 1 ;;
esac
;;
status)
status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $?
;;
restart)
echo -n "Restarting $DESC" "$NAME"
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) echo 0 ;;
1) echo 1 ;; # Old process is still running
*) echo 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
echo 1
;;
esac
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|status|restart}" >&2
exit 3
;;
esac

View File

@@ -0,0 +1,22 @@
#!/bin/sh
DAEMON=/usr/bin/octoprint
LOGDIR=/var/log/octoprint
BASEDIR=/var/lib/octoprint
CONFIGFILE=/etc/octoprint/config.yaml
PORT=5000
mkdir -p $LOGDIR
mkdir -p $BASEDIR
OPTIONS="serve --basedir $BASEDIR --config $CONFIGFILE --port $PORT \
--logging $LOGDIR --iknowwhatimdoing --host 127.0.0.1"
if [ ! -x $DAEMON ]; then
echo "$0: $DAEMON not found"
sleep 10
exit 1
fi
exec 2>&1
exec $DAEMON $OPTIONS

View File

@@ -1,4 +0,0 @@
octoprint ALL=NOPASSWD: /etc/init.d/octoprint
octoprint ALL=NOPASSWD: /sbin/shutdown
octoprint ALL=NOPASSWD: /usr/bin/pip
octoprint ALL=NOPASSWD: /usr/bin/python

View File

@@ -1,3 +0,0 @@
#!/bin/sh
sudo pip $*
exit $?

View File

@@ -12,15 +12,12 @@ LIC_FILES_CHKSUM = "file://LICENSE.txt;md5=73f1eb20517c55bf9493b7dd6e480788"
SRC_URI = "\
git://github.com/OctoPrint/OctoPrint.git;protocol=https;tag=${PV} \
file://config.yaml \
file://octoprint.default \
file://octoprint.init \
file://octoprint.sudo \
file://pip-sudo \
file://octoprint.run \
"
S = "${WORKDIR}/git"
inherit setuptools update-rc.d useradd
inherit setuptools runit-service
export BUILD_SYS
@@ -30,42 +27,20 @@ export STAGING_LIBDIR
BBCLASSEXTEND = "native"
INITSCRIPT_NAME = "octoprint"
INITSCRIPT_PARAMS = "start 90 2 3 4 5 . stop 80 2 3 4 5 ."
RUNIT_SERVICES = "octoprint"
do_install_append(){
install -d ${D}${sysconfdir}/octoprint
install -d ${D}${sysconfdir}/default
install -m 0644 ${WORKDIR}/octoprint.default ${D}${sysconfdir}/default/octoprint
install -m 0644 ${WORKDIR}/config.yaml ${D}${sysconfdir}/octoprint/config.yaml
chmod a+rw ${D}${sysconfdir}/octoprint/
install -d ${D}${sysconfdir}/init.d
install -m 0755 ${WORKDIR}/octoprint.init ${D}${sysconfdir}/init.d/octoprint
install -m 0755 -d ${D}${sysconfdir}/runit/octoprint
install -m 0755 ${WORKDIR}/octoprint.run ${D}${sysconfdir}/runit/octoprint/run
install -d ${D}${localstatedir}/lib/octoprint
chmod a+rw ${D}${localstatedir}/lib/octoprint
install -d ${D}${sysconfdir}/sudoers.d
install -m 0644 ${WORKDIR}/octoprint.sudo ${D}${sysconfdir}/sudoers.d/octoprint
install -d ${D}${bindir}
install -m 0755 ${WORKDIR}/pip-sudo ${D}${bindir}
}
FILES_${PN} += "${sysconfdir} ${localstatedir}"
CONFFILES_${PN} += "${sysconfdir}/octoprint/config.yaml"
USERADD_PACKAGES = "${PN}"
GROUPADD_PARAM_${PN} = "octoprint"
USERADD_PARAM_${PN} = "--system -d ${localstatedir}/lib/octoprint/ -g octoprint octoprint"
pkg_postinst_ontarget_${PN}_append () {
chown -R octoprint.octoprint $D${sysconfdir}/octoprint
chown -R octoprint.octoprint $D${localstatedir}/lib/octoprint
}
DEPENDS = "${PYTHON_PN} ${PYTHON_PN}-markdown-native"
INSANE_SKIP_${PN} += "build-deps"
@@ -112,7 +87,6 @@ RDEPENDS_${PN} = "\
${PYTHON_PN}-chainmap \
${PYTHON_PN}-typing \
${PYTHON_PN}-pip \
sudo \
"
BBCLASSEXTEND = "native"