Skip to content

Commit

Permalink
Merge 0984e46 into af2f4b9
Browse files Browse the repository at this point in the history
  • Loading branch information
midstar committed Feb 17, 2019
2 parents af2f4b9 + 0984e46 commit 28ee055
Show file tree
Hide file tree
Showing 20 changed files with 599 additions and 32 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ tmpcache
main-packr.go
a_main-packr.go
packrd
mediaweb
mediaweb.exe
mediaweb.log
mediaweb_windows_x64_setup.exe
8 changes: 8 additions & 0 deletions MediaWEB.url
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[{000214A0-0000-0000-C000-000000000046}]
Prop3=19,2
[InternetShortcut]
IDList=
URL=http://localhost:9834/
IconIndex=0
HotKey=0
IconFile=C:\Users\Joel\Go\src\github.com\midstar\mediaweb\testmedia\logo.ico
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,12 @@ To uninstall MediaWEB run:

## Download and install on Windows (64bit)

Download mediaweb_windows_x64.zip [here on GitHub](https://github.com/midstar/mediaweb/releases).
Download mediaweb_windows_x64_setup.exe [here on GitHub](https://github.com/midstar/mediaweb/releases).

Update the mediapath setting in mediaweb.conf. You might also want to change the port setting.
Run the installer and follow the instructions.

Just start the mediaweb executable. It will look for the mediaweb.conf in the same folder.

It is currently not possible to run MediaWEB as a system service on Windows without any external software.
To modify changes just edit mediaweb.conf in the installation directory and restart the mediaweb
service in task manager.

## Build from source (any platform)

Expand All @@ -97,6 +96,10 @@ The mediaweb executable and an example configuration file will be in
$GOPATH/src/github.com/midstar/mediaweb. Edit the configuration file
and then run the mediaweb executable.

To install as a Windows service start cmd.exe in administrator mode and run:

scripts\service.bat install

On Linux platforms execute following to install MediaWEB as a service:

sudo sh scripts/service.sh install
Expand All @@ -106,7 +109,7 @@ On Linux platforms execute following to install MediaWEB as a service:

* Create thumbnails for videos (probably using ffmpeg)
* Add support for TLS/SSL
* Add Windows installer (install MediaWEB as a service on Windows)


## Author and license

Expand Down
23 changes: 19 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,33 @@ build_script:
# Windows and publish result on coveralls.io
- cmd: '%GOPATH%/bin/goveralls -coverprofile=coverage.out -service=appveyor-ci -repotoken=%COVERALLS_TOKEN%'
- cmd: '%GOPATH%\src\github.com\midstar\mediaweb\scripts\build.bat %APPVEYOR_BUILD_VERSION%'
- cmd: 7z a mediaweb_windows_x64.zip mediaweb.conf %GOPATH%\bin\mediaweb.exe
- cmd: 'copy scripts\service.bat .'
- cmd: 'copy configs\mediaweb.conf .'
- cmd: 7z a mediaweb_windows_x64.zip mediaweb.exe mediaweb.conf service.bat

# Windows rename tempates directory to secure that packr is working
- cmd: 'rename templates old_templates'


# Windows Test service installation/uninstallation script
- cmd: 'scripts/service_test.bat'

# Windows create windows setup (installer)
- cmd: 'makensis -DVERSION=%APPVEYOR_BUILD_VERSION% %GOPATH%\src\github.com\midstar\mediaweb\scripts\windows_installer.nsi'

# Linux PC/x64
- sh: 'sh $GOPATH/src/github.com/midstar/mediaweb/scripts/build.sh $APPVEYOR_BUILD_VERSION'
- sh: 'cp scripts/service.sh .'
- sh: tar -zcvf mediaweb_linux_x64.tar.gz mediaweb.conf mediaweb service.sh
- sh: 'cp configs/mediaweb.conf .'
- sh: tar -zcvf mediaweb_linux_x64.tar.gz mediaweb mediaweb.conf service.sh

# Test service installation/uninstallation script
# Linux Test service installation/uninstallation script
- sh: 'sudo -E sh scripts/service_test.sh'

# Linux ARM (cross compile from linux x64)
- sh: rm mediaweb
- sh: 'sh $GOPATH/src/github.com/midstar/mediaweb/scripts/build_cross_arm.sh $APPVEYOR_BUILD_VERSION'
- sh: tar -zcvf mediaweb_linux_arm.tar.gz mediaweb.conf mediaweb service.sh
- sh: tar -zcvf mediaweb_linux_arm.tar.gz mediaweb mediaweb.conf service.sh

# Deploy to GitHub (only on master AND on tags)
deploy:
Expand Down Expand Up @@ -76,6 +89,8 @@ for:
artifacts:
- path: mediaweb_windows_x64.zip
name: mediaweb_windows_x64.zip
- path: mediaweb_windows_x64_setup.exe
name: mediaweb_windows_x64_setup.exe

# Special configurations for Linux
-
Expand Down
36 changes: 36 additions & 0 deletions configs/mediaweb.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#######################################################
# This is a configuration file for mediaweb
#######################################################

# Server network port.
# This parameter is MANDATORY
port = 9834

# Media path, i.e. where is your media located
# This parameter is MANADTORY
#
# For example:
# mediapath = /home/fobar/pictures
# mediapath = c:\users\fobar\pictures
mediapath = pictures

# Thumb cache path is by default your operating systems
# temp folder + mediaweb. Uncomment below to set to
# another location. Not used if enablethumbcache = off.
# thumbpath = tmpcache

# Thumb cache is by default on. Uncomment below to
# disable thumb cache
#enablethumbcache = off

# Auto rotate of JPEG is by default on. Uncomment below
# to disable auto rotate of JPEG.
#autorotate = off

# Logging is by default output on stderr.
logfile = mediaweb.log

# Logging level is by default info. Available levels
# are trace, debug, info, warn, error and panic.
#loglevel = trace

5 changes: 2 additions & 3 deletions main.go → main_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/midstar/llog"
)

func main() {
func mainCommon() *WebAPI {
s := loadSettings(findConfFile())
llog.SetLevel(s.logLevel)
if s.logFile != "" {
Expand All @@ -17,6 +17,5 @@ func main() {
media := createMedia(s.mediaPath, s.thumbPath, s.enableThumbCache, s.autoRotate)
box := packr.New("templates", "./templates")
webAPI := CreateWebAPI(s.port, "templates", media, box)
httpServerDone := webAPI.Start()
<-httpServerDone // Block until http server is done
return webAPI
}
8 changes: 8 additions & 0 deletions main_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Main method for Linux systems
package main

func main() {
webAPI := mainCommon()
httpServerDone := webAPI.Start()
<-httpServerDone // Block until http server is done
}
60 changes: 60 additions & 0 deletions main_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Main method for Windows systems
package main

import (
"log"
"os"

"github.com/kardianos/service"
)

var logger service.Logger

type program struct {
webAPI *WebAPI
workingDir string
}

func (p *program) Start(s service.Service) error {
// Start should not block. Do the actual work async.
if p.workingDir != "" {
os.Chdir(p.workingDir)
}
p.webAPI = mainCommon()
go p.run()
return nil
}
func (p *program) run() {
p.webAPI.Start()
}
func (p *program) Stop(s service.Service) error {
// Stop should not block. Return with a few seconds.
p.webAPI.Stop()
return nil
}

func main() {
workingDir := ""
if len(os.Args) > 1 {
workingDir = os.Args[1]
}
svcConfig := &service.Config{
Name: "MediaWEB",
DisplayName: "MediaWEB",
Description: "WEB server for photos and videos",
}

prg := &program{workingDir: workingDir}
s, err := service.New(prg, svcConfig)
if err != nil {
log.Fatal(err)
}
logger, err = s.Logger(nil)
if err != nil {
log.Fatal(err)
}
err = s.Run()
if err != nil {
logger.Error(err)
}
}
3 changes: 1 addition & 2 deletions media.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,7 @@ func (m *Media) writeEXIFThumbnail(w io.Writer, relativeFilePath string) error {
case 8:
outImg = imaging.Rotate90(img)
}
err = imaging.Encode(w, outImg, imaging.JPEG)
//return err
imaging.Encode(w, outImg, imaging.JPEG)
} else {
// No rotation is needed
w.Write(thumbBytes)
Expand Down
10 changes: 5 additions & 5 deletions media_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func TestFullPath(t *testing.T) {
assertExpectNoErr(t, "unable to get valid full path", err)
assertEqualsStr(t, "invalid path", "afile.jpg", p)

p, err = media.getFullMediaPath("../../secret_file")
_, err = media.getFullMediaPath("../../secret_file")
assertExpectErr(t, "hackers shall not be allowed", err)

// Relative path
Expand All @@ -162,7 +162,7 @@ func TestFullPath(t *testing.T) {
assertExpectNoErr(t, "unable to get valid full path", err)
assertEqualsStr(t, "invalid path", "arelative/path/afile.jpg", p)

p, err = media.getFullMediaPath("../../secret_file")
_, err = media.getFullMediaPath("../../secret_file")
assertExpectErr(t, "hackers shall not be allowed", err)

// Absolute path
Expand All @@ -171,7 +171,7 @@ func TestFullPath(t *testing.T) {
assertExpectNoErr(t, "unable to get valid full path", err)
assertEqualsStr(t, "invalid path", "/root/absolute/path/afile.jpg", p)

p, err = media.getFullMediaPath("../../secret_file")
_, err = media.getFullMediaPath("../../secret_file")
assertExpectErr(t, "hackers shall not be allowed", err)
}

Expand All @@ -190,10 +190,10 @@ func TestThumbnailPath(t *testing.T) {
assertExpectNoErr(t, "", err)
assertEqualsStr(t, "", "/d/thumbpath/subdrive/_myimage.jpg", thumbPath)

thumbPath, err = media.thumbnailPath("subdrive/myimage")
_, err = media.thumbnailPath("subdrive/myimage")
assertExpectErr(t, "", err)

thumbPath, err = media.thumbnailPath("subdrive/../../hacker")
_, err = media.thumbnailPath("subdrive/../../hacker")
assertExpectErr(t, "", err)
}

Expand Down
2 changes: 1 addition & 1 deletion mediaweb.conf
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ thumbpath = tmpcache

# Logging is by default output on stderr. Uncomment
# below to log to a file.
#logfile = /yourdrive/mediaweb.log
#logfile = mediaweb.log

# Logging level is by default info. Available levels
# are trace, debug, info, warn, error and panic.
Expand Down
13 changes: 8 additions & 5 deletions scripts/build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ for /f %%i in ('git rev-parse HEAD') do set GITHASH=%%i
echo git hash: %GITHASH%
echo building / installing
cd %GOPATH%\src\github.com\midstar\mediaweb
REM packr2 has a bug in Windows where absolute paths are generated instead
REM of relative paths. We use --legacy to fix this
set PACKRCMD=packr2 --legacy
set PACKRCMD=packr2
echo %PACKRCMD%
%PACKRCMD%
type main-packr.go
set INSTALLCMD=go install -ldflags="-X 'main.applicationBuildTime=%DATE% %TIME%' -X main.applicationVersion=%VERSION% -X main.applicationGitHash=%GITHASH%" github.com/midstar/mediaweb
REM There is a bug in packr that creates absolute paths in main-packr.go on some
REM build machines (uncertain why). Replace main-packr.go with a new file
echo Replacing main-packr.go due to a bug in packr library
echo // +build !skippackr > main-packr.go
echo package main >> main-packr.go
echo import _ "github.com/midstar/mediaweb/packrd" >> main-packr.go
set INSTALLCMD=go build -ldflags="-X 'main.applicationBuildTime=%DATE% %TIME%' -X main.applicationVersion=%VERSION% -X main.applicationGitHash=%GITHASH%" github.com/midstar/mediaweb
echo %INSTALLCMD%
%INSTALLCMD%
3 changes: 2 additions & 1 deletion scripts/install_deps.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ go get github.com/midstar/gocfg
go get github.com/disintegration/imaging
go get github.com/rwcarlsen/goexif/exif
go get -u github.com/gobuffalo/packr/v2/...
go get -u github.com/gobuffalo/packr/v2/packr2
go get -u github.com/gobuffalo/packr/v2/packr2
go get github.com/kardianos/service
82 changes: 82 additions & 0 deletions scripts/service.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
@echo off

REM MediaWEB windows service (un)installation batch script

if [%1] EQU [install] (

if not exist mediaweb.exe (
echo ERROR! mediaweb.exe needs to be in current directory
exit /b 1
)

if not exist mediaweb.conf (
echo ERROR! mediaweb.conf needs to be in current directory
exit /b 1
)

echo ------------------------------------------
echo Installing MediaWEB windows service
echo ------------------------------------------
sc create mediaweb binpath="\"%cd%\mediaweb.exe\" \"%cd%\"" start= auto DisplayName= "MediaWEB" || (
echo ERROR! Unable to create mediaweb service
exit /b 1
)
sc description mediaweb "MediaWEB Service" || (
echo ERROR! Unable to create description for mediaweb service
echo.
echo Make sure you are running cmd.exe as an administrator
exit /b 1
)
sc start mediaweb || (
echo ERROR! Unable to start mediaweb service
exit /b 1
)
sc query mediaweb || (
echo ERROR! Unable to query mediaweb service
exit /b 1
)

echo MediaWEB service successfully installed!
exit /b 0

) else if [%1] EQU [uninstall] (

echo ------------------------------------------
echo Uninstalling MediaWEB windows service
echo ------------------------------------------

sc stop mediaweb
sc delete mediaweb || (
exit /b 1
)

echo Uninstallation complete!
exit /b 0

) else if [%1] EQU [] (
call :print_usage
) else (
echo ERROR! Unknown command '%1'
call :print_usage
)

exit /b 0

:print_usage
echo.
echo Usage:
echo.
echo.NOTE! Start cmd.exe with administrator privileges.
echo.
echo.Update mediaweb.conf before installation.
echo.
echo For MediaWEB service installation:
echo.
echo service.bat install
echo.
echo.
echo For MediaWEB service uninstallation:
echo.
echo sudo sh service.sh uninstall
echo.
exit /b 1

0 comments on commit 28ee055

Please sign in to comment.