Skip to content
This repository was archived by the owner on Aug 27, 2022. It is now read-only.

Feature: add filesync #158

Merged
merged 43 commits into from
Dec 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
f40c4af
added syncing script and needed extras
thatonedude3470 Sep 30, 2020
e36835f
fixed whitespace
thatonedude3470 Sep 30, 2020
bf5b2a0
add null check
thatonedude3470 Sep 30, 2020
e445f1f
only return drives with mountpoint
thatonedude3470 Sep 30, 2020
b39a823
rsync add delete-after so only deleted files are backed up
thatonedude3470 Sep 30, 2020
f2e3a12
moved comment and added null check
thatonedude3470 Sep 30, 2020
2c0f5ad
add faq and ask if the user wants the cronjob
thatonedude3470 Sep 30, 2020
a7a2765
forget to change link and to build faq
thatonedude3470 Sep 30, 2020
3fc0ebf
add rsync to update script
thatonedude3470 Sep 30, 2020
374dd1e
added comment about the DATA_DIR_NAME
thatonedude3470 Sep 30, 2020
9455157
fixed md, added comment about hard coded data path
thatonedude3470 Sep 30, 2020
56b2c04
moved config, fixed faq, fixed small bugs
thatonedude3470 Oct 1, 2020
0f702a2
how hard could rsync be?
thatonedude3470 Oct 1, 2020
9f09493
bug fix point after mountpoint (its different on distros)
thatonedude3470 Oct 1, 2020
890c1c2
added all the stuff to make script useable from www-data
thatonedude3470 Oct 1, 2020
73a212f
ofc stuff on the inet isnt correct
thatonedude3470 Oct 1, 2020
0d311a2
Rewrite to eliminate cron, integrate with Admin GUI and settings
jacques42 Oct 8, 2020
336f7b9
Sync to USB Translations, Admin GUI, udisks2, clean-up, etc.
jacques42 Oct 10, 2020
a6e1b98
Sync to USB small bug fix and clean-up
jacques42 Oct 10, 2020
4e9927b
Sync to USB: Done prettier, update script, faq, manual, logging fixes…
jacques42 Oct 11, 2020
e79d877
Sync to USB: gulp clean-up
jacques42 Oct 11, 2020
abf7627
Sync to USB fixed bug and implemented recommendations
jacques42 Oct 12, 2020
f8e6eb1
Sync to USB as always, forgot one more thing to change.
jacques42 Oct 12, 2020
64266bb
reverted back to interpolation and some small fixes, new logging func…
thatonedude3470 Oct 12, 2020
23781f5
dang me always that one typo
thatonedude3470 Oct 12, 2020
aa683ca
missed interpolation here
thatonedude3470 Oct 14, 2020
bc9cd72
changed name of log function
thatonedude3470 Oct 14, 2020
3fe6ecb
fixed inf node bug, check rsync every loop, loop with interval
thatonedude3470 Oct 14, 2020
e5bd250
writeFileSync has no callback
thatonedude3470 Oct 14, 2020
c1b4bf8
USB sync to drive: enhanced services_start / services_stop scripts to…
jacques42 Oct 14, 2020
2d8b131
lib: formatting
andi34 Oct 24, 2020
21df217
Added basic inter-process communication using events, to track child …
jacques42 Oct 27, 2020
dda71fc
make kill signal configurable
thatonedude3470 Oct 28, 2020
1581415
fixed/ignored all eslint errors, added unmount function, fixed indent…
thatonedude3470 Oct 28, 2020
a493603
copy paste i tell ya
thatonedude3470 Oct 28, 2020
854036c
Finalize code for initial version to be included in next PB release
jacques42 Dec 19, 2020
4bb66a6
Final adjustments, prettier, eslint
jacques42 Dec 19, 2020
67562c5
docs (README): add thatonedude3470 to contributors
andi34 Dec 19, 2020
0577b5b
fix (js): fix lint issues
andi34 Dec 19, 2020
1fbdaef
Added babel polyfills for Promises
jacques42 Dec 21, 2020
19339a8
Updated pack-build.js
jacques42 Dec 21, 2020
947bfd8
Excluded server scripts from babel transpiler modifications, this is …
jacques42 Dec 22, 2020
7a4fb57
Fixed prettier / eslint conflict
jacques42 Dec 22, 2020
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,4 @@ If you like my work and like to keep me motivated you can buy me a coconut water
- [joiyco](https://github.com/joiyco)
- [EccoB](https://github.com/EccoB)
- [couz74](https://github.com/couz74)
- [thatonedude3470](https://github.com/thatonedude3470)
6 changes: 4 additions & 2 deletions api/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@

if ($os === 'windows') {
$newConfig['remotebuzzer_enabled'] = false;
}
$newConfig['synctodrive_enabled'] = false;
}

$content = "<?php\n\$config = ". var_export(arrayRecursiveDiff($newConfig, $defaultConfig), true) . ";";

Expand All @@ -112,7 +113,8 @@
}
}

require_once('../lib/remotebuzzer_config.php');
/* Kill service daemons after config has changed */
require_once('../lib/services_stop.php');

function arrayRecursiveDiff($aArray1, $aArray2)
{
Expand Down
9 changes: 8 additions & 1 deletion config/config.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@
$config['exiftool']['msg'] = null;
$config['preview']['cmd'] = null;
$config['preview']['killcmd'] = null;
$config['nodebin']['cmd'] = null;


// R E M O T E B U Z Z E R
Expand All @@ -241,10 +242,16 @@
$config['remotebuzzer_collagetime'] = '2';
$config['remotebuzzer_port'] = 14711;
$config['remotebuzzer_pin'] = 40;
$config['remotebuzzer_nodebin'] = '/usr/bin/node';
$config['remotebuzzer_collagetime'] = '2'; // control time to distinguish picture from collage


// R E S E T
$config['reset_remove_images'] = true;
$config['reset_remove_mailtxt'] = true;
$config['reset_remove_config'] = true;


// S Y N C T O U S B S T I C K
$config['synctodrive_enabled'] = false;
$config['synctodrive_target'] = 'photobooth'; //Default target for the sync script
$config['synctodrive_interval'] = 300;
11 changes: 11 additions & 0 deletions faq/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,14 @@ If you run into any errors setting up your hotspot we can remove all the setting
sudo ./setup-network.sh --clean
```

### Automatic picture syncing to USB stick

This feature will automatically and in regular intervals copy (sync) new pictures to a plugged-in USB stick. Currently works on Raspberry PI OS only.

Use the `install-raspbian.sh` script to get the operating system setup in place. The target USB device is selected through the admin panel

A USB drive / stick can be identified either by the USB stick label (e.g. `photobooth`), the operating system specific USB device name (e.g. `/dev/sda1`) or the USB device system subsystem name (e.g. `sda`). The preferred method would be the USB stick label (for use of a single USB stick) or the very specific USB device name, for different USB stick use. The default config will look for a drive with the label photobooth. The script only supports one single USB stick connected at a time

Pictures will be synced to the USB stick matched by the pattern, as long as it is mounted (aka USB stick is plugged in)

Debugging: switch on dev settings for server logs to be written to the `data/tmp` directory of the photobooth installation (i.e. `data/tmp/synctodrive_server.log`).
4 changes: 2 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ gulp.task('sass', function () {
gulp.task('js', function () {
return gulp
.src('./src/js/**/*.js')
.pipe(babel({ presets: ['@babel/env'] }))
.pipe(babel({ presets: ['@babel/env'], ignore: [ "src/js/sync-to-drive.js", "src/js/remotebuzzer_server.js" ] }))
.pipe(gulp.dest('./resources/js'));
});

Expand All @@ -23,4 +23,4 @@ gulp.task('watch', function () {
gulp.watch('./src/js/*.js', gulp.series('js'));
});

gulp.task('default', gulp.parallel('sass', 'js'));
gulp.task('default', gulp.parallel('sass', 'js'));
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,6 @@
<script src="node_modules/@andreasremdt/simple-translator/dist/umd/translator.min.js"></script>
<script type="text/javascript" src="resources/js/i18n.js"></script>

<?php require_once('lib/remotebuzzer_server.php'); ?>
<?php require_once('lib/services_start.php'); ?>
</body>
</html>
33 changes: 33 additions & 0 deletions install-raspbian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ COMMON_PACKAGES=(
'php-gd'
'php-zip'
'yarn'
'rsync'
'udisks2'
)

apache_webserver() {
Expand Down Expand Up @@ -317,6 +319,37 @@ cat >> /boot/config.txt << EOF
dtoverlay=gpio-no-irq
EOF

echo -e "\033[0;33m### Sync to USB - this feature will automatically copy (sync) new pictures to a USB stick."
echo -e "### The actual configuration will be done in the admin panel but we need to setup Raspberry Pi OS first"
read -p "### Would you like to enable the USB sync file backup? [y/N] " -n 1 -r
echo -e "\033[0m"
if [[ $REPLY =~ ^[Yy]$ ]]
then
info "### Disabling automount for pi user"

mkdir -p /home/pi/.config/pcmanfm/LXDE-pi/
cat >> /home/pi/.config/pcmanfm/LXDE-pi/pcmanfm.conf <<EOF
[volume]
mount_on_startup=0
mount_removable=0
autorun=0
EOF

chown -R pi:pi /home/pi/.config/pcmanfm

info "### Adding polkit rule so www-data can (un)mount drives"

cat >> /etc/polkit-1/localauthority/50-local.d/udisks2.pkla <<EOF
[Allow www-data to mount drives with udisks2]
Identity=unix-user:www-data
Action=org.freedesktop.udisks2.filesystem-mount*;org.freedesktop.udisks2.filesystem-unmount*
ResultAny=yes
ResultInactive=yes
ResultActive=yes
EOF

fi

info "### Congratulations you finished the install process."
info "### Have fun with your Photobooth, but first restart your Pi."

Expand Down
10 changes: 9 additions & 1 deletion lib/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
'preview' => [
'cmd' => '',
'killcmd' => '',
],
'nodebin' => [
'cmd' => '',
]
],
'linux' => [
Expand All @@ -40,6 +43,9 @@
'preview' => [
'cmd' => 'gphoto2 --stdout --capture-movie | ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 /dev/video0 > /dev/null 2>&1 & echo $!',
'killcmd' => 'killall gphoto2 && sleep 1',
],
'nodebin' => [
'cmd' => '/usr/bin/node',
]
],
];
Expand Down Expand Up @@ -75,10 +81,12 @@
$config['exiftool']['msg'] = $cmds[$os]['exiftool']['msg'];
$config['preview']['cmd'] = $cmds[$os]['preview']['cmd'];
$config['preview']['killcmd'] = $cmds[$os]['preview']['killcmd'];
$config['nodebin']['cmd'] = $cmds[$os]['nodebin']['cmd'];

$config['collage_limit'] = 4;

$config['remotebuzzer_logfile'] = 'io_server.log';
$config['remotebuzzer_logfile'] = 'remotebuzzer_server.log';
$config['synctodrive_logfile'] = 'synctodrive_server.log';

$defaultConfig = $config;

Expand Down
43 changes: 36 additions & 7 deletions lib/configsetup.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,12 @@
'placeholder' => 'preview_killcmd',
'name' => 'preview[killcmd]',
'value' => htmlentities($config['preview']['killcmd'])
],
'nodebin_cmd' => [
'type' => 'input',
'placeholder' => 'nodebin_cmd',
'name' => 'nodebin[cmd]',
'value' => htmlentities($config['nodebin']['cmd'])
]
],
'remotebuzzer' => [
Expand Down Expand Up @@ -1118,18 +1124,41 @@
'name' => 'remotebuzzer_pin',
'value' => $config['remotebuzzer_pin']
],
'nodebin' => [
'type' => 'input',
'placeholder' => $defaultConfig['remotebuzzer_nodebin'],
'name' => 'remotebuzzer_nodebin',
'value' => $config['remotebuzzer_nodebin']
],
'logfile' => [
'type' => 'hidden',
'name' => 'remotebuzzer_logfile',
'value' => $config['remotebuzzer_logfile']
]
],
],
'synctodrive' => [
'platform' => 'linux',
'synctodrive_enabled' => [
'type' => 'checkbox',
'name' => 'synctodrive_enabled',
'value' => $config['synctodrive_enabled']
],
'target' => [
'type' => 'input',
'placeholder' => $defaultConfig['synctodrive_target'],
'name' => 'synctodrive_target',
'value' => $config['synctodrive_target']
],
'interval' => [
'type' => 'range',
'placeholder' => $defaultConfig['synctodrive_interval'],
'name' => 'synctodrive_interval',
'value' => $config['synctodrive_interval'],
'range_min' => 10,
'range_max' => 600,
'range_step' => 1,
'unit' => 'seconds'
],
'logfile' => [
'type' => 'hidden',
'name' => 'synctodrive_logfile',
'value' => $config['synctodrive_logfile']
]
],
'reset' => [
'remove_images' => [
'type' => 'checkbox',
Expand Down
25 changes: 0 additions & 25 deletions lib/remotebuzzer_config.php

This file was deleted.

23 changes: 0 additions & 23 deletions lib/remotebuzzer_server.php

This file was deleted.

59 changes: 59 additions & 0 deletions lib/services_start.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

require_once(__DIR__ . '/config.php');

function processIsRunning ($pName, $pidFile) {
if (file_exists($pidFile))
{
exec("pgrep -F ".$pidFile, $output, $return);
if ($return == 0) { return true; } // process is active
unlink ($pidFile); // remove stale PID file
}

exec("pgrep -a -f ".$pName, $output, $return);
return count($output)-1 ? true : false ; // true if process is active
}


if ($config['remotebuzzer_enabled']) {
$connection = @fsockopen('127.0.0.1', $config['remotebuzzer_port']);

if (! is_resource($connection))
{
if ($config['dev'])
{
$logfile = $config['foldersAbs']['tmp']."/".$config['remotebuzzer_logfile'];
}
else
{ $logfile = "/dev/null"; }

print ("\t<!-- Remote Buzzer enabled --- starting server -->\n");

proc_close(proc_open ($config['nodebin']['cmd']." resources/js/remotebuzzer_server.js 1>>".$logfile." 2>&1 &", array(), $foo));

} else {
print ("\t<!-- Remote Buzzer Enabled --- server already started (port in use) -->\n");
}

print("\t<script type=\"text/javascript\" src=\"node_modules/socket.io-client/dist/socket.io.slim.js\"></script>\n");
}

if ($config['synctodrive_enabled']) {
if ($config['dev']) {
$logfile = $config['foldersAbs']['tmp']."/".$config['synctodrive_logfile'];
}
else {
$logfile = "/dev/null";
}

if ( processIsRunning("sync-to-drive.js",$config['foldersAbs']['tmp'].'/synctodrive_server.pid'))
{
print ("\t<!-- Sync To Drive enabled --- server already active -->\n");
}
else
{
print ("\t<!-- Sync To Drive enabled --- starting server -->\n");
proc_close(proc_open ($config['nodebin']['cmd']." resources/js/sync-to-drive.js 1>>".$logfile." 2>&1 &", array(), $foo));
}
}
?>
33 changes: 33 additions & 0 deletions lib/services_stop.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/* check PID file and if found, kill process and delete PID file */

require_once(__DIR__ . '/config.php');

function killProcessIfActive($pName, $pidFile, $logfileName, $killSig)
{
global $config;

exec("pgrep -f ".$pName,$pids);

if (count($pids) > 1) {
foreach ($pids as $procPID) {
if ($config['dev'])
{
$logfile = $config['foldersAbs']['tmp']."/".$logfileName;
$fp = fopen($logfile, 'a');//opens file in append mode.
fwrite($fp, "Service Control [ config ]: Photobooth config has changed, killed processes by name ".$pName." -> PID ".$procPID."\n");
fclose($fp);
}

posix_kill($procPID, $killSig);
}
}

if (file_exists($pidFile)) { unlink ($pidFile); }

}

killProcessIfActive('remotebuzzer_server.js','../'.$config['folders']['tmp'].'/remotebuzzer_server.pid',$config['remotebuzzer_logfile'], 9);
killProcessIfActive('sync-to-drive.js','../'.$config['folders']['tmp'].'/synctodrive_server.pid',$config['synctodrive_logfile'], 15);

?>
4 changes: 4 additions & 0 deletions manual/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
echo '<div class="panel-body">';

foreach($fields as $key => $field) {
if ($key == 'platform') {
continue;
};

echo '<div class="form-row">';
switch($field['type']) {
case 'checkbox':
Expand Down
Loading