mirror of
https://github.com/IceWhaleTech/CasaOS.git
synced 2025-11-16 03:23:13 +00:00
update usb auto mount shell
This commit is contained in:
parent
4cfd2ec2f6
commit
2f429972ad
2
go.mod
2
go.mod
@ -38,6 +38,7 @@ require (
|
|||||||
github.com/jinzhu/copier v0.3.2
|
github.com/jinzhu/copier v0.3.2
|
||||||
github.com/json-iterator/go v1.1.11 // indirect
|
github.com/json-iterator/go v1.1.11 // indirect
|
||||||
github.com/klauspost/compress v1.13.6 // indirect
|
github.com/klauspost/compress v1.13.6 // indirect
|
||||||
|
github.com/kr/pretty v0.2.1
|
||||||
github.com/kr/text v0.2.0 // indirect
|
github.com/kr/text v0.2.0 // indirect
|
||||||
github.com/leodido/go-urn v1.2.1 // indirect
|
github.com/leodido/go-urn v1.2.1 // indirect
|
||||||
github.com/lucas-clemente/quic-go v0.25.0
|
github.com/lucas-clemente/quic-go v0.25.0
|
||||||
@ -49,6 +50,7 @@ require (
|
|||||||
github.com/opencontainers/image-spec v1.0.2 // indirect
|
github.com/opencontainers/image-spec v1.0.2 // indirect
|
||||||
github.com/opencontainers/selinux v1.8.5 // indirect
|
github.com/opencontainers/selinux v1.8.5 // indirect
|
||||||
github.com/patrickmn/go-cache v2.1.0+incompatible
|
github.com/patrickmn/go-cache v2.1.0+incompatible
|
||||||
|
github.com/pilebones/go-udev v0.9.0
|
||||||
github.com/pkg/errors v0.9.1
|
github.com/pkg/errors v0.9.1
|
||||||
github.com/prometheus/procfs v0.7.3 // indirect
|
github.com/prometheus/procfs v0.7.3 // indirect
|
||||||
github.com/robfig/cron v1.2.0
|
github.com/robfig/cron v1.2.0
|
||||||
|
|||||||
2
go.sum
2
go.sum
@ -706,6 +706,8 @@ github.com/pelletier/go-toml v1.8.1/go.mod h1:T2/BmBdy8dvIRq1a/8aqjN41wvWlN4lrap
|
|||||||
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
|
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
|
||||||
github.com/pierrec/lz4/v4 v4.1.2 h1:qvY3YFXRQE/XB8MlLzJH7mSzBs74eA2gg52YTk6jUPM=
|
github.com/pierrec/lz4/v4 v4.1.2 h1:qvY3YFXRQE/XB8MlLzJH7mSzBs74eA2gg52YTk6jUPM=
|
||||||
github.com/pierrec/lz4/v4 v4.1.2/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
|
github.com/pierrec/lz4/v4 v4.1.2/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
|
||||||
|
github.com/pilebones/go-udev v0.9.0 h1:N1uEO/SxUwtIctc0WLU0t69JeBxIYEYnj8lT/Nabl9Q=
|
||||||
|
github.com/pilebones/go-udev v0.9.0/go.mod h1:T2eI2tUSK0hA2WS5QLjXJUfQkluZQu+18Cqvem3CaXI=
|
||||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pkg/errors v0.8.1-0.20171018195549-f15c970de5b7/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.8.1-0.20171018195549-f15c970de5b7/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
|
|||||||
2
main.go
2
main.go
@ -95,7 +95,7 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
go route.SocketInit(service.NotifyMsg)
|
go route.SocketInit(service.NotifyMsg)
|
||||||
|
go route.MonitoryUSB()
|
||||||
//model.Setup()
|
//model.Setup()
|
||||||
//gredis.Setup()
|
//gredis.Setup()
|
||||||
r := route.InitRouter()
|
r := route.InitRouter()
|
||||||
|
|||||||
33
pkg/utils/udev_helper.go
Normal file
33
pkg/utils/udev_helper.go
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* @Author: LinkLeong link@icewhale.org
|
||||||
|
* @Date: 2022-08-10 16:06:12
|
||||||
|
* @LastEditors: LinkLeong
|
||||||
|
* @LastEditTime: 2022-08-10 16:11:37
|
||||||
|
* @FilePath: /CasaOS/pkg/utils/udev_helper.go
|
||||||
|
* @Description:
|
||||||
|
* @Website: https://www.casaos.io
|
||||||
|
* Copyright (c) 2022 by icewhale, All Rights Reserved.
|
||||||
|
*/
|
||||||
|
package utils
|
||||||
|
|
||||||
|
// func getOptionnalMatcher() (matcher netlink.Matcher, err error) {
|
||||||
|
// if filePath == nil || *filePath == "" {
|
||||||
|
// return nil, nil
|
||||||
|
// }
|
||||||
|
|
||||||
|
// stream, err := ioutil.ReadFile(*filePath)
|
||||||
|
// if err != nil {
|
||||||
|
// return nil, err
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if stream == nil {
|
||||||
|
// return nil, fmt.Errorf("Empty, no rules provided in \"%s\", err: %w", *filePath, err)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// var rules netlink.RuleDefinitions
|
||||||
|
// if err := json.Unmarshal(stream, &rules); err != nil {
|
||||||
|
// return nil, fmt.Errorf("Wrong rule syntax, err: %w", err)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return &rules, nil
|
||||||
|
// }
|
||||||
@ -2,7 +2,7 @@
|
|||||||
* @Author: LinkLeong link@icewhale.com
|
* @Author: LinkLeong link@icewhale.com
|
||||||
* @Date: 2022-07-01 15:11:36
|
* @Date: 2022-07-01 15:11:36
|
||||||
* @LastEditors: LinkLeong
|
* @LastEditors: LinkLeong
|
||||||
* @LastEditTime: 2022-08-03 14:49:15
|
* @LastEditTime: 2022-08-10 17:19:27
|
||||||
* @FilePath: /CasaOS/route/periodical.go
|
* @FilePath: /CasaOS/route/periodical.go
|
||||||
* @Description:
|
* @Description:
|
||||||
* @Website: https://www.casaos.io
|
* @Website: https://www.casaos.io
|
||||||
@ -11,14 +11,20 @@
|
|||||||
package route
|
package route
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"github.com/IceWhaleTech/CasaOS/model"
|
"github.com/IceWhaleTech/CasaOS/model"
|
||||||
|
"github.com/IceWhaleTech/CasaOS/pkg/utils/loger"
|
||||||
"github.com/IceWhaleTech/CasaOS/service"
|
"github.com/IceWhaleTech/CasaOS/service"
|
||||||
|
"github.com/pilebones/go-udev/netlink"
|
||||||
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
func SendNetINfoBySocket() {
|
func SendNetINfoBySocket() {
|
||||||
@ -257,3 +263,38 @@ func SendAllHardwareStatusBySocket() {
|
|||||||
service.MyService.Notify().SendAllHardwareStatusBySocket(summary, usb, memInfo, cpuData, newNet)
|
service.MyService.Notify().SendAllHardwareStatusBySocket(summary, usb, memInfo, cpuData, newNet)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
func MonitoryUSB() {
|
||||||
|
var matcher netlink.Matcher
|
||||||
|
|
||||||
|
conn := new(netlink.UEventConn)
|
||||||
|
if err := conn.Connect(netlink.UdevEvent); err != nil {
|
||||||
|
loger.Error("udev err", zap.Any("Unable to connect to Netlink Kobject UEvent socket", err))
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
queue := make(chan netlink.UEvent)
|
||||||
|
errors := make(chan error)
|
||||||
|
quit := conn.Monitor(queue, errors, matcher)
|
||||||
|
|
||||||
|
signals := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
|
||||||
|
go func() {
|
||||||
|
<-signals
|
||||||
|
close(quit)
|
||||||
|
os.Exit(0)
|
||||||
|
}()
|
||||||
|
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case uevent := <-queue:
|
||||||
|
if uevent.Env["DEVTYPE"] == "disk" {
|
||||||
|
time.Sleep(time.Microsecond * 500)
|
||||||
|
SendUSBBySocket()
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
case err := <-errors:
|
||||||
|
loger.Error("udev err", zap.Any("err", err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@ -233,9 +233,9 @@ func (s *systemService) GetTimeZone() string {
|
|||||||
|
|
||||||
func (s *systemService) ExecUSBAutoMountShell(state string) {
|
func (s *systemService) ExecUSBAutoMountShell(state string) {
|
||||||
if state == "False" {
|
if state == "False" {
|
||||||
command2.OnlyExec("source " + config.AppInfo.ShellPath + "/helper.sh ;USB_Remove_File")
|
command2.OnlyExec("source " + config.AppInfo.ShellPath + "/helper.sh ;USB_Stop_Auto")
|
||||||
} else {
|
} else {
|
||||||
command2.OnlyExec("source " + config.AppInfo.ShellPath + "/helper.sh ;USB_Move_File")
|
command2.OnlyExec("source " + config.AppInfo.ShellPath + "/helper.sh ;USB_Start_Auto")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -330,17 +330,16 @@ TarFolder() {
|
|||||||
du -sh /DATA
|
du -sh /DATA
|
||||||
}
|
}
|
||||||
|
|
||||||
USB_Move_File() {
|
USB_Start_Auto() {
|
||||||
((EUID)) && sudo_cmd="sudo"
|
((EUID)) && sudo_cmd="sudo"
|
||||||
$sudo_cmd cp -rf /casaOS/server/shell/11-usb-mount.rules /etc/udev/rules.d/
|
$sudo_cmd systemctl enable devmon@devmon
|
||||||
$sudo_cmd chmod +x /casaOS/server/shell/usb-mount.sh
|
$sudo_cmd} systemctl start devmon@devmon
|
||||||
$sudo_cmd cp -rf /casaOS/server/shell/usb-mount@.service /etc/systemd/system/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
USB_Remove_File() {
|
USB_Stop_Auto() {
|
||||||
((EUID)) && sudo_cmd="sudo"
|
((EUID)) && sudo_cmd="sudo"
|
||||||
$sudo_cmd rm -fr /etc/udev/rules.d/11-usb-mount.rules
|
$sudo_cmd} systemctl stop devmon@devmon
|
||||||
$sudo_cmd rm -fr /etc/systemd/system/usb-mount@.service
|
$sudo_cmd systemctl disable devmon@devmon
|
||||||
}
|
}
|
||||||
|
|
||||||
GetDeviceTree(){
|
GetDeviceTree(){
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user