mirror of
https://github.com/IceWhaleTech/CasaOS.git
synced 2025-12-01 18:57:33 +00:00
Adjusting multi-partition disk mounts
This commit is contained in:
parent
5009b04a6d
commit
35e44f1362
@ -2,7 +2,7 @@
|
||||
* @Author: LinkLeong link@icewhale.com
|
||||
* @Date: 2022-07-13 10:43:45
|
||||
* @LastEditors: LinkLeong
|
||||
* @LastEditTime: 2022-07-13 11:00:04
|
||||
* @LastEditTime: 2022-07-29 14:21:59
|
||||
* @FilePath: /CasaOS/model/disk.go
|
||||
* @Description:
|
||||
* @Website: https://www.casaos.io
|
||||
@ -39,6 +39,7 @@ type LSBLKModel struct {
|
||||
Serial string `json:"serial"`
|
||||
Children []LSBLKModel `json:"children"`
|
||||
SubSystems string `json:"subsystems"`
|
||||
Label string `json:"label"`
|
||||
//详情特有
|
||||
StartSector uint64 `json:"start_sector,omitempty"`
|
||||
Rota bool `json:"rota"` //true(hhd) false(ssd)
|
||||
@ -56,6 +57,7 @@ type Drive struct {
|
||||
NeedFormat bool `json:"need_format"`
|
||||
Serial string `json:"serial"`
|
||||
Path string `json:"path"`
|
||||
ChildrenNumber int `json:"children_number"`
|
||||
}
|
||||
|
||||
type DriveUSB struct {
|
||||
@ -68,14 +70,19 @@ type DriveUSB struct {
|
||||
}
|
||||
|
||||
type Storage struct {
|
||||
Name string `json:"name"`
|
||||
MountPoint string `json:"mountpoint"`
|
||||
Size string `json:"size"`
|
||||
Avail string `json:"avail"` //可用空间
|
||||
Type string `json:"type"`
|
||||
CreatedAt int64 `json:"create_at"`
|
||||
Path string `json:"path"`
|
||||
DriveName string `json:"drive_name"`
|
||||
Label string `json:"label"`
|
||||
}
|
||||
type Storages struct {
|
||||
DiskName string `json:"disk_name"`
|
||||
Size uint64 `json:"size"`
|
||||
Path string `json:"path"`
|
||||
Children []Storage `json:"children"`
|
||||
}
|
||||
|
||||
type Summary struct {
|
||||
|
||||
@ -1,3 +1,13 @@
|
||||
/*
|
||||
* @Author: LinkLeong link@icewhale.org
|
||||
* @Date: 2022-05-13 18:15:46
|
||||
* @LastEditors: LinkLeong
|
||||
* @LastEditTime: 2022-07-28 13:47:00
|
||||
* @FilePath: /CasaOS/model/zima.go
|
||||
* @Description:
|
||||
* @Website: https://www.casaos.io
|
||||
* Copyright (c) 2022 by icewhale, All Rights Reserved.
|
||||
*/
|
||||
package model
|
||||
|
||||
import "time"
|
||||
@ -11,4 +21,5 @@ type Path struct {
|
||||
Type string `json:"type,omitempty"`
|
||||
Label string `json:"label,omitempty"`
|
||||
Write bool `json:"write"`
|
||||
Extensions map[string]string `json:"extensions"`
|
||||
}
|
||||
|
||||
@ -29,6 +29,7 @@ const (
|
||||
VERIFICATION_FAILURE = 20006
|
||||
Record_NOT_EXIST = 20007
|
||||
Record_ALREADY_EXIST = 20008
|
||||
SERVICE_NOT_RUNNING = 20009
|
||||
|
||||
//disk
|
||||
NAME_NOT_AVAILABLE = 40001
|
||||
@ -83,6 +84,7 @@ var MsgFlags = map[int]string{
|
||||
VERIFICATION_FAILURE: "Verification failure",
|
||||
Record_ALREADY_EXIST: "Record already exists",
|
||||
Record_NOT_EXIST: "Record does not exist",
|
||||
SERVICE_NOT_RUNNING: "Service is not running",
|
||||
|
||||
//app
|
||||
UNINSTALL_APP_ERROR: "Error uninstalling app",
|
||||
|
||||
@ -24,7 +24,6 @@ func InitFunction() {
|
||||
ChangeAPIUrl()
|
||||
|
||||
MoveUserToDB()
|
||||
InitSamba()
|
||||
}
|
||||
|
||||
func CheckSerialDiskMount() {
|
||||
@ -139,66 +138,3 @@ func MoveUserToDB() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func InitSamba() {
|
||||
if file.Exists("/etc/samba/smb.conf") {
|
||||
str := file.ReadLine(1, "/etc/samba/smb.conf")
|
||||
if strings.Contains(str, "# Copyright (c) 2021-2022 CasaOS Inc. All rights reserved.") {
|
||||
|
||||
return
|
||||
}
|
||||
file.MoveFile("/etc/samba/smb.conf", "/etc/samba/smb.conf.bak")
|
||||
var smbConf = ""
|
||||
smbConf += `# Copyright (c) 2021-2022 CasaOS Inc. All rights reserved.
|
||||
#
|
||||
#
|
||||
# ______ _______
|
||||
# ( __ \ ( ___ )
|
||||
# | ( \ ) | ( ) |
|
||||
# | | ) | | | | |
|
||||
# | | | | | | | |
|
||||
# | | ) | | | | |
|
||||
# | (__/ ) | (___) |
|
||||
# (______/ (_______)
|
||||
#
|
||||
# _ _______ _________
|
||||
# ( ( /| ( ___ ) \__ __/
|
||||
# | \ ( | | ( ) | ) (
|
||||
# | \ | | | | | | | |
|
||||
# | (\ \) | | | | | | |
|
||||
# | | \ | | | | | | |
|
||||
# | ) \ | | (___) | | |
|
||||
# |/ )_) (_______) )_(
|
||||
#
|
||||
# _______ _______ ______ _________ _______
|
||||
# ( ) ( ___ ) ( __ \ \__ __/ ( ____ \ |\ /|
|
||||
# | () () | | ( ) | | ( \ ) ) ( | ( \/ ( \ / )
|
||||
# | || || | | | | | | | ) | | | | (__ \ (_) /
|
||||
# | |(_)| | | | | | | | | | | | | __) \ /
|
||||
# | | | | | | | | | | ) | | | | ( ) (
|
||||
# | ) ( | | (___) | | (__/ ) ___) (___ | ) | |
|
||||
# |/ \| (_______) (______/ \_______/ |/ \_/
|
||||
#
|
||||
#
|
||||
# IMPORTANT: CasaOS will not provide technical support for any issues
|
||||
# caused by unauthorized modification to the configuration.
|
||||
|
||||
[global]
|
||||
## fruit settings
|
||||
min protocol = SMB2
|
||||
ea support = yes
|
||||
vfs objects = fruit streams_xattr
|
||||
fruit:metadata = stream
|
||||
fruit:model = Macmini
|
||||
fruit:veto_appledouble = no
|
||||
fruit:posix_rename = yes
|
||||
fruit:zero_file_id = yes
|
||||
fruit:wipe_intentionally_left_blank_rfork = yes
|
||||
fruit:delete_empty_adfiles = yes
|
||||
map to guest = bad user
|
||||
include=/etc/samba/smb.casa.conf
|
||||
|
||||
`
|
||||
file.WriteToPath([]byte(smbConf), "/etc/samba", "smb.conf")
|
||||
}
|
||||
}
|
||||
|
||||
@ -216,6 +216,7 @@ func InitRouter() *gin.Engine {
|
||||
v1StorageGroup.PUT("", v1.PostDiskFormat)
|
||||
|
||||
v1StorageGroup.DELETE("", v1.PostDiskUmount)
|
||||
v1StorageGroup.GET("", v1.GetStorageList)
|
||||
}
|
||||
v1SambaGroup := v1Group.Group("/samba")
|
||||
v1SambaGroup.Use()
|
||||
@ -233,6 +234,7 @@ func InitRouter() *gin.Engine {
|
||||
v1SharesGroup.GET("", v1.GetSambaSharesList)
|
||||
v1SharesGroup.POST("", v1.PostSambaSharesCreate)
|
||||
v1SharesGroup.DELETE("/:id", v1.DeleteSambaShares)
|
||||
v1SharesGroup.GET("/status", v1.GetSambaStatus)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -87,14 +87,13 @@ func GetDiskList(c *gin.Context) {
|
||||
disk.Size = list[i].Size
|
||||
disk.Path = list[i].Path
|
||||
disk.Model = list[i].Model
|
||||
|
||||
disk.ChildrenNumber = len(list[i].Children)
|
||||
if len(list[i].Children) > 0 && findSystem == 0 {
|
||||
for j := 0; j < len(list[i].Children); j++ {
|
||||
if len(list[i].Children[j].Children) > 0 {
|
||||
for _, v := range list[i].Children[j].Children {
|
||||
if v.MountPoint == "/" {
|
||||
stor := model.Storage{}
|
||||
stor.Name = "System"
|
||||
stor.MountPoint = v.MountPoint
|
||||
stor.Size = v.FSSize
|
||||
stor.Avail = v.FSAvail
|
||||
@ -118,7 +117,6 @@ func GetDiskList(c *gin.Context) {
|
||||
} else {
|
||||
if list[i].Children[j].MountPoint == "/" {
|
||||
stor := model.Storage{}
|
||||
stor.Name = "System"
|
||||
stor.MountPoint = list[i].Children[j].MountPoint
|
||||
stor.Size = list[i].Children[j].FSSize
|
||||
stor.Avail = list[i].Children[j].FSAvail
|
||||
@ -152,31 +150,29 @@ func GetDiskList(c *gin.Context) {
|
||||
if reflect.DeepEqual(temp, model.SmartctlA{}) {
|
||||
temp.SmartStatus.Passed = true
|
||||
}
|
||||
if len(list[i].Children) == 1 && len(list[i].Children[0].MountPoint) > 0 {
|
||||
isAvail := true
|
||||
for _, v := range list[i].Children {
|
||||
if v.MountPoint != "" {
|
||||
stor := model.Storage{}
|
||||
stor.MountPoint = list[i].Children[0].MountPoint
|
||||
stor.Size = list[i].Children[0].FSSize
|
||||
stor.Avail = list[i].Children[0].FSAvail
|
||||
stor.Path = list[i].Children[0].Path
|
||||
stor.Type = list[i].Children[0].FsType
|
||||
stor.MountPoint = v.MountPoint
|
||||
stor.Size = v.FSSize
|
||||
stor.Avail = v.FSAvail
|
||||
stor.Path = v.Path
|
||||
stor.Type = v.FsType
|
||||
stor.DriveName = list[i].Name
|
||||
pathArr := strings.Split(list[i].Children[0].MountPoint, "/")
|
||||
if len(pathArr) == 3 {
|
||||
stor.Name = pathArr[2]
|
||||
}
|
||||
if t, ok := part[list[i].Children[0].MountPoint]; ok {
|
||||
stor.CreatedAt = t
|
||||
}
|
||||
storage = append(storage, stor)
|
||||
} else {
|
||||
//todo 长度有问题
|
||||
if len(list[i].Children) == 1 && list[i].Children[0].FsType == "ext4" {
|
||||
isAvail = false
|
||||
}
|
||||
}
|
||||
|
||||
if isAvail {
|
||||
//if len(list[i].Children) == 1 && list[i].Children[0].FsType == "ext4" {
|
||||
disk.NeedFormat = false
|
||||
avail = append(avail, disk)
|
||||
} else {
|
||||
disk.NeedFormat = true
|
||||
avail = append(avail, disk)
|
||||
}
|
||||
// } else {
|
||||
// disk.NeedFormat = true
|
||||
// avail = append(avail, disk)
|
||||
// }
|
||||
}
|
||||
|
||||
disk.Temperature = temp.Temperature.Current
|
||||
@ -296,13 +292,7 @@ func PostDiskAddPartition(c *gin.Context) {
|
||||
}
|
||||
diskMap[path] = "busying"
|
||||
currentDisk := service.MyService.Disk().GetDiskInfo(path)
|
||||
if !format {
|
||||
if len(currentDisk.Children) != 1 || !(len(currentDisk.Children) > 0 && currentDisk.Children[0].FsType == "ext4") {
|
||||
delete(diskMap, path)
|
||||
c.JSON(common_err.SERVICE_ERROR, model.Result{Success: common_err.DISK_NEEDS_FORMAT, Message: common_err.GetMsg(common_err.DISK_NEEDS_FORMAT)})
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if format {
|
||||
// format := service.MyService.Disk().FormatDisk(path+"1", "ext4")
|
||||
// if len(format) == 0 {
|
||||
// delete(diskMap, path)
|
||||
@ -323,22 +313,23 @@ func PostDiskAddPartition(c *gin.Context) {
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
currentDisk = service.MyService.Disk().GetDiskInfo(path)
|
||||
if len(currentDisk.Children) != 1 {
|
||||
c.JSON(common_err.SERVICE_ERROR, model.Result{Success: common_err.DISK_NEEDS_FORMAT, Message: common_err.GetMsg(common_err.DISK_NEEDS_FORMAT)})
|
||||
return
|
||||
}
|
||||
|
||||
// if len(currentDisk.Children) != 1 {
|
||||
// c.JSON(common_err.SERVICE_ERROR, model.Result{Success: common_err.DISK_NEEDS_FORMAT, Message: common_err.GetMsg(common_err.DISK_NEEDS_FORMAT)})
|
||||
// return
|
||||
// }
|
||||
for i := 0; i < len(currentDisk.Children); i++ {
|
||||
mountPath := "/DATA/" + name
|
||||
m := model2.SerialDisk{}
|
||||
m.MountPoint = mountPath
|
||||
m.Path = currentDisk.Children[0].Path
|
||||
m.UUID = currentDisk.Children[0].UUID
|
||||
m.MountPoint = mountPath + strconv.Itoa(i)
|
||||
m.Path = currentDisk.Children[i].Path
|
||||
m.UUID = currentDisk.Children[i].UUID
|
||||
m.State = 0
|
||||
m.CreatedAt = time.Now().Unix()
|
||||
service.MyService.Disk().SaveMountPoint(m)
|
||||
|
||||
//mount dir
|
||||
service.MyService.Disk().MountDisk(currentDisk.Children[0].Path, mountPath)
|
||||
service.MyService.Disk().MountDisk(currentDisk.Children[i].Path, mountPath+strconv.Itoa(i))
|
||||
}
|
||||
|
||||
service.MyService.Disk().RemoveLSBLKCache()
|
||||
|
||||
@ -348,7 +339,7 @@ func PostDiskAddPartition(c *gin.Context) {
|
||||
msg := notify.StorageMessage{}
|
||||
msg.Action = "ADDED"
|
||||
msg.Path = currentDisk.Children[0].Path
|
||||
msg.Volume = mountPath
|
||||
msg.Volume = "/DATA/" + name
|
||||
msg.Size = currentDisk.Children[0].Size
|
||||
msg.Type = currentDisk.Children[0].Tran
|
||||
service.MyService.Notify().SendStorageBySocket(msg)
|
||||
|
||||
@ -218,6 +218,11 @@ func GetDownloadSingleFile(c *gin.Context) {
|
||||
func DirPath(c *gin.Context) {
|
||||
path := c.DefaultQuery("path", "")
|
||||
info := service.MyService.System().GetDirPath(path)
|
||||
shares := service.MyService.Shares().GetSharesList()
|
||||
sharesMap := make(map[string]string)
|
||||
for _, v := range shares {
|
||||
sharesMap[v.Path] = v.Name
|
||||
}
|
||||
if path == "/DATA/AppData" {
|
||||
list := service.MyService.Docker().DockerContainerList()
|
||||
apps := make(map[string]string, len(list))
|
||||
@ -229,6 +234,11 @@ func DirPath(c *gin.Context) {
|
||||
info[i].Label = v
|
||||
info[i].Type = "application"
|
||||
}
|
||||
if _, ok := sharesMap[info[i].Path]; ok {
|
||||
ex := make(map[string]string)
|
||||
ex["shared"] = "true"
|
||||
info[i].Extensions = ex
|
||||
}
|
||||
}
|
||||
} else if path == "/DATA" {
|
||||
disk := make(map[string]string)
|
||||
@ -255,6 +265,11 @@ func DirPath(c *gin.Context) {
|
||||
if v, ok := disk[info[i].Path]; ok {
|
||||
info[i].Type = v
|
||||
}
|
||||
if _, ok := sharesMap[info[i].Path]; ok {
|
||||
ex := make(map[string]string)
|
||||
ex["shared"] = "true"
|
||||
info[i].Extensions = ex
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
* @Author: LinkLeong link@icewhale.com
|
||||
* @Date: 2022-07-26 11:08:48
|
||||
* @LastEditors: LinkLeong
|
||||
* @LastEditTime: 2022-07-27 15:30:08
|
||||
* @LastEditTime: 2022-07-28 11:51:03
|
||||
* @FilePath: /CasaOS/route/v1/samba.go
|
||||
* @Description:
|
||||
* @Website: https://www.casaos.io
|
||||
@ -13,6 +13,7 @@ package v1
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS/model"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/samba"
|
||||
@ -25,6 +26,25 @@ import (
|
||||
|
||||
// service
|
||||
|
||||
func GetSambaStatus(c *gin.Context) {
|
||||
status := service.MyService.System().IsServiceRunning("smbd")
|
||||
|
||||
if !status {
|
||||
c.JSON(common_err.SERVICE_ERROR, model.Result{Success: common_err.SERVICE_NOT_RUNNING, Message: common_err.GetMsg(common_err.SERVICE_NOT_RUNNING)})
|
||||
return
|
||||
}
|
||||
needInit := true
|
||||
if file.Exists("/etc/samba/smb.conf") {
|
||||
str := file.ReadLine(1, "/etc/samba/smb.conf")
|
||||
if strings.Contains(str, "# Copyright (c) 2021-2022 CasaOS Inc. All rights reserved.") {
|
||||
needInit = false
|
||||
}
|
||||
}
|
||||
data := make(map[string]string, 1)
|
||||
data["need_init"] = fmt.Sprintf("%v", needInit)
|
||||
c.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: data})
|
||||
}
|
||||
|
||||
func GetSambaSharesList(c *gin.Context) {
|
||||
shares := service.MyService.Shares().GetSharesList()
|
||||
shareList := []model.Shares{}
|
||||
@ -58,7 +78,6 @@ func PostSambaSharesCreate(c *gin.Context) {
|
||||
c.JSON(common_err.CLIENT_ERROR, model.Result{Success: common_err.SHARE_NAME_ALREADY_EXISTS, Message: common_err.GetMsg(common_err.SHARE_NAME_ALREADY_EXISTS)})
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
for _, v := range shares {
|
||||
shareDBModel := model2.SharesDBModel{}
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
* @Author: LinkLeong link@icewhale.com
|
||||
* @Date: 2022-07-11 16:02:29
|
||||
* @LastEditors: LinkLeong
|
||||
* @LastEditTime: 2022-07-11 16:02:55
|
||||
* @LastEditTime: 2022-07-29 14:14:17
|
||||
* @FilePath: /CasaOS/route/v1/storage.go
|
||||
* @Description:
|
||||
* @Website: https://www.casaos.io
|
||||
@ -10,8 +10,59 @@
|
||||
*/
|
||||
package v1
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
import (
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS/model"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/utils/common_err"
|
||||
"github.com/IceWhaleTech/CasaOS/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func GetStorageList(c *gin.Context) {
|
||||
|
||||
storages := []model.Storages{}
|
||||
disks := service.MyService.Disk().LSBLK(false)
|
||||
diskNumber := 1
|
||||
children := 1
|
||||
for _, d := range disks {
|
||||
children = 1
|
||||
if d.Tran == "sata" || d.Tran == "nvme" || d.Tran == "spi" || d.Tran == "sas" || strings.Contains(d.SubSystems, "virtio") || (d.Tran == "ata" && d.Type == "disk") {
|
||||
storageArr := []model.Storage{}
|
||||
temp := service.MyService.Disk().SmartCTL(d.Path)
|
||||
if reflect.DeepEqual(temp, model.SmartctlA{}) {
|
||||
temp.SmartStatus.Passed = true
|
||||
}
|
||||
for _, v := range d.Children {
|
||||
if v.MountPoint != "" {
|
||||
stor := model.Storage{}
|
||||
stor.MountPoint = v.MountPoint
|
||||
stor.Size = v.FSSize
|
||||
stor.Avail = v.FSAvail
|
||||
stor.Path = v.Path
|
||||
stor.Type = v.FsType
|
||||
stor.DriveName = "System"
|
||||
if len(v.Label) == 0 {
|
||||
stor.Label = "Storage" + strconv.Itoa(diskNumber) + "_" + strconv.Itoa(children)
|
||||
children += 1
|
||||
} else {
|
||||
stor.Label = v.Label
|
||||
}
|
||||
storageArr = append(storageArr, stor)
|
||||
}
|
||||
}
|
||||
if len(storageArr) > 0 {
|
||||
storages = append(storages, model.Storages{
|
||||
DiskName: d.Model,
|
||||
Path: d.Path,
|
||||
Size: d.Size,
|
||||
Children: storageArr,
|
||||
})
|
||||
diskNumber += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
c.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: storages})
|
||||
}
|
||||
|
||||
@ -243,6 +243,7 @@ func (d *diskService) GetDiskInfo(path string) model.LSBLKModel {
|
||||
}
|
||||
|
||||
func (d *diskService) MountDisk(path, volume string) {
|
||||
fmt.Println("source " + config.AppInfo.ShellPath + "/helper.sh ;do_mount " + path + " " + volume)
|
||||
r := command2.ExecResultStr("source " + config.AppInfo.ShellPath + "/helper.sh ;do_mount " + path + " " + volume)
|
||||
fmt.Print(r)
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
* @Author: LinkLeong link@icewhale.org
|
||||
* @Date: 2022-07-26 11:21:14
|
||||
* @LastEditors: LinkLeong
|
||||
* @LastEditTime: 2022-07-27 15:27:38
|
||||
* @LastEditTime: 2022-07-28 16:08:56
|
||||
* @FilePath: /CasaOS/service/shares.go
|
||||
* @Description:
|
||||
* @Website: https://www.casaos.io
|
||||
@ -12,6 +12,7 @@ package service
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/config"
|
||||
command2 "github.com/IceWhaleTech/CasaOS/pkg/utils/command"
|
||||
@ -28,6 +29,7 @@ type SharesService interface {
|
||||
CreateShare(share model2.SharesDBModel)
|
||||
DeleteShare(id string)
|
||||
UpdateConfigFile()
|
||||
InitSambaConfig()
|
||||
}
|
||||
|
||||
type sharesStruct struct {
|
||||
@ -35,19 +37,21 @@ type sharesStruct struct {
|
||||
}
|
||||
|
||||
func (s *sharesStruct) GetSharesByName(name string) (shares []model2.SharesDBModel) {
|
||||
s.db.Select("title,anonymous,path,id").Where("name = ?", name).Find(&shares)
|
||||
s.db.Select("anonymous,path,id").Where("name = ?", name).Find(&shares)
|
||||
|
||||
return
|
||||
}
|
||||
func (s *sharesStruct) GetSharesByPath(path string) (shares []model2.SharesDBModel) {
|
||||
s.db.Select("title,anonymous,path,id").Where("path = ?", path).Find(&shares)
|
||||
s.db.Select("anonymous,path,id").Where("path = ?", path).Find(&shares)
|
||||
return
|
||||
}
|
||||
func (s *sharesStruct) GetSharesList() (shares []model2.SharesDBModel) {
|
||||
s.db.Select("title,anonymous,path,id").Find(&shares)
|
||||
s.db.Select("anonymous,path,id").Find(&shares)
|
||||
return
|
||||
}
|
||||
func (s *sharesStruct) CreateShare(share model2.SharesDBModel) {
|
||||
s.db.Create(&share)
|
||||
s.InitSambaConfig()
|
||||
s.UpdateConfigFile()
|
||||
}
|
||||
func (s *sharesStruct) DeleteShare(id string) {
|
||||
@ -57,13 +61,14 @@ func (s *sharesStruct) DeleteShare(id string) {
|
||||
|
||||
func (s *sharesStruct) UpdateConfigFile() {
|
||||
shares := []model2.SharesDBModel{}
|
||||
s.db.Select("title,anonymous,path").Find(&shares)
|
||||
s.db.Select("anonymous,path").Find(&shares)
|
||||
//generated config file
|
||||
var configStr = ""
|
||||
for _, share := range shares {
|
||||
dirName := filepath.Base(share.Path)
|
||||
configStr += `
|
||||
[` + dirName + `]
|
||||
comment = CasaOS share ` + dirName + `
|
||||
public = Yes
|
||||
path = ` + share.Path + `
|
||||
browseable = Yes
|
||||
@ -78,7 +83,71 @@ directory mask = 0777
|
||||
file.WriteToPath([]byte(configStr), "/etc/samba", "smb.casa.conf")
|
||||
//restart samba
|
||||
command2.ExecResultStrArray("source " + config.AppInfo.ShellPath + "/helper.sh ;RestartSMBD")
|
||||
|
||||
}
|
||||
func (s *sharesStruct) InitSambaConfig() {
|
||||
if file.Exists("/etc/samba/smb.conf") {
|
||||
str := file.ReadLine(1, "/etc/samba/smb.conf")
|
||||
if strings.Contains(str, "# Copyright (c) 2021-2022 CasaOS Inc. All rights reserved.") {
|
||||
return
|
||||
}
|
||||
file.MoveFile("/etc/samba/smb.conf", "/etc/samba/smb.conf.bak")
|
||||
var smbConf = ""
|
||||
smbConf += `# Copyright (c) 2021-2022 CasaOS Inc. All rights reserved.
|
||||
#
|
||||
#
|
||||
# ______ _______
|
||||
# ( __ \ ( ___ )
|
||||
# | ( \ ) | ( ) |
|
||||
# | | ) | | | | |
|
||||
# | | | | | | | |
|
||||
# | | ) | | | | |
|
||||
# | (__/ ) | (___) |
|
||||
# (______/ (_______)
|
||||
#
|
||||
# _ _______ _________
|
||||
# ( ( /| ( ___ ) \__ __/
|
||||
# | \ ( | | ( ) | ) (
|
||||
# | \ | | | | | | | |
|
||||
# | (\ \) | | | | | | |
|
||||
# | | \ | | | | | | |
|
||||
# | ) \ | | (___) | | |
|
||||
# |/ )_) (_______) )_(
|
||||
#
|
||||
# _______ _______ ______ _________ _______
|
||||
# ( ) ( ___ ) ( __ \ \__ __/ ( ____ \ |\ /|
|
||||
# | () () | | ( ) | | ( \ ) ) ( | ( \/ ( \ / )
|
||||
# | || || | | | | | | | ) | | | | (__ \ (_) /
|
||||
# | |(_)| | | | | | | | | | | | | __) \ /
|
||||
# | | | | | | | | | | ) | | | | ( ) (
|
||||
# | ) ( | | (___) | | (__/ ) ___) (___ | ) | |
|
||||
# |/ \| (_______) (______/ \_______/ |/ \_/
|
||||
#
|
||||
#
|
||||
# IMPORTANT: CasaOS will not provide technical support for any issues
|
||||
# caused by unauthorized modification to the configuration.
|
||||
|
||||
[global]
|
||||
## fruit settings
|
||||
min protocol = SMB2
|
||||
ea support = yes
|
||||
vfs objects = fruit streams_xattr
|
||||
fruit:metadata = stream
|
||||
fruit:model = Macmini
|
||||
fruit:veto_appledouble = no
|
||||
fruit:posix_rename = yes
|
||||
fruit:zero_file_id = yes
|
||||
fruit:wipe_intentionally_left_blank_rfork = yes
|
||||
fruit:delete_empty_adfiles = yes
|
||||
map to guest = bad user
|
||||
include=/etc/samba/smb.casa.conf
|
||||
|
||||
`
|
||||
file.WriteToPath([]byte(smbConf), "/etc/samba", "smb.conf")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func NewSharesService(db *gorm.DB) SharesService {
|
||||
return &sharesStruct{db: db}
|
||||
}
|
||||
|
||||
@ -49,6 +49,7 @@ type SystemService interface {
|
||||
CreateFile(path string) (int, error)
|
||||
RenameFile(oldF, newF string) (int, error)
|
||||
MkdirAll(path string) (int, error)
|
||||
IsServiceRunning(name string) bool
|
||||
}
|
||||
type systemService struct {
|
||||
}
|
||||
@ -287,6 +288,12 @@ func GetDeviceAllIP() []string {
|
||||
}
|
||||
return address
|
||||
}
|
||||
|
||||
func (s *systemService) IsServiceRunning(name string) bool {
|
||||
status := command2.ExecResultStr("source " + config.AppInfo.ShellPath + "/helper.sh ;CheckServiceStatus smbd")
|
||||
return strings.TrimSpace(status) == "running"
|
||||
|
||||
}
|
||||
func NewSystemService() SystemService {
|
||||
return &systemService{}
|
||||
}
|
||||
|
||||
@ -369,3 +369,19 @@ EOF
|
||||
MountCIFS(){
|
||||
$sudo_cmd mount -t cifs -o username=$1,password=$6,port=$4 //$2/$3 $5
|
||||
}
|
||||
|
||||
# $1:service name
|
||||
CheckServiceStatus(){
|
||||
rs="`systemctl status $1 |grep -E 'Active|PID'`"
|
||||
#echo "$rs"
|
||||
run="`echo "$rs" |grep -B 2 'running'`"
|
||||
fai="`echo "$rs" |grep -E -B 2 'failed|inactive|dead'`"
|
||||
if [ "$run" == "" ]
|
||||
then
|
||||
echo "failed"
|
||||
else
|
||||
echo "running"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user