CasaOS/route/init.go
Tiger Wang 381fb85b1d
v0.3.7 (#600)
* add send notify function

* add shell script

* add system notiry

* remove disk and test common package

* update http status

* add share function to common

* remove temp path

* remove /DATA directory initialization - moved to local-storage (#578)

* update goreleaser configuration

* wip

* change service type to notify for systemd so its status is OK only when service is initialized successfully

* update CasaOS-Common to fix runtime error

* wip

* add send notify function

* add shell script

* add system notiry

* remove disk and test common package

* update http status

* add share function to common

* remove temp path

* remove /DATA directory initialization - moved to local-storage (#578)

* update goreleaser configuration

* wip

* change service type to notify for systemd so its status is OK only when service is initialized successfully

* update CasaOS-Common to fix runtime error

* wip

* wip

* wip

* wip

* wip

* Utilization interface to supplement disk information

* fix upload file

* wip

* wip

* add update url

* wip

* wip

* add change log

* update changelog

Co-authored-by: LinkLeong <a624669980@163.com>
2022-10-20 14:25:26 +08:00

48 lines
1.5 KiB
Go

package route
import (
"fmt"
"os"
"strings"
"time"
"github.com/IceWhaleTech/CasaOS/pkg/samba"
"github.com/IceWhaleTech/CasaOS/pkg/utils/file"
"github.com/IceWhaleTech/CasaOS/pkg/utils/loger"
"github.com/IceWhaleTech/CasaOS/service"
"go.uber.org/zap"
)
func InitFunction() {
go InitNetworkMount()
}
func InitNetworkMount() {
time.Sleep(time.Second * 10)
connections := service.MyService.Connections().GetConnectionsList()
for _, v := range connections {
connection := service.MyService.Connections().GetConnectionByID(fmt.Sprint(v.ID))
directories, err := samba.GetSambaSharesList(connection.Host, connection.Port, connection.Username, connection.Password)
if err != nil {
service.MyService.Connections().DeleteConnection(fmt.Sprint(connection.ID))
loger.Error("mount samba err", zap.Any("err", err), zap.Any("info", connection))
continue
}
baseHostPath := "/mnt/" + connection.Host
mountPointList := service.MyService.System().GetDirPath(baseHostPath)
for _, v := range mountPointList {
service.MyService.Connections().UnmountSmaba(v.Path)
}
os.RemoveAll(baseHostPath)
file.IsNotExistMkDir(baseHostPath)
for _, v := range directories {
mountPoint := baseHostPath + "/" + v
file.IsNotExistMkDir(mountPoint)
service.MyService.Connections().MountSmaba(connection.Username, connection.Host, v, connection.Port, mountPoint, connection.Password)
}
connection.Directories = strings.Join(directories, ",")
service.MyService.Connections().UpdateConnection(&connection)
}
}