From 2508a4e07dd367d01e96b7cce65256e032b86a28 Mon Sep 17 00:00:00 2001 From: link Date: Mon, 6 Dec 2021 17:08:36 +0800 Subject: [PATCH] Pull Submit --- go.mod | 4 +-- go.sum | 11 ++++---- pkg/utils/oasis_err/e.go | 2 ++ route/route.go | 4 +++ route/v1/app.go | 23 ++++++++++++++++ route/v1/disk.go | 13 +++++---- route/v1/docker.go | 13 ++------- route/v1/system.go | 51 +++++++++++++++++++++++++++++++++- service/app.go | 59 +++++++++++++++++++++++++++++++++++++++- service/disk.go | 6 ++-- service/docker.go | 14 ++++++---- service/system.go | 12 ++++++++ service/zima_info.go | 1 - shell/assist.sh | 25 +++++++++++++++++ shell/tools.sh | 2 +- shell/usb-mount.sh | 6 ++-- shell/usb-mount@.service | 4 +-- 17 files changed, 209 insertions(+), 41 deletions(-) create mode 100644 shell/assist.sh diff --git a/go.mod b/go.mod index 5f58af2c3..51e15df50 100644 --- a/go.mod +++ b/go.mod @@ -48,8 +48,8 @@ require ( github.com/smartystreets/goconvey v1.6.4 // indirect github.com/swaggo/gin-swagger v1.3.0 github.com/swaggo/swag v1.7.3 - github.com/tidwall/gjson v1.8.0 - github.com/tidwall/pretty v1.2.0 // indirect + github.com/tidwall/gjson v1.10.2 + github.com/tidwall/sjson v1.2.3 github.com/tklauser/go-sysconf v0.3.6 // indirect github.com/ugorji/go v1.2.6 // indirect go.opencensus.io v0.23.0 // indirect diff --git a/go.sum b/go.sum index f349c6da7..3b533e6d5 100644 --- a/go.sum +++ b/go.sum @@ -741,13 +741,14 @@ github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8/go.mod h1:hkRG github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww= github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww= github.com/tchap/go-patricia v2.2.6+incompatible/go.mod h1:bmLyhP68RS6kStMGxByiQ23RP/odRBOTVjwp2cDyi6I= -github.com/tidwall/gjson v1.8.0 h1:Qt+orfosKn0rbNTZqHYDqBrmm3UDA4KRkv70fDzG+PQ= -github.com/tidwall/gjson v1.8.0/go.mod h1:5/xDoumyyDNerp2U36lyolv46b3uF/9Bu6OfyQ9GImk= -github.com/tidwall/match v1.0.3 h1:FQUVvBImDutD8wJLN6c5eMzWtjgONK9MwIBCOrUJKeE= -github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= -github.com/tidwall/pretty v1.1.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= +github.com/tidwall/gjson v1.10.2 h1:APbLGOM0rrEkd8WBw9C24nllro4ajFuJu0Sc9hRz8Bo= +github.com/tidwall/gjson v1.10.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= +github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= +github.com/tidwall/sjson v1.2.3 h1:5+deguEhHSEjmuICXZ21uSSsXotWMA0orU783+Z7Cp8= +github.com/tidwall/sjson v1.2.3/go.mod h1:5WdjKx3AQMvCJ4RG6/2UYT7dLrGvJUV1x4jdTAyGvZs= github.com/tklauser/go-sysconf v0.3.4/go.mod h1:Cl2c8ZRWfHD5IrfHo9VN+FX9kCFjIOyVklgXycLB6ek= github.com/tklauser/go-sysconf v0.3.6 h1:oc1sJWvKkmvIxhDHeKWvZS4f6AW+YcoguSfRF2/Hmo4= github.com/tklauser/go-sysconf v0.3.6/go.mod h1:MkWzOF4RMCshBAMXuhXJs64Rte09mITnppBXY/rYEFI= diff --git a/pkg/utils/oasis_err/e.go b/pkg/utils/oasis_err/e.go index 96cf5724c..fc589f804 100644 --- a/pkg/utils/oasis_err/e.go +++ b/pkg/utils/oasis_err/e.go @@ -16,6 +16,7 @@ const ( DIR_ALREADY_EXISTS = 20001 FILE_ALREADY_EXISTS = 20002 FILE_OR_DIR_EXISTS = 20003 + PORT_IS_OCCUPIED = 20004 //zerotier GET_TOKEN_ERROR = 30001 @@ -49,6 +50,7 @@ var MsgFlags = map[int]string{ DIR_ALREADY_EXISTS: "Directory already exists", FILE_ALREADY_EXISTS: "File already exists", FILE_OR_DIR_EXISTS: "File or directory already exists", + PORT_IS_OCCUPIED: "Port is occupied", //zerotier GET_TOKEN_ERROR: "Get token error,Please log in to zerotier's official website to confirm whether the account is available", diff --git a/route/route.go b/route/route.go index 87b7adcd0..cbd5e0e69 100644 --- a/route/route.go +++ b/route/route.go @@ -141,6 +141,8 @@ func InitRouter() *gin.Engine { { //获取我的已安装的列表 v1AppGroup.GET("/mylist", v1.MyAppList) + // + v1AppGroup.GET("/usage", v1.AppUsageList) //app详情 v1AppGroup.GET("/appinfo/:id", v1.AppInfo) //获取未安装的列表 @@ -192,6 +194,8 @@ func InitRouter() *gin.Engine { v1SysGroup.POST("/config", v1.PostSetSystemConfig) v1SysGroup.GET("/widget/config", v1.GetWidgetConfig) v1SysGroup.POST("/widget/config", v1.PostSetWidgetConfig) + v1SysGroup.PUT("/port", v1.PutCasaOSPort) + v1SysGroup.POST("/kill", v1.PostKillCasaOS) } v1FileGroup := v1Group.Group("/file") v1FileGroup.Use() diff --git a/route/v1/app.go b/route/v1/app.go index 6761e1195..be9682266 100644 --- a/route/v1/app.go +++ b/route/v1/app.go @@ -103,6 +103,18 @@ func MyAppList(c *gin.Context) { c.JSON(http.StatusOK, &model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS), Data: list}) } +// @Summary my app hardware usage list +// @Produce application/json +// @Accept application/json +// @Tags app +// @Security ApiKeyAuth +// @Success 200 {string} string "ok" +// @Router /app/usage [get] +func AppUsageList(c *gin.Context) { + list := service.MyService.App().GetHardwareUsage() + c.JSON(http.StatusOK, &model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS), Data: list}) +} + // @Summary 应用详情 // @Produce application/json // @Accept application/json @@ -212,3 +224,14 @@ func ShareAppFile(c *gin.Context) { content := service.MyService.OAPI().ShareAppFile(str) c.JSON(http.StatusOK, json.RawMessage(content)) } + +// @Summary Resource Usage +// @Produce application/json +// @Accept application/json +// @Tags app +// @Security ApiKeyAuth +// @Success 200 {string} string "ok" +// @Router /app/share [post] +func AppListResourceUsage() { + +} diff --git a/route/v1/disk.go b/route/v1/disk.go index b6f82faab..de0b6dc45 100644 --- a/route/v1/disk.go +++ b/route/v1/disk.go @@ -1,13 +1,14 @@ package v1 import ( + "net/http" + "strconv" + "github.com/IceWhaleTech/CasaOS/model" "github.com/IceWhaleTech/CasaOS/pkg/utils/oasis_err" "github.com/IceWhaleTech/CasaOS/service" "github.com/gin-gonic/gin" "github.com/shirou/gopsutil/v3/disk" - "net/http" - "strconv" ) // @Summary 获取磁盘列表 @@ -59,7 +60,7 @@ func GetPlugInDisk(c *gin.Context) { c.JSON(http.StatusOK, model.Result{Success: oasis_err.SUCCESS, Message: oasis_err.GetMsg(oasis_err.SUCCESS), Data: lst}) } -// @Summary 获取磁盘列表 +// @Summary get disk list // @Produce application/json // @Accept application/json // @Tags disk @@ -76,12 +77,12 @@ func GetPlugInDisks(c *gin.Context) { c.JSON(http.StatusOK, model.Result{Success: oasis_err.SUCCESS, Message: oasis_err.GetMsg(oasis_err.SUCCESS), Data: result}) } -// @Summary 磁盘详情 +// @Summary disk detail // @Produce application/json // @Accept application/json // @Tags disk // @Security ApiKeyAuth -// @Param path query string true "要获取的磁盘详情 例如/dev/sda" +// @Param path query string true "for example /dev/sda" // @Success 200 {string} string "ok" // @Router /disk/info [get] func GetDiskInfo(c *gin.Context) { @@ -93,7 +94,7 @@ func GetDiskInfo(c *gin.Context) { c.JSON(http.StatusOK, model.Result{Success: oasis_err.SUCCESS, Message: oasis_err.GetMsg(oasis_err.SUCCESS), Data: m}) } -// @Summary 磁盘详情 +// @Summary format disk // @Produce application/json // @Accept multipart/form-data // @Tags disk diff --git a/route/v1/docker.go b/route/v1/docker.go index 59001c08b..08e760fb0 100644 --- a/route/v1/docker.go +++ b/route/v1/docker.go @@ -2,7 +2,6 @@ package v1 import ( "bytes" - "encoding/json" json2 "encoding/json" "net/http" "reflect" @@ -677,7 +676,7 @@ func UnInstallApp(c *gin.Context) { } //step:删除容器 - err = service.MyService.Docker().DockerContainerRemove(appId) + err = service.MyService.Docker().DockerContainerRemove(appId, false) if err != nil { c.JSON(http.StatusOK, model.Result{Success: oasis_err2.UNINSTALL_APP_ERROR, Message: oasis_err2.GetMsg(oasis_err2.UNINSTALL_APP_ERROR), Data: err.Error()}) return @@ -908,16 +907,10 @@ func UpdateSetting(c *gin.Context) { //如果容器端口均未修改,这不进行处理 portsStr, _ := json2.Marshal(m.Ports) - list := []model.PathMap{} - json.Unmarshal([]byte(appInfo.Volumes), &list) - for i := 0; i < len(list); i++ { - list[i].Path = docker.GetDir(id, list[i].ContainerPath) - } envsStr, _ := json2.Marshal(m.Envs) volumesStr, _ := json2.Marshal(m.Volumes) devicesStr, _ := json2.Marshal(m.Devices) - listStr, _ := json2.Marshal(list) - if !reflect.DeepEqual(string(portsStr), appInfo.Ports) || !reflect.DeepEqual(string(envsStr), appInfo.Envs) || !reflect.DeepEqual(volumesStr, listStr) || m.PortMap != appInfo.PortMap || m.NetworkModel != appInfo.NetModel { + if !reflect.DeepEqual(string(portsStr), appInfo.Ports) || !reflect.DeepEqual(string(envsStr), appInfo.Envs) || !reflect.DeepEqual(string(volumesStr), appInfo.Volumes) || m.PortMap != appInfo.PortMap || m.NetworkModel != appInfo.NetModel { var newUUid = uuid.NewV4().String() var err error @@ -934,7 +927,7 @@ func UpdateSetting(c *gin.Context) { return } - err = service.MyService.Docker().DockerContainerRemove(id) + err = service.MyService.Docker().DockerContainerRemove(id, true) if err != nil { c.JSON(http.StatusOK, model.Result{Success: oasis_err2.ERROR, Message: oasis_err2.GetMsg(oasis_err2.ERROR)}) return diff --git a/route/v1/system.go b/route/v1/system.go index 69505eb16..7ddd40f78 100644 --- a/route/v1/system.go +++ b/route/v1/system.go @@ -4,12 +4,14 @@ import ( "encoding/json" "fmt" "net/http" + "os" "strconv" "time" "github.com/IceWhaleTech/CasaOS/model" "github.com/IceWhaleTech/CasaOS/pkg/config" "github.com/IceWhaleTech/CasaOS/pkg/utils/oasis_err" + port2 "github.com/IceWhaleTech/CasaOS/pkg/utils/port" "github.com/IceWhaleTech/CasaOS/pkg/utils/version" "github.com/IceWhaleTech/CasaOS/service" model2 "github.com/IceWhaleTech/CasaOS/service/model" @@ -80,7 +82,7 @@ func GetCasaOSErrorLogs(c *gin.Context) { // @Produce application/json // @Accept multipart/form-data // @Tags sys -// @Param file formData file true "用户头像" +// @Param config formData string true "config json string" // @Security ApiKeyAuth // @Success 200 {string} string "ok" // @Router /sys/changhead [post] @@ -135,6 +137,42 @@ func PostSetWidgetConfig(c *gin.Context) { }) } +// @Summary edit casaos server port +// @Produce application/json +// @Accept application/json +// @Tags sys +// @Security ApiKeyAuth +// @Param port formData file true "用户头像" +// @Success 200 {string} string "ok" +// @Router /sys/widget/config [post] +func PutCasaOSPort(c *gin.Context) { + port, err := strconv.Atoi(c.PostForm("port")) + if err != nil { + c.JSON(http.StatusOK, + model.Result{ + Success: oasis_err.ERROR, + Message: err.Error(), + }) + return + } + + isAvailable := port2.IsPortAvailable(port, "tcp") + if !isAvailable { + c.JSON(http.StatusOK, + model.Result{ + Success: oasis_err.PORT_IS_OCCUPIED, + Message: oasis_err.GetMsg(oasis_err.PORT_IS_OCCUPIED), + }) + return + } + service.MyService.System().UpSystemPort(strconv.Itoa(port)) + c.JSON(http.StatusOK, + model.Result{ + Success: oasis_err.SUCCESS, + Message: oasis_err.GetMsg(oasis_err.SUCCESS), + }) +} + // @Summary 检查是否进入引导状态 // @Produce application/json // @Accept application/json @@ -156,3 +194,14 @@ func GetGuideCheck(c *gin.Context) { Data: data, }) } + +// @Summary active killing casaos +// @Produce application/json +// @Accept application/json +// @Tags sys +// @Security ApiKeyAuth +// @Success 200 {string} string "ok" +// @Router /sys/kill [post] +func PostKillCasaOS(c *gin.Context) { + os.Exit(0) +} diff --git a/service/app.go b/service/app.go index c7f065958..5a1744f1e 100644 --- a/service/app.go +++ b/service/app.go @@ -2,7 +2,10 @@ package service import ( "context" + "io/ioutil" + "runtime" "strings" + "sync" "time" "github.com/IceWhaleTech/CasaOS/pkg/config" @@ -13,6 +16,7 @@ import ( "github.com/docker/docker/api/types/filters" client2 "github.com/docker/docker/client" "github.com/pkg/errors" + "github.com/tidwall/sjson" "gorm.io/gorm" ) @@ -27,6 +31,7 @@ type AppService interface { GetSimpleContainerInfo(name string) (types.Container, error) DelAppConfigDir(path string) GetSystemAppList() *[]model2.MyAppList + GetHardwareUsage() []string } type appStruct struct { @@ -48,7 +53,6 @@ func (a *appStruct) GetMyList(index, size int, position bool) *[]model2.MyAppLis if err != nil { a.log.Error("获取docker容器失败", "app.getmylist", "line:42", err) } - //获取本地数据库应用 var lm []model2.AppListDBModel @@ -231,6 +235,59 @@ func (a *appStruct) RemoveContainerById(id string) { a.db.Table(model2.CONTAINERTABLENAME).Where("custom_id = ?", id).Delete(&model2.AppListDBModel{}) } +func (a *appStruct) GetHardwareUsage() []string { + + var dataStr []string + cli, err := client2.NewClientWithOpts(client2.FromEnv) + if err != nil { + return dataStr + } + defer cli.Close() + + lock := &sync.Mutex{} + var lm []model2.AppListDBModel + var count = 0 + a.db.Table(model2.CONTAINERTABLENAME).Select("title,icon,container_id").Find(&lm) + for _, v := range lm { + go func(lock *sync.Mutex, id, title, icon string) { + stats, err := cli.ContainerStats(context.Background(), id, false) + if err != nil { + lock.Lock() + count++ + lock.Unlock() + return + } + defer stats.Body.Close() + statsByte, err := ioutil.ReadAll(stats.Body) + if err != nil { + lock.Lock() + count++ + lock.Unlock() + return + } + lock.Lock() + statsByte, _ = sjson.SetBytes(statsByte, "icon", icon) + statsByte, _ = sjson.SetBytes(statsByte, "title", title) + dataStr = append(dataStr, string(statsByte)) + count++ + lock.Unlock() + }(lock, v.ContainerId, v.Title, v.Icon) + } + + for { + lock.Lock() + c := count + lock.Unlock() + + runtime.Gosched() + if c == len(lm) { + break + } + } + return dataStr + +} + // init install func Init() { diff --git a/service/disk.go b/service/disk.go index cf28bb601..180888462 100644 --- a/service/disk.go +++ b/service/disk.go @@ -90,7 +90,7 @@ func (d *diskService) GetDiskInfoByPath(path string) *disk.UsageStat { return diskInfo } -//获取磁盘信息 +//get disk details func (d *diskService) LSBLK() []model.LSBLKModel { str := command2.ExecLSBLK() if str == nil { @@ -111,7 +111,7 @@ func (d *diskService) LSBLK() []model.LSBLKModel { var health = true for _, i := range m { - if i.Children != nil { + if i.Type != "loop" { fsused = 0 for _, child := range i.Children { if child.RM { @@ -134,7 +134,7 @@ func (d *diskService) LSBLK() []model.LSBLKModel { i.Children = c if fsused > 0 { i.UsedPercent, err = strconv.ParseFloat(fmt.Sprintf("%.4f", float64(fsused)/float64(i.Size)), 64) - fmt.Println(err) + d.log.Fatal("diskservice_lsblk_fsused", err) } n = append(n, i) health = true diff --git a/service/docker.go b/service/docker.go index a9b830265..3a5f0c057 100644 --- a/service/docker.go +++ b/service/docker.go @@ -53,7 +53,7 @@ type DockerService interface { DockerListByImage(image, version string) (*types.Container, error) DockerContainerInfo(name string) (*types.ContainerJSON, error) DockerImageRemove(name string) error - DockerContainerRemove(name string) error + DockerContainerRemove(name string, update bool) error DockerContainerStop(id string) error DockerContainerUpdateName(name, id string) (err error) DockerContainerUpdate(m model.CustomizationPostData, id string) (err error) @@ -352,7 +352,7 @@ func (ds *dockerService) DockerPullImage(imageName string, m model2.AppNotify) e //param udp 容器其他udp端口 func (ds *dockerService) DockerContainerCreate(imageName string, containerDbId string, m model.CustomizationPostData, net string) (containerId string, err error) { if len(net) == 0 { - net = "oasis" + net = "bridge" } cli, err := client2.NewClientWithOpts(client2.FromEnv) @@ -515,7 +515,7 @@ func (ds *dockerService) DockerContainerCreate(imageName string, containerDbId s } //删除容器 -func (ds *dockerService) DockerContainerRemove(name string) error { +func (ds *dockerService) DockerContainerRemove(name string, update bool) error { cli, err := client2.NewClientWithOpts(client2.FromEnv) if err != nil { return err @@ -524,9 +524,11 @@ func (ds *dockerService) DockerContainerRemove(name string) error { err = cli.ContainerRemove(context.Background(), name, types.ContainerRemoveOptions{}) //路径处理 - path := docker.GetDir(name, "/config") - if !file.CheckNotExist(path) { - file.RMDir(path) + if !update { + path := docker.GetDir(name, "/config") + if !file.CheckNotExist(path) { + file.RMDir(path) + } } if err != nil { diff --git a/service/system.go b/service/system.go index fd2b83c02..90c66f720 100644 --- a/service/system.go +++ b/service/system.go @@ -14,6 +14,8 @@ type SystemService interface { UpdateSystemVersion(version string) GetSystemConfigDebug() []string GetCasaOSLogs(lineNumber int) string + UpdateAssist() + UpSystemPort(port string) } type systemService struct { log loger.OLog @@ -25,6 +27,9 @@ func (s *systemService) UpdateSystemVersion(version string) { s.log.Error(command2.ExecResultStrArray("source " + config.AppInfo.ProjectPath + "/shell/tools.sh ;update " + version)) //s.log.Error(command2.ExecResultStr(config.AppInfo.ProjectPath + "/shell/tool.sh -r " + version)) } +func (s *systemService) UpdateAssist() { + s.log.Error(command2.ExecResultStrArray("source " + config.AppInfo.ProjectPath + "/shell/assist.sh")) +} func (s *systemService) GetSystemConfigDebug() []string { return command2.ExecResultStrArray("source " + config.AppInfo.ProjectPath + "/shell/helper.sh ;GetSysInfo") } @@ -39,6 +44,13 @@ func (s *systemService) UpSystemConfig(str string, widget string) { } config.Cfg.SaveTo(config.SystemConfigInfo.ConfigPath) } +func (s *systemService) UpSystemPort(port string) { + if len(port) > 0 && port != config.ServerInfo.HttpPort { + config.Cfg.Section("server").Key("HttpPort").SetValue(port) + config.ServerInfo.HttpPort = port + } + config.Cfg.SaveTo(config.SystemConfigInfo.ConfigPath) +} func (s *systemService) GetCasaOSLogs(lineNumber int) string { file, err := os.Open(s.log.Path()) if err != nil { diff --git a/service/zima_info.go b/service/zima_info.go index 4770ff8b3..fa7930c59 100644 --- a/service/zima_info.go +++ b/service/zima_info.go @@ -116,7 +116,6 @@ func (c *zima) GetNetState(name string) string { //网络信息 func (c *zima) GetNetInfo() []net.IOCountersStat { - //loger.Error("输出个内容试试") parts, _ := net.IOCounters(true) //fmt.Println(net.ConntrackStatsWithContext(true)) return parts diff --git a/shell/assist.sh b/shell/assist.sh new file mode 100644 index 000000000..75108b4d1 --- /dev/null +++ b/shell/assist.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +#update to v0.2.3 +version_0_2_3(){ + ((EUID)) && sudo_cmd="sudo" + +#copy file to path + if [ ! -s "/etc/udev/rules.d/11-usb-mount.rules" ]; then + $sudo_cmd cp /casaOS/server/shell/11-usb-mount.rules /etc/udev/rules.d/ + fi + + if [ ! -s "/casaOS/util/shell/usb-mount.sh" ]; then + $sudo_cmd cp /casaOS/server/shell/usb-mount.sh /casaOS/util/shell/ + $sudo_cmd chmod +x /casaOS/util/shell/usb-mount.sh + fi + if [ ! -s "/etc/systemd/system/cp /casaOS/server/shell/usb-mount@.service" ]; then + $sudo_cmd cp /casaOS/server/shell/usb-mount@.service /etc/systemd/system/ + fi + + + + +} + +version_0_2_3 \ No newline at end of file diff --git a/shell/tools.sh b/shell/tools.sh index fc24e0174..cbb332565 100644 --- a/shell/tools.sh +++ b/shell/tools.sh @@ -60,7 +60,7 @@ show() { } run_external_script() { - show 0 "run_external_script" + assist.sh } update() { diff --git a/shell/usb-mount.sh b/shell/usb-mount.sh index d31ee0ed2..74e9b3d03 100644 --- a/shell/usb-mount.sh +++ b/shell/usb-mount.sh @@ -1,6 +1,6 @@ #!/bin/sh -# copy to /oasis/util/shell path +# copy to /casaOS/util/shell path # chmod 755 log="logger -t usb-mount.sh -s " @@ -18,10 +18,10 @@ MOUNT_POINT=$(mount | grep ${DEVICE} | awk '{ print $3 }') do_mount() { - if [[ -n ${MOUNT_POINT} ]]; then + if [ -n "${MOUNT_POINT}" ]; then ${log} "Warning: ${DEVICE} is already mounted at ${MOUNT_POINT}" exit 1 - fib + fi # Get info for this drive: $ID_FS_LABEL and $ID_FS_TYPE eval $(blkid -o udev ${DEVICE} | grep -i -e "ID_FS_LABEL" -e "ID_FS_TYPE") diff --git a/shell/usb-mount@.service b/shell/usb-mount@.service index 839790d27..c97673015 100644 --- a/shell/usb-mount@.service +++ b/shell/usb-mount@.service @@ -4,5 +4,5 @@ Description=Mount USB Drive on %i [Service] Type=oneshot RemainAfterExit=true -ExecStart=/oasis/util/shell/usb-mount.sh add %i -ExecStop=/oasis/util/shell/usb-mount.sh remove %i +ExecStart=/casaOS/util/shell/usb-mount.sh add %i +ExecStop=/casaOS/util/shell/usb-mount.sh remove %i