[IMP] point_of_sale: add scripts to generate posbox images
Instead of continuing to build upon the old images, these scripts implement a reproducable way to generate new posbox images. The generated images will be based on the latest stable Raspbian release. The image will be created with the help of qemu-system-arm, which will boot up the image and execute a script that will set up the posbox image. This way everything necessary to set up a posbox is readable in the scripts and accompanying files, instead of being hidden in an image.
This commit is contained in:
parent
7c4864e942
commit
86762ef30f
|
@ -40,6 +40,10 @@ from openerp.tools.translate import _
|
|||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
# workaround https://bugs.launchpad.net/openobject-server/+bug/947231
|
||||
# related to http://bugs.python.org/issue7980
|
||||
from datetime import datetime
|
||||
datetime.strptime('2012-01-01', '%Y-%m-%d')
|
||||
|
||||
class EscposDriver(Thread):
|
||||
def __init__(self):
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
kernel-qemu
|
||||
posbox.img
|
||||
raspbian.img
|
|
@ -0,0 +1,4 @@
|
|||
proc /proc proc defaults 0 0
|
||||
/dev/mmcblk0p1 /boot vfat defaults 0 2
|
||||
/dev/mmcblk0p2 / ext4 defaults,noatime,ro 0 1
|
||||
# a swapfile is not a swap partition, so no using swapon|off from here on, use dphys-swapfile swap[on|off] for that
|
|
@ -0,0 +1,10 @@
|
|||
#! /bin/sh
|
||||
#
|
||||
# rcS
|
||||
#
|
||||
# Call all S??* scripts in /etc/rcS.d/ in numerical/alphabetical order
|
||||
#
|
||||
|
||||
/etc/setup_ramdisks.sh
|
||||
|
||||
exec /etc/init.d/rc S
|
|
@ -0,0 +1,3 @@
|
|||
# needed for postgresql
|
||||
auto lo
|
||||
iface lo inet loopback
|
|
@ -0,0 +1,23 @@
|
|||
#!/bin/sh -e
|
||||
#
|
||||
# rc.local
|
||||
#
|
||||
# This script is executed at the end of each multiuser runlevel.
|
||||
# Make sure that the script will "exit 0" on success or any other
|
||||
# value on error.
|
||||
#
|
||||
# In order to enable or disable this script just change the execution
|
||||
# bits.
|
||||
#
|
||||
# By default this script does nothing.
|
||||
|
||||
# Print the IP address
|
||||
_IP=$(hostname -I) || true
|
||||
if [ "$_IP" ]; then
|
||||
printf "My IP address is %s\n" "$_IP"
|
||||
fi
|
||||
|
||||
mkdir -p /var/run/odoo
|
||||
chown pi:pi /var/run/odoo
|
||||
|
||||
exit 0
|
|
@ -0,0 +1,25 @@
|
|||
#!/usr/bin/env bash
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
# set -o xtrace
|
||||
|
||||
create_ramdisk () {
|
||||
ORIGINAL="${1}"
|
||||
RAMDISK="${ORIGINAL}_ram"
|
||||
SIZE="${2}"
|
||||
echo "Creating ramdisk for ${1} of size ${SIZE}..."
|
||||
|
||||
mount -t tmpfs -o size="${SIZE}" tmpfs "${RAMDISK}"
|
||||
rsync -a --exclude="swap" --exclude="apt" --exclude="dpkg" "${ORIGINAL}/" "${RAMDISK}/"
|
||||
mount --bind "${RAMDISK}" "${ORIGINAL}"
|
||||
}
|
||||
|
||||
# check /proc/cmdline
|
||||
|
||||
# bind mount / so that we can get to the real /var and /etc
|
||||
mount --bind / /root_bypass_ramdisks
|
||||
|
||||
echo "Creating ramdisks..."
|
||||
create_ramdisk "/var" "128M"
|
||||
create_ramdisk "/etc" "16M"
|
|
@ -0,0 +1,72 @@
|
|||
#!/bin/bash
|
||||
### BEGIN INIT INFO
|
||||
# Provides: odoo.py
|
||||
# Required-Start: $remote_fs $syslog postgresql
|
||||
# Required-Stop: $remote_fs $syslog
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: Start odoo daemon at boot time
|
||||
# Description: Enable service provided by daemon.
|
||||
# X-Interactive: true
|
||||
### END INIT INFO
|
||||
## more info: http://wiki.debian.org/LSBInitScripts
|
||||
|
||||
. /lib/lsb/init-functions
|
||||
|
||||
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
|
||||
DAEMON=/home/pi/odoo/odoo.py
|
||||
NAME=odoo
|
||||
DESC=odoo
|
||||
CONFIG=/home/pi/odoo.conf
|
||||
LOGFILE=/var/log/odoo/odoo-server.log
|
||||
PIDFILE=/var/run/${NAME}.pid
|
||||
USER=pi
|
||||
|
||||
test -x $DAEMON || exit 0
|
||||
set -e
|
||||
|
||||
function _start() {
|
||||
start-stop-daemon --start --quiet --pidfile $PIDFILE --chuid $USER:$USER --background --make-pidfile --exec $DAEMON -- --config $CONFIG --logfile $LOGFILE --load=web,hw_proxy,hw_posbox_homepage,hw_posbox_upgrade,hw_scale,hw_scanner,hw_escpos
|
||||
}
|
||||
|
||||
function _stop() {
|
||||
start-stop-daemon --stop --quiet --pidfile $PIDFILE --oknodo --retry 3
|
||||
rm -f $PIDFILE
|
||||
}
|
||||
|
||||
function _status() {
|
||||
start-stop-daemon --status --quiet --pidfile $PIDFILE
|
||||
return $?
|
||||
}
|
||||
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
echo -n "Starting $DESC: "
|
||||
_start
|
||||
echo "ok"
|
||||
;;
|
||||
stop)
|
||||
echo -n "Stopping $DESC: "
|
||||
_stop
|
||||
echo "ok"
|
||||
;;
|
||||
restart|force-reload)
|
||||
echo -n "Restarting $DESC: "
|
||||
_stop
|
||||
sleep 1
|
||||
_start
|
||||
echo "ok"
|
||||
;;
|
||||
status)
|
||||
echo -n "Status of $DESC: "
|
||||
_status && echo "running" || echo "stopped"
|
||||
;;
|
||||
*)
|
||||
N=/etc/init.d/$NAME
|
||||
echo "Usage: $N {start|stop|restart|force-reload|status}" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
exit 0
|
|
@ -0,0 +1,68 @@
|
|||
#!/usr/bin/env bash
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
# set -o xtrace
|
||||
|
||||
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
|
||||
__base="$(basename ${__file} .sh)"
|
||||
|
||||
# Recommends: antiword, graphviz, ghostscript, postgresql, python-gevent, poppler-utils
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
# GUI-related packages
|
||||
PKGS_TO_DELETE="xserver-xorg-video-fbdev xserver-xorg xinit gstreamer1.0-x gstreamer1.0-omx gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-alsa gstreamer1.0-libav epiphany-browser lxde lxtask menu-xdg gksu xserver-xorg-video-fbturbo xpdf gtk2-engines alsa-utils netsurf-gtk zenity desktop-base lxpolkit weston omxplayer raspberrypi-artwork lightdm gnome-themes-standard-data gnome-icon-theme qt50-snapshot qt50-quick-particle-examples idle python-pygame python-tk idle3 python-serial python-picamera debian-reference-en dillo x2x scratch nuscratch raspberrypi-ui-mods timidity smartsim penguinspuzzle pistore sonic-pi python-pifacecommon python-pifacedigitalio oracle-java8-jdk minecraft-pi python-minecraftpi wolfram-engine raspi-config libgl1-mesa-dri libicu48 pypy-upstream lxde-icon-theme python3"
|
||||
INSTALLED_PKGS_TO_DELETE=""
|
||||
set +o errexit
|
||||
for CURRENT_PKG in $(echo $PKGS_TO_DELETE); do
|
||||
$(dpkg --status $CURRENT_PKG &> /dev/null)
|
||||
if [[ $? -eq 0 ]]; then
|
||||
INSTALLED_PKGS_TO_DELETE="$INSTALLED_PKGS_TO_DELETE $CURRENT_PKG"
|
||||
fi
|
||||
done
|
||||
set -o errexit
|
||||
|
||||
apt-get -y remove --purge ${INSTALLED_PKGS_TO_DELETE}
|
||||
|
||||
# Remove automatically installed dependency packages
|
||||
apt-get -y autoremove
|
||||
|
||||
apt-get update
|
||||
apt-get -y dist-upgrade
|
||||
|
||||
PKGS_TO_INSTALL="adduser postgresql-client python python-dateutil python-decorator python-docutils python-feedparser python-imaging python-jinja2 python-ldap python-libxslt1 python-lxml python-mako python-mock python-openid python-passlib python-psutil python-psycopg2 python-pybabel python-pychart python-pydot python-pyparsing python-pypdf python-reportlab python-requests python-simplejson python-tz python-unittest2 python-vatnumber python-vobject python-werkzeug python-xlwt python-yaml postgresql python-gevent python-serial python-pip python-dev localepurge vim mc mg"
|
||||
|
||||
apt-get -y install ${PKGS_TO_INSTALL}
|
||||
|
||||
apt-get clean
|
||||
localepurge
|
||||
rm -rf /usr/share/doc || true
|
||||
rm -rf /home/pi/python_games || true
|
||||
|
||||
# python-usb in wheezy is too old
|
||||
# the latest pyusb from pip does not work either, usb.core.find() never returns
|
||||
# this may be fixed with libusb>2:1.0.11-1, but that's the most recent one in raspbian
|
||||
# so we install the latest pyusb that works with this libusb
|
||||
pip install pyusb==1.0.0b1
|
||||
pip install qrcode
|
||||
pip install evdev
|
||||
|
||||
usermod -a -G lp pi
|
||||
|
||||
sudo -u postgres createuser -s pi
|
||||
mkdir /var/log/odoo
|
||||
chown pi:pi /var/log/odoo
|
||||
|
||||
update-rc.d odoo defaults
|
||||
|
||||
# create dirs for ramdisks
|
||||
create_ramdisk_dir () {
|
||||
mkdir "${1}_ram"
|
||||
}
|
||||
|
||||
create_ramdisk_dir "/var"
|
||||
create_ramdisk_dir "/etc"
|
||||
mkdir /root_bypass_ramdisks
|
||||
|
||||
reboot
|
|
@ -0,0 +1,2 @@
|
|||
# the used qemu-kernel doesn't work well with this library, so get rid of it
|
||||
#/usr/lib/arm-linux-gnueabihf/libcofi_rpi.so
|
|
@ -0,0 +1,32 @@
|
|||
# see "man logrotate" for details
|
||||
# rotate log files daily
|
||||
daily
|
||||
|
||||
# keep 2 days worth of backlogs
|
||||
rotate 2
|
||||
|
||||
# create new (empty) log files after rotating old ones
|
||||
create
|
||||
|
||||
# uncomment this if you want your log files compressed
|
||||
#compress
|
||||
|
||||
# packages drop log rotation information into this directory
|
||||
include /etc/logrotate.d
|
||||
|
||||
# no packages own wtmp, or btmp -- we'll rotate them here
|
||||
/var/log/wtmp {
|
||||
missingok
|
||||
monthly
|
||||
create 0664 root utmp
|
||||
rotate 1
|
||||
}
|
||||
|
||||
/var/log/btmp {
|
||||
missingok
|
||||
monthly
|
||||
create 0660 root utmp
|
||||
rotate 1
|
||||
}
|
||||
|
||||
# system-specific logs may be configured here
|
|
@ -0,0 +1,5 @@
|
|||
/var/log/odoo/*.log {
|
||||
copytruncate
|
||||
missingok
|
||||
notifempty
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
#!/bin/sh -e
|
||||
#
|
||||
# rc.local
|
||||
#
|
||||
# This script is executed at the end of each multiuser runlevel.
|
||||
# Make sure that the script will "exit 0" on success or any other
|
||||
# value on error.
|
||||
#
|
||||
# In order to enable or disable this script just change the execution
|
||||
# bits.
|
||||
#
|
||||
# By default this script does nothing.
|
||||
|
||||
# Print the IP address
|
||||
_IP=$(hostname -I) || true
|
||||
if [ "$_IP" ]; then
|
||||
printf "My IP address is %s\n" "$_IP"
|
||||
fi
|
||||
|
||||
/etc/init_posbox_image.sh
|
||||
|
||||
exit 0
|
|
@ -0,0 +1,3 @@
|
|||
KERNEL=="sda", SYMLINK+="mmcblk0"
|
||||
KERNEL=="sda?", SYMLINK+="mmcblk0p%n"
|
||||
KERNEL=="sda2", SYMLINK+="root"
|
|
@ -0,0 +1,6 @@
|
|||
[options]
|
||||
data_dir = /var/run/odoo
|
||||
log_level = error
|
||||
logfile = /var/log/odoo/odoo-server.log
|
||||
pidfile = /var/run/odoo/odoo.pid
|
||||
server_wide_modules = web,hw_proxy,hw_posbox_homepage,hw_posbox_upgrade,hw_scale,hw_scanner,hw_escpos
|
|
@ -0,0 +1,75 @@
|
|||
#!/usr/bin/env bash
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
# set -o xtrace
|
||||
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
echo "This script must be run as root"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
file_exists() {
|
||||
[[ -f $1 ]];
|
||||
}
|
||||
|
||||
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
|
||||
__base="$(basename ${__file} .sh)"
|
||||
|
||||
MOUNT_POINT="${__dir}/root_mount"
|
||||
OVERWRITE_FILES_BEFORE_INIT_DIR="${__dir}/overwrite_before_init"
|
||||
OVERWRITE_FILES_AFTER_INIT_DIR="${__dir}/overwrite_after_init"
|
||||
|
||||
if [ ! -f kernel-qemu ] || ! file_exists *raspbian*.img ; then
|
||||
./posbox_download_images.sh
|
||||
fi
|
||||
|
||||
cp -a *raspbian*.img posbox.img
|
||||
|
||||
CLONE_DIR="${OVERWRITE_FILES_BEFORE_INIT_DIR}/home/pi/odoo"
|
||||
mkdir "${CLONE_DIR}"
|
||||
git clone -b 8.0 --no-checkout --depth 1 https://github.com/odoo/odoo.git "${CLONE_DIR}"
|
||||
cd "${CLONE_DIR}"
|
||||
git config core.sparsecheckout true
|
||||
echo "addons/web
|
||||
addons/web_kanban
|
||||
addons/hw_*
|
||||
openerp/
|
||||
odoo.py" | tee --append .git/info/sparse-checkout > /dev/null
|
||||
git read-tree -mu HEAD
|
||||
cd "${__dir}"
|
||||
|
||||
# rc.local
|
||||
LOOP_MAPPER_PATH=$(kpartx -av posbox.img | tail -n 1 | cut -d ' ' -f 3)
|
||||
LOOP_MAPPER_PATH="/dev/mapper/${LOOP_MAPPER_PATH}"
|
||||
mkdir "${MOUNT_POINT}"
|
||||
mount "${LOOP_MAPPER_PATH}" "${MOUNT_POINT}"
|
||||
|
||||
# 'overlay' the overwrite directory onto the mounted image filesystem
|
||||
cp -a "${OVERWRITE_FILES_BEFORE_INIT_DIR}"/* "${MOUNT_POINT}"
|
||||
|
||||
# get rid of the git clone
|
||||
rm -rf "${CLONE_DIR}"
|
||||
|
||||
# get rid of the mount, we have to remount it anyway because we have
|
||||
# to "refresh" the filesystem after qemu modified it
|
||||
sleep 2
|
||||
umount "${MOUNT_POINT}"
|
||||
|
||||
# from http://paulscott.co.za/blog/full-raspberry-pi-raspbian-emulation-with-qemu/
|
||||
# ssh pi@localhost -p10022
|
||||
qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw" -hda posbox.img -net user,hostfwd=tcp::10022-:22,hostfwd=tcp::18069-:8069 -net nic
|
||||
|
||||
mount "${LOOP_MAPPER_PATH}" "${MOUNT_POINT}"
|
||||
cp -av "${OVERWRITE_FILES_AFTER_INIT_DIR}"/* "${MOUNT_POINT}"
|
||||
|
||||
# cleanup
|
||||
sleep 2
|
||||
umount "${MOUNT_POINT}"
|
||||
rm -r "${MOUNT_POINT}"
|
||||
|
||||
echo "Running zerofree..."
|
||||
zerofree -v "${LOOP_MAPPER_PATH}" || true
|
||||
|
||||
kpartx -d posbox.img
|
|
@ -0,0 +1,5 @@
|
|||
#!/bin/sh
|
||||
|
||||
wget 'http://downloads.raspberrypi.org/raspbian_latest' -O raspbian.img.zip
|
||||
unzip raspbian.img.zip
|
||||
wget 'https://github.com/dhruvvyas90/qemu-rpi-kernel/raw/master/kernel-qemu'
|
Loading…
Reference in New Issue