Skip to content

Commit

Permalink
Merge pull request #201 from gustavosbarreto/mount_usb
Browse files Browse the repository at this point in the history
updatehub-server: add cli options for mounting usb disk
  • Loading branch information
otavio committed May 22, 2018
2 parents 7d931b0 + d23fb4e commit 5ebf1df
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 17 deletions.
24 changes: 24 additions & 0 deletions cmd/updatehub-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import (
"fmt"
"net/http"
"os"
"syscall"
"time"

"github.com/OSSystems/pkg/log"
linuxproc "github.com/c9s/goprocinfo/linux"
"github.com/parnurzeal/gorequest"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -61,6 +63,8 @@ func main() {
isQuiet := cmd.PersistentFlags().Bool("quiet", false, "sets the log level to 'error'")
isDebug := cmd.PersistentFlags().Bool("debug", false, "sets the log level to 'debug'")
wait := cmd.PersistentFlags().Bool("wait", false, "wait for UpdateHub Agent")
mount := cmd.PersistentFlags().StringP("mount", "m", "", "device to mount")
fstype := cmd.PersistentFlags().StringP("fstype", "f", "", "filesystem type of device to mount")

err := cmd.Execute()
if err != nil {
Expand Down Expand Up @@ -94,6 +98,26 @@ func main() {
os.Exit(1)
}

if *mount != "" {
mounts, err := linuxproc.ReadMounts("/proc/mounts")
if err != nil {
log.Fatal(err)
os.Exit(1)
}

for _, mount := range mounts.Mounts {
if mount.MountPoint == path {
log.Fatalf("%s: already mounted", path)
os.Exit(1)
}
}

if err = syscall.Mount(*mount, path, *fstype, syscall.MS_RDONLY, ""); err != nil {
log.Fatal(err)
os.Exit(1)
}
}

err = backend.ProcessDirectory()
if err != nil {
log.Fatal(err)
Expand Down
16 changes: 14 additions & 2 deletions cmd/updatehub-server/udev.rules
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
ENV{ID_FS_LABEL}=="updatehub|UPDATEHUB", ENV{DEVTYPE}=="partition", ACTION=="add", RUN+="/bin/mkdir -p /mnt/updatehub", RUN+="/bin/mount -o ro /dev/%k /mnt/updatehub", RUN+="/usr/bin/updatehub-server --wait /mnt/updatehub"
ENV{ID_FS_LABEL}=="updatehub|UPDATEHUB", ENV{DEVTYPE}=="partition", ACTION=="remove", RUN+="/bin/umount /mnt/updatehub", RUN+="/bin/rm -rf /mnt/updatehub"
ENV{ID_FS_LABEL}=="updatehub|UPDATEHUB", \
ENV{DEVTYPE}=="partition", \
ACTION=="add", \
SUBSYSTEM=="block", \
RUN+="/bin/mkdir -p /mnt/updatehub", \
RUN+="/bin/mount -o ro /dev/%k /mnt/updatehub", \
RUN+="/bin/sh -c '/bin/echo /usr/bin/updatehub-server --mount /dev/%k --fstype $env{ID_FS_TYPE} --wait /mnt/updatehub | at -M now'"

ENV{ID_FS_LABEL}=="updatehub|UPDATEHUB", \
ENV{DEVTYPE}=="partition", \
ACTION=="remove", \
RUN+="/usr/bin/killall updatehub-server", \
RUN+="/bin/umount /mnt/updatehub", \
RUN+="/bin/rm -rf /mnt/updatehub"
36 changes: 21 additions & 15 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ import:
- package: github.com/koofr/go-httputils
- package: github.com/updatehub/agent-sdk-go
version: v1
- package: github.com/c9s/goprocinfo
subpackages:
- linux

0 comments on commit 5ebf1df

Please sign in to comment.