Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] packaging, service, upgrade changes #1759

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
FROM debian:latest

#TODO: Use version from package.json?
ENV NODE_VERSION 14.15.4
ENV NVM_DIR /usr/local/nvm


RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections

RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
devscripts \
debhelper \
dh-systemd \
jq \
python3-pip \
apt-transport-https \
build-essential \
ca-certificates \
curl \
git \
libssl-dev \
wget \
rsync


RUN pip3 install yq

RUN rm /bin/sh && ln -s /bin/bash /bin/sh

RUN mkdir $NVM_DIR

RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash \
&& . $NVM_DIR/nvm.sh \
&& nvm install $NODE_VERSION \
&& nvm alias default $NODE_VERSION \
&& nvm use default

ENV NODE_PATH $NVM_DIR/versions/node/v$NODE_VERSION/lib/node_modules
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH

CMD rsync -av /src/ /build --exclude "package/" \
&& cd /build \
&& make build-internal \
&& BUILD_TIMESTAMP=$(date +%s) \
&& cp -rv "/build/package" "/package/${BUILD_TIMESTAMP}"
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
SHELL := /bin/bash

DOCKER_IMAGE_NAME="octodash/build"

export

all:
mkdir -p package && \
docker build \
-t ${DOCKER_IMAGE_NAME} . && \
docker run -it --rm \
-v "${PWD}":/src:ro \
-v "${PWD}/package":/package \
${DOCKER_IMAGE_NAME}

build-internal:
npm run pack

clean:
44 changes: 44 additions & 0 deletions distribution/debian.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash
set -e

cd "$(dirname "$0")"


VERSION=$(yq -c -M .version ../package.json | tr -d \")
ARCHS=$(jq ".build.linux.target[0].arch[]" ../package.json | tr -d \")

#hack for amd64
ARCHS=$(echo "${ARCHS}" | sed 's/x64/amd64/g')
if [[ ( ! -L ../package/linux-amd64-unpacked ) && ( -d ../package/linux-unpacked ) ]]
then
ln -s ../package/linux-unpacked ../package/linux-amd64-unpacked
fi


for ARCH in `echo ${ARCHS}`
do
PACKAGE="linux-${ARCH}-unpacked"

TMP_DIR=$(mktemp -d)
BUILD_DIR="${TMP_DIR}/build"

mkdir -p "${BUILD_DIR}"


cp -prv debian "${BUILD_DIR}/debian"
cp -prv "../package/${PACKAGE}/" "${BUILD_DIR}/"
mv "${BUILD_DIR}/${PACKAGE}" "${BUILD_DIR}/package"

pushd $BUILD_DIR

sed -i "s:{version}:$VERSION:g;" debian/changelog
#sed -i "s:{arch}:$ARCH:g;" debian/control

#debuild -b
debuild -b -uc -us

popd
find "${TMP_DIR}" -maxdepth 1 -type f -name "*.deb" -exec cp -f "{}" "../package/octodash-${VERSION}-${ARCH}.deb" \;
rm -rf "${TMP_DIR}"

done
5 changes: 5 additions & 0 deletions distribution/debian/changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
octodash ({version}) stable; urgency=low

* Automatic Release.

-- Name <[email protected]> Sun, 01 Jan 1970 00:00:00 -0000
1 change: 1 addition & 0 deletions distribution/debian/compat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10
18 changes: 18 additions & 0 deletions distribution/debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Source: octodash
Section: x11
Priority: optional
Maintainer: Name <email>
Homepage: https://github.com/UnchartedBull/OctoDash
Vcs-Git: https://github.com/UnchartedBull/OctoDash.git
Vcs-Browser: https://github.com/UnchartedBull/OctoDash
Build-Depends: debhelper (>= 9),
dh-systemd (>= 1.5)

Package: octodash
Architecture: all
Depends: bc, desktop-file-utils, libappindicator3-1, libatspi2.0-0, libavahi-compat-libdnssd1, libgtk-3-0, libgtk-3-0, libnotify4, libnss3, libpam0g-dev, libsecret-1-0, libuuid1, libx11-dev, libxss1, libxtst6, rsync, x11-xserver-utils, xdg-utils, xinit, xserver-xorg
Description: OctoDash is a User Interface for OctoPrint, it utilizes the OctoPrint API
but tries to use modern design principles in order to fully enable the power of your
Raspberry Pi attached to your 3D Printer. OctoDash works best with a Touchscreen and
will support almost all functions that OctoPrint offers just in a nicer format.

22 changes: 22 additions & 0 deletions distribution/debian/copyright
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: octodash
Source: https://github.com/UnchartedBull/OctoDash

Files: *
Copyright: 20XX-20XX OctoDash <EMAIL>

License: Apache-2.0
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

On Debian systems, the complete text of the Apache version 2.0 license
can be found in `/usr/share/common-licenses/Apache-2.0'.
6 changes: 6 additions & 0 deletions distribution/debian/local/etc/X11/xinit/octodash.xinit
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
xset s off
xset s noblank
xset -dpms

octodash
4 changes: 4 additions & 0 deletions distribution/debian/local/etc/default/octodash
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Configuration for OctoDash

# User to run OctoDash as. This will generally will be the same as OctoPrint
OCTODASH_USER=
1 change: 1 addition & 0 deletions distribution/debian/octodash.install
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
debian/local/* /
1 change: 1 addition & 0 deletions distribution/debian/octodash.links
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/opt/OctoDash/octodash /usr/bin/octodash
63 changes: 63 additions & 0 deletions distribution/debian/octodash.postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/sh
set -e

. /usr/share/debconf/confmodule

db_get octodash/owning_user
USER="$RET"
db_get octodash/owning_group
GROUP="$RET"


THIS_PACKAGE=octodash
DEFAULT_DISPLAY_MANAGER_FILE=/etc/X11/default-display-manager
DEFAULT_SERVICE=/etc/systemd/system/display-manager.service

# debconf is not a registry, so we only fiddle with the default file if
# the configure script requested an update
if [ -e $DEFAULT_DISPLAY_MANAGER_FILE.debconf-update ]; then
rm -f $DEFAULT_DISPLAY_MANAGER_FILE.debconf-update
if db_get shared/default-x-display-manager; then
# workaround debconf passthru bug (#379198)
if [ -z "$RET" ]; then
RET="$THIS_PACKAGE"
fi
if [ "$THIS_PACKAGE" != "$RET" ]; then
echo "Please be sure to run \"dpkg --configure $RET\"."
fi
if db_get "$RET"/daemon_name; then
echo "$RET" > $DEFAULT_DISPLAY_MANAGER_FILE
fi
fi
fi


if [ $1 = "configure" ]; then
if [ -d /etc/systemd/system/ ]; then
if [ -e "$DEFAULT_DISPLAY_MANAGER_FILE" ]; then
SERVICE=/lib/systemd/system/$(basename $(cat "$DEFAULT_DISPLAY_MANAGER_FILE") | awk '{print tolower($0)}').service
echo "Installing service $SERVICE"
if [ -h "$DEFAULT_SERVICE" ] && [ $(readlink "$DEFAULT_SERVICE") = /dev/null ]; then
echo "Display manager service is masked" >&2
elif [ -e "$SERVICE" ]; then
ln -sf "$SERVICE" "$DEFAULT_SERVICE"
else
echo "WARNING: $SERVICE is the selected default display manager but does not exist" >&2
rm -f "$DEFAULT_SERVICE"
fi
else
rm -f "$DEFAULT_SERVICE"
fi
fi


chown -R $USER:$GROUP /opt/OctoDash
chmod -R 775 /opt/OctoDash

sed -i "s/OCTODASH_USER=\w*/OCTODASH_USER=${USER}/g" /etc/default/octodash
sed -i "s/^#*allowed_users=\w*$/allowed_users=anybody/g" /etc/X11/Xwrapper.config

systemctl set-default graphical.target
fi

exit 0
4 changes: 4 additions & 0 deletions distribution/debian/octodash.postrm
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
set -e

exit 0
20 changes: 20 additions & 0 deletions distribution/debian/octodash.preinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh
set -e

. /usr/share/debconf/confmodule

db_get octodash/owning_user
USER="$RET"
db_get octodash/owning_group
GROUP="$RET"

if [ $1 = "install" ]; then
if ! getent group "$GROUP" >/dev/null; then
groupadd "$GROUP"
fi
if ! getent passwd "$USER" >/dev/null; then
adduser --system --no-create-home --ingroup "$GROUP" "$USER"
fi
fi

exit 0
20 changes: 20 additions & 0 deletions distribution/debian/octodash.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[Unit]
Description=OctoDash
After=octoprint.service
Requires=graphical.target
Wants=network-online.target

[Service]
Type=simple
EnvironmentFile=-/etc/default/octodash
Environment=DISPLAY=:0.0
Environment=XINITRC=/etc/X11/xinit/octodash.xinit
ExecStart=/bin/su $OCTODASH_USER -w DISPLAY,XINITRC -l -c '/usr/bin/xinit -- -nocursor'
ExecStop=/bin/kill -TERM $MAINPID
TimeoutStopSec=30
Restart=always
RestartSec=2
StartLimitInterval=0

[Install]
WantedBy=graphical.target
13 changes: 13 additions & 0 deletions distribution/debian/octodash.templates
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Template: octodash/owning_user
Type: string
Default: pi
Description: octodash user:
Specify the user that is used to run octodash. The user will be created if it does not already exist.
The default 'pi' should work fine for most users. You can specify the user group next.

Template: octodash/owning_group
Type: string
Default: pi
Description: octodash group:
Specify the group that is used to run octodash. The group will be created if it does not already exist.
If the user doesn't already exist then this group will be used as the user's primary group.
14 changes: 14 additions & 0 deletions distribution/debian/rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
export DH_VERBOSE=1

%:
dh $@ --with=systemd

# No init script, only systemd
override_dh_installinit:
true

override_dh_install:
dh_install package/* /opt/OctoDash
Loading