Skip to content

Commit

Permalink
Merge pull request #425 from qdraw/feature/202107_bugfixes_10
Browse files Browse the repository at this point in the history
no filestream to log && add mac os script
  • Loading branch information
qdraw authored Jul 15, 2021
2 parents 5f06bdc + 785f003 commit 56ea4d5
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
55 changes: 55 additions & 0 deletions starsky-tools/import/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash

# Mac OS only:
# launchctl load -w ~/Library/LaunchAgents/starsky.importer.plist
# launchctl unload ~/Library/LaunchAgents/starsky.importer.plist
# chmod +x /opt/starsky/import.sh
# replace data_disk with your disk name

BACKUP_DIR="/Volumes/data_disk/storage/fotobiebbak"


LOCKFILE="/tmp/importd.lock"

# lock file
if [ -f $LOCKFILE ]; then
# Control will enter here if file exists.
if [ "$(( $(date +"%s") - $(stat -f "%m" "$LOCKFILE") ))" -gt "3600" ]; then
echo "$LOCKFILE is older then 1 hour"
rm $LOCKFILE
fi

if [ -f $LOCKFILE ]; then
if [ "$(( $(date +"%s") - $(stat -f "%m" "$LOCKFILE") ))" -lt "3600" ]; then
echo "$LOCKFILE is younger than 1 hour"
exit 1
fi
fi
fi

if [ ! -f $LOCKFILE ]; then
touch $LOCKFILE
fi

echo "script started"
# end lock file

find /Volumes -type d -maxdepth 2 -name "DCIM" -print0 |
while IFS= read -r -d '' line;
do
echo "$line"
# just copy
/opt/starsky/starsky/starskyimportercli --recursive true -v true -i false --path $line --structure "/yyyyMMdd_HHmmss_{filenamebase}.ext" --basepath $BACKUP_DIR -x false

# import
/opt/starsky/starsky/starskyimportercli --recursive true -v true --move true -i true --path $line
done

# lock file
echo "script ended"

if [ -f $LOCKFILE ]; then
echo "Lockfile removed"
rm $LOCKFILE
fi
# end lock file
24 changes: 24 additions & 0 deletions starsky-tools/import/starsky.importer.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>starsky.importer</string>
<key>ProgramArguments</key>
<array>
<string>sh</string>
<string>-c</string>
<string>/opt/starsky/starsky-importer.sh</string>
</array>
<key>WatchPaths</key>
<array>
<string>/Volumes/</string>
</array>
<key>StartOnMount</key>
<true/>
<key>StandardErrorPath</key>
<string>/opt/starsky/z-log-starsky-importer.error.log</string>
<key>StandardOutPath</key>
<string>/opt/starsky/z-log-starsky-importer.out.log</string>
</dict>
</plist>
2 changes: 1 addition & 1 deletion starsky/starsky/Controllers/UploadController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public async Task<IActionResult> UploadToFolder()

var writeStatus =
await _iStorage.WriteStreamAsync(tempFileStream, subPath);
_logger.LogInformation($"write {tempFileStream} is {writeStatus}");
_logger.LogInformation($"write {subPath} is {writeStatus}");
await tempFileStream.DisposeAsync();

// clear directory cache
Expand Down

0 comments on commit 56ea4d5

Please sign in to comment.