Compare commits

..

30 Commits

Author SHA1 Message Date
LinkLeong
438b8a1dd2 Solve the problem of local application import failure 2022-11-04 07:41:09 +00:00
LinkLeong
ca967ec59c update release 2022-10-26 08:45:32 +01:00
LinkLeong
2beb1c0d82 update changelog 2022-10-19 09:08:11 +01:00
LinkLeong
772c3e0bc0 Merge branch 'v0.3.7' of https://github.com/IceWhaleTech/CasaOS into v0.3.7 2022-10-19 09:00:57 +01:00
LinkLeong
bcda992322 add change log 2022-10-19 09:00:45 +01:00
Tiger Wang
87de9cec0a wip 2022-10-18 18:58:26 -04:00
Tiger Wang
6d47d4ff18 wip 2022-10-18 17:30:00 -04:00
LinkLeong
4bb81e4669 Merge branch 'v0.3.7' of https://github.com/IceWhaleTech/CasaOS into v0.3.7 2022-10-17 06:54:34 +01:00
LinkLeong
c05d837350 add update url 2022-10-17 06:53:23 +01:00
Tiger Wang
8908c39969 wip 2022-10-13 19:33:18 -04:00
Tiger Wang
df0f015944 wip 2022-10-13 16:09:19 -04:00
LinkLeong
46a37f0510 fix upload file 2022-10-13 11:32:30 +01:00
LinkLeong
6ea3cdb364 Utilization interface to supplement disk information 2022-10-13 04:45:17 +01:00
LinkLeong
be80d0cd95 Merge branch 'v0.3.7' of https://github.com/IceWhaleTech/CasaOS into v0.3.7 2022-10-13 04:32:13 +01:00
a624669980@163.com
296e88d099 Merge branch 'v0.3.7' of ssh://github.com/IceWhaleTech/CasaOS into v0.3.7 2022-10-13 11:16:52 +08:00
Tiger Wang
b61a3db611 wip 2022-10-12 16:12:14 -04:00
Tiger Wang
42ebd5f325 wip 2022-10-11 00:19:02 -04:00
Tiger Wang
a51bf70b79 update CasaOS-Common to fix runtime error 2022-09-29 00:05:12 -04:00
Tiger Wang
3787c7bf99 change service type to notify for systemd so its status is OK only when service is initialized successfully 2022-09-28 18:19:31 -04:00
Tiger Wang
ec7f6573ad wip 2022-09-28 17:56:28 -04:00
Tiger Wang
50d68f3f76 update goreleaser configuration 2022-09-28 12:21:44 -04:00
Tiger Wang
d9c6a5c875 remove /DATA directory initialization - moved to local-storage (#578) 2022-09-28 11:14:19 -04:00
LinkLeong
4bace9b16a remove temp path 2022-09-28 16:13:42 +01:00
LinkLeong
84dfa7f5bf add share function to common 2022-09-19 10:09:04 +01:00
LinkLeong
582f85c3ba update http status 2022-09-16 04:47:42 +01:00
LinkLeong
7f4562629a remove disk and test common package 2022-09-15 08:13:07 +01:00
LinkLeong
4776b76b16 add system notiry 2022-09-13 07:22:24 +01:00
a624669980@163.com
9f938f65b1 Merge branch 'main' into v0.3.7 2022-09-09 12:02:19 +08:00
LinkLeong
4ccae3f67f add shell script 2022-09-09 04:12:34 +01:00
LinkLeong
9f2e8dae6f add send notify function 2022-09-08 10:55:20 +01:00
20 changed files with 443 additions and 94 deletions

View File

@@ -28,6 +28,10 @@ jobs:
- -
name: Fetch all tags name: Fetch all tags
run: git fetch --force --tags run: git fetch --force --tags
- name: Get version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
- -
name: Set up Go name: Set up Go
uses: actions/setup-go@v2 uses: actions/setup-go@v2
@@ -45,3 +49,18 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution # Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution
# GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} # GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
- name: Upload to oss
id: upload_to_oss
uses: tvrcgo/upload-to-oss@master
with:
key-id: ${{ secrets.OSS_KEY_ID }}
key-secret: ${{ secrets.OSS_KEY_SECRET }}
region: oss-cn-shanghai
bucket: casaos
assets: |
dist/checksums.txt:/IceWhaleTech/CasaOS/releases/download/${{ steps.get_version.outputs.VERSION }}/checksums.txt
dist/linux-arm-7-casaos-${{ steps.get_version.outputs.VERSION }}.tar.gz:/IceWhaleTech/CasaOS/releases/download/${{ steps.get_version.outputs.VERSION }}/linux-arm-7-casaos-${{ steps.get_version.outputs.VERSION }}.tar.gz
dist/linux-arm64-casaos-${{ steps.get_version.outputs.VERSION }}.tar.gz:/IceWhaleTech/CasaOS/releases/download/${{ steps.get_version.outputs.VERSION }}/linux-arm64-casaos-${{ steps.get_version.outputs.VERSION }}.tar.gz
dist/linux-amd64-casaos-${{ steps.get_version.outputs.VERSION }}.tar.gz:/IceWhaleTech/CasaOS/releases/download/${{ steps.get_version.outputs.VERSION }}/linux-amd64-casaos-${{ steps.get_version.outputs.VERSION }}.tar.gz

View File

@@ -18,6 +18,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed ### Fixed
## [0.3.7.1] 2022-11-04
### Fixed
- Fix memory leak issue ([#658](https://github.com/IceWhaleTech/CasaOS/issues/658)[#646](https://github.com/IceWhaleTech/CasaOS/issues/646))
- Solve the problem of local application import failure ([#490](https://github.com/IceWhaleTech/CasaOS/issues/490))
## [0.3.7] 2022-10-28
### Added
- [Storage] Disk merge (Beta), you can merge multiple disks into a single storage space (currently you need to enable this feature from the command line)
### Changed
- [Files] Changed the cache file storage location, now the file upload size is not limited by the system disk capacity.
- [Scripts] Updated installation and upgrade scripts to support more Debian-based Linux distributions.
- [Engineering] Refactored Local Storage into a standalone service as part of CasaOS modularization.
### Fixed
- [Apps] App list update mechanism improved, now you can see the latest apps in App Store immediately.
- [Storage] Fixed a lot of known issues
## [0.3.6-alpha.1] - 2022-09-06 ## [0.3.6-alpha.1] - 2022-09-06

View File

@@ -31,15 +31,10 @@ if [ ! -f "${CONF_FILE}" ]; then
cp -v "${CONF_FILE_SAMPLE}" "${CONF_FILE}" cp -v "${CONF_FILE_SAMPLE}" "${CONF_FILE}"
fi fi
if systemctl is-active "${APP_NAME}.service" &>/dev/null ;then rm -rf /etc/systemd/system/casaos.service # remove old service file
echo "server started"
else
# enable and start service
systemctl daemon-reload systemctl daemon-reload
# enable service (without starting)
echo "Enabling service..." echo "Enabling service..."
systemctl enable --force --no-ask-password "${APP_NAME}.service" systemctl enable --force --no-ask-password "${APP_NAME}.service"
#echo "Starting service..."
#systemctl start --force --no-ask-password "${APP_NAME}.service"
fi

View File

@@ -0,0 +1,46 @@
#!/bin/bash
set -e
readonly APP_NAME_SHORT=casaos
__get_setup_script_directory_by_os_release() {
pushd "$(dirname "${BASH_SOURCE[0]}")/../service.d/${APP_NAME_SHORT}" &>/dev/null
{
# shellcheck source=/dev/null
{
source /etc/os-release
{
pushd "${ID}"/"${VERSION_CODENAME}" &>/dev/null
} || {
pushd "${ID}" &>/dev/null
} || {
pushd "${ID_LIKE}" &>/dev/null
} || {
echo "Unsupported OS: ${ID} ${VERSION_CODENAME} (${ID_LIKE})"
exit 1
}
pwd
popd &>/dev/null
} || {
echo "Unsupported OS: unknown"
exit 1
}
}
popd &>/dev/null
}
SETUP_SCRIPT_DIRECTORY=$(__get_setup_script_directory_by_os_release)
readonly SETUP_SCRIPT_DIRECTORY
readonly SETUP_SCRIPT_FILENAME="cleanup-${APP_NAME_SHORT}.sh"
readonly SETUP_SCRIPT_FILEPATH="${SETUP_SCRIPT_DIRECTORY}/${SETUP_SCRIPT_FILENAME}"
echo "🟩 Running ${SETUP_SCRIPT_FILENAME}..."
$SHELL "${SETUP_SCRIPT_FILEPATH}" "${BUILD_PATH}"

View File

@@ -0,0 +1 @@
../cleanup-casaos.sh

View File

@@ -0,0 +1,204 @@
#!/bin/bash
set -e
readonly CASA_SERVICES=(
"casaos.service"
"devmon@devmon.service"
)
readonly CASA_EXEC=casaos
readonly CASA_CONF=/etc/casaos/casaos.conf
readonly CASA_URL=/var/run/casaos/casaos.url
readonly CASA_SERVICE_USR=/usr/lib/systemd/system/casaos.service
readonly CASA_SERVICE_LIB=/lib/systemd/system/casaos.service
readonly CASA_SERVICE_ETC=/etc/systemd/system/casaos.service
# Old Casa Files
readonly CASA_PATH=/casaOS
readonly CASA_CONF_PATH_OLD=/etc/casaos.conf
readonly aCOLOUR=(
'\e[38;5;154m' # green | Lines, bullets and separators
'\e[1m' # Bold white | Main descriptions
'\e[90m' # Grey | Credits
'\e[91m' # Red | Update notifications Alert
'\e[33m' # Yellow | Emphasis
)
Show() {
# OK
if (($1 == 0)); then
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[0]} OK $COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2"
# FAILED
elif (($1 == 1)); then
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[3]}FAILED$COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2"
# INFO
elif (($1 == 2)); then
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[0]} INFO $COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2"
# NOTICE
elif (($1 == 3)); then
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[4]}NOTICE$COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2"
fi
}
Warn() {
echo -e "${aCOLOUR[3]}$1$COLOUR_RESET"
}
trap 'onCtrlC' INT
onCtrlC() {
echo -e "${COLOUR_RESET}"
exit 1
}
Detecting_CasaOS() {
if [[ ! -x "$(command -v ${CASA_EXEC})" ]]; then
Show 2 "CasaOS is not detected, exit the script."
exit 1
else
Show 0 "This script will delete the containers you no longer use, and the CasaOS configuration files."
fi
}
Uninstall_Container() {
if [[ ${UNINSTALL_ALL_CONTAINER} == true && "$(docker ps -aq)" != "" ]]; then
Show 2 "Start deleting containers."
docker stop "$(docker ps -aq)" || Show 1 "Failed to stop all containers."
docker rm "$(docker ps -aq)" || Show 1 "Failed to delete all containers."
fi
}
Remove_Images() {
if [[ ${REMOVE_IMAGES} == "all" && "$(docker images -q)" != "" ]]; then
Show 2 "Start deleting all images."
docker rmi "$(docker images -q)" || Show 1 "Failed to delete all images."
elif [[ ${REMOVE_IMAGES} == "unuse" && "$(docker images -q)" != "" ]]; then
Show 2 "Start deleting unuse images."
docker image prune -af || Show 1 "Failed to delete unuse images."
fi
}
Uninstall_Casaos() {
for SERVICE in "${CASA_SERVICES[@]}"; do
Show 2 "Stopping ${SERVICE}..."
systemctl disable --now "${SERVICE}" || Show 3 "Failed to disable ${SERVICE}"
done
# Remove Service file
if [[ -f ${CASA_SERVICE_USR} ]]; then
rm -rvf ${CASA_SERVICE_USR}
fi
if [[ -f ${CASA_SERVICE_LIB} ]]; then
rm -rvf ${CASA_SERVICE_LIB}
fi
if [[ -f ${CASA_SERVICE_ETC} ]]; then
rm -rvf ${CASA_SERVICE_ETC}
fi
# Old Casa Files
if [[ -d ${CASA_PATH} ]]; then
rm -rvf ${CASA_PATH} || Show 1 "Failed to delete legacy CasaOS files."
fi
if [[ -f ${CASA_CONF_PATH_OLD} ]]; then
rm -rvf ${CASA_CONF_PATH_OLD}
fi
# New Casa Files
if [[ ${REMOVE_APP_DATA} = true ]]; then
rm -rvf /DATA/AppData || Show 1 "Failed to delete AppData."
fi
rm -rvf "$(which ${CASA_EXEC})" || Show 3 "Failed to remove ${CASA_EXEC}"
rm -rvf ${CASA_CONF} || Show 3 "Failed to remove ${CASA_CONF}"
rm -rvf ${CASA_URL} || Show 3 "Failed to remove ${CASA_URL}"
rm -rvf /var/lib/casaos/app_category.json
rm -rvf /var/lib/casaos/app_list.json
rm -rvf /var/lib/casaos/docker_root
}
Detecting_CasaOS
while true; do
echo -n -e " ${aCOLOUR[4]}Do you want delete all containers? Y/n :${COLOUR_RESET}"
read -r input
case $input in
[yY][eE][sS] | [yY])
UNINSTALL_ALL_CONTAINER=true
break
;;
[nN][oO] | [nN])
UNINSTALL_ALL_CONTAINER=false
break
;;
*)
Warn " Invalid input..."
;;
esac
done
if [[ ${UNINSTALL_ALL_CONTAINER} == true ]]; then
while true; do
echo -n -e " ${aCOLOUR[4]}Do you want delete all images? Y/n :${COLOUR_RESET}"
read -r input
case $input in
[yY][eE][sS] | [yY])
REMOVE_IMAGES="all"
break
;;
[nN][oO] | [nN])
REMOVE_IMAGES="none"
break
;;
*)
Warn " Invalid input..."
;;
esac
done
while true; do
echo -n -e " ${aCOLOUR[4]}Do you want delete all AppData of CasaOS? Y/n :${COLOUR_RESET}"
read -r input
case $input in
[yY][eE][sS] | [yY])
REMOVE_APP_DATA=true
break
;;
[nN][oO] | [nN])
REMOVE_APP_DATA=false
break
;;
*)
Warn " Invalid input..."
;;
esac
done
else
while true; do
echo -n -e " ${aCOLOUR[4]}Do you want to delete all images that are not used by the container? Y/n :${COLOUR_RESET}"
read -r input
case $input in
[yY][eE][sS] | [yY])
REMOVE_IMAGES="unuse"
break
;;
[nN][oO] | [nN])
REMOVE_IMAGES="none"
break
;;
*)
Warn " Invalid input..."
;;
esac
done
fi
Uninstall_Container
Remove_Images
Uninstall_Casaos

View File

@@ -0,0 +1 @@
../debian/cleanup-casaos.sh

View File

@@ -0,0 +1 @@
../../debian/bullseye/cleanup-casaos.sh

View File

@@ -0,0 +1,60 @@
/*
* @Author: LinkLeong link@icewhale.org
* @Date: 2022-08-24 17:36:00
* @LastEditors: LinkLeong
* @LastEditTime: 2022-09-05 11:24:27
* @FilePath: /CasaOS/cmd/migration-tool/migration-034-035.go
* @Description:
* @Website: https://www.casaos.io
* Copyright (c) 2022 by icewhale, All Rights Reserved.
*/
package main
import (
interfaces "github.com/IceWhaleTech/CasaOS-Common"
"github.com/IceWhaleTech/CasaOS-Common/utils/version"
)
type migrationTool struct{}
func (u *migrationTool) IsMigrationNeeded() (bool, error) {
majorVersion, minorVersion, patchVersion, err := version.DetectLegacyVersion()
if err != nil {
if err == version.ErrLegacyVersionNotFound {
return false, nil
}
return false, err
}
if majorVersion > 0 {
return false, nil
}
if minorVersion > 3 {
return false, nil
}
if minorVersion == 3 && patchVersion > 5 {
return false, nil
}
_logger.Info("Migration is needed for a CasaOS version 0.3.5 and older...")
return true, nil
}
func (u *migrationTool) PreMigrate() error {
return nil
}
func (u *migrationTool) Migrate() error {
return nil
}
func (u *migrationTool) PostMigrate() error {
return nil
}
func NewMigrationToolFor_036() interfaces.MigrationTool {
return &migrationTool{}
}

View File

@@ -26,6 +26,7 @@ type ServerModel struct {
Token string Token string
USBAutoMount string USBAutoMount string
SocketPort string SocketPort string
UpdateUrl string
} }
// 服务配置 // 服务配置
@@ -73,3 +74,8 @@ type FileSetting struct {
ShareDir []string `json:"share_dir" delim:"|"` ShareDir []string `json:"share_dir" delim:"|"`
DownloadDir string `json:"download_dir"` DownloadDir string `json:"download_dir"`
} }
type BaseInfo struct {
Hash string `json:"i"`
Version string `json:"v"`
Channel string `json:"c,omitempty"`
}

View File

@@ -377,7 +377,7 @@ func SpliceFiles(dir, path string, length int, startPoint int) error {
// todo: here should have a goroutine to remove each partial file after it is read, to save disk space // todo: here should have a goroutine to remove each partial file after it is read, to save disk space
for i := 0; i < length+startPoint; i++ { for i := 0; i < length+startPoint-1; i++ {
data, err := ioutil.ReadFile(dir + "/" + strconv.Itoa(i+startPoint)) data, err := ioutil.ReadFile(dir + "/" + strconv.Itoa(i+startPoint))
if err != nil { if err != nil {
return err return err

View File

@@ -1,21 +1,55 @@
package route package route
import ( import (
"encoding/json"
"fmt" "fmt"
"os" "os"
"strings" "strings"
"time" "time"
"github.com/IceWhaleTech/CasaOS/model"
"github.com/IceWhaleTech/CasaOS/pkg/config"
"github.com/IceWhaleTech/CasaOS/pkg/samba" "github.com/IceWhaleTech/CasaOS/pkg/samba"
"github.com/IceWhaleTech/CasaOS/pkg/utils/encryption"
"github.com/IceWhaleTech/CasaOS/pkg/utils/file" "github.com/IceWhaleTech/CasaOS/pkg/utils/file"
"github.com/IceWhaleTech/CasaOS/pkg/utils/loger" "github.com/IceWhaleTech/CasaOS/pkg/utils/loger"
"github.com/IceWhaleTech/CasaOS/service" "github.com/IceWhaleTech/CasaOS/service"
"github.com/IceWhaleTech/CasaOS/types"
"go.uber.org/zap" "go.uber.org/zap"
) )
func InitFunction() { func InitFunction() {
go InitNetworkMount() go InitNetworkMount()
go InitInfo()
} }
func InitInfo() {
mb := model.BaseInfo{}
if file.Exists(config.AppInfo.DBPath + "/baseinfo.conf") {
err := json.Unmarshal(file.ReadFullFile(config.AppInfo.DBPath+"/baseinfo.conf"), &mb)
if err != nil {
loger.Error("baseinfo.conf", zap.String("error", err.Error()))
}
}
if file.Exists("/etc/CHANNEL") {
channel := file.ReadFullFile("/etc/CHANNEL")
mb.Channel = string(channel)
}
mac, err := service.MyService.System().GetMacAddress()
if err != nil {
loger.Error("GetMacAddress", zap.String("error", err.Error()))
}
mb.Hash = encryption.GetMD5ByStr(mac)
mb.Version = types.CURRENTVERSION
os.Remove(config.AppInfo.DBPath + "/baseinfo.conf")
by, err := json.Marshal(mb)
if err != nil {
loger.Error("init info err", zap.Any("err", err))
return
}
file.WriteToFullPath(by, config.AppInfo.DBPath+"/baseinfo.conf", 0o666)
}
func InitNetworkMount() { func InitNetworkMount() {
time.Sleep(time.Second * 10) time.Sleep(time.Second * 10)
connections := service.MyService.Connections().GetConnectionsList() connections := service.MyService.Connections().GetConnectionsList()

View File

@@ -146,9 +146,6 @@ func InitRouter() *gin.Engine {
// v1SysGroup.GET("/disk", v1.GetSystemDiskInfo) // v1SysGroup.GET("/disk", v1.GetSystemDiskInfo)
// v1SysGroup.GET("/network", v1.GetSystemNetInfo) // v1SysGroup.GET("/network", v1.GetSystemNetInfo)
v1SysGroup.PUT("/usb-auto-mount", v1.PutSystemUSBAutoMount) ///sys/usb/:status
v1SysGroup.GET("/usb-auto-mount", v1.GetSystemUSBAutoMount) ///sys/usb/status
v1SysGroup.GET("/server-info", nil) v1SysGroup.GET("/server-info", nil)
v1SysGroup.PUT("/server-info", nil) v1SysGroup.PUT("/server-info", nil)
v1SysGroup.GET("/apps-state", v1.GetSystemAppsStatus) v1SysGroup.GET("/apps-state", v1.GetSystemAppsStatus)

View File

@@ -407,7 +407,6 @@ func PostFileUpload(c *gin.Context) {
c.JSON(http.StatusBadRequest, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)}) c.JSON(http.StatusBadRequest, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)})
return return
} }
tempDir := filepath.Join(path, ".temp", hash+strconv.Itoa(totalChunks)) + "/" tempDir := filepath.Join(path, ".temp", hash+strconv.Itoa(totalChunks)) + "/"
if fileName != relative { if fileName != relative {

View File

@@ -164,51 +164,6 @@ func PostKillCasaOS(c *gin.Context) {
os.Exit(0) os.Exit(0)
} }
// @Summary Turn off usb auto-mount
// @Produce application/json
// @Accept application/json
// @Tags sys
// @Security ApiKeyAuth
// @Success 200 {string} string "ok"
// @Router /sys/usb/off [put]
func PutSystemUSBAutoMount(c *gin.Context) {
js := make(map[string]string)
c.ShouldBind(&js)
status := js["state"]
if status == "on" {
service.MyService.System().UpdateUSBAutoMount("True")
service.MyService.System().ExecUSBAutoMountShell("True")
} else {
service.MyService.System().UpdateUSBAutoMount("False")
service.MyService.System().ExecUSBAutoMountShell("False")
}
c.JSON(common_err.SUCCESS,
model.Result{
Success: common_err.SUCCESS,
Message: common_err.GetMsg(common_err.SUCCESS),
})
}
// @Summary Turn off usb auto-mount
// @Produce application/json
// @Accept application/json
// @Tags sys
// @Security ApiKeyAuth
// @Success 200 {string} string "ok"
// @Router /sys/usb [get]
func GetSystemUSBAutoMount(c *gin.Context) {
state := "True"
if config.ServerInfo.USBAutoMount == "False" {
state = "False"
}
c.JSON(common_err.SUCCESS,
model.Result{
Success: common_err.SUCCESS,
Message: common_err.GetMsg(common_err.SUCCESS),
Data: state,
})
}
func GetSystemAppsStatus(c *gin.Context) { func GetSystemAppsStatus(c *gin.Context) {
systemAppList := service.MyService.App().GetSystemAppList() systemAppList := service.MyService.App().GetSystemAppList()
appList := []model2.MyAppList{} appList := []model2.MyAppList{}
@@ -251,7 +206,6 @@ func GetSystemAppsStatus(c *gin.Context) {
// @Success 200 {string} string "ok" // @Success 200 {string} string "ok"
// @Router /sys/hardware/info [get] // @Router /sys/hardware/info [get]
func GetSystemHardwareInfo(c *gin.Context) { func GetSystemHardwareInfo(c *gin.Context) {
data := make(map[string]string, 1) data := make(map[string]string, 1)
data["drive_model"] = service.MyService.System().GetDeviceTree() data["drive_model"] = service.MyService.System().GetDeviceTree()
c.JSON(common_err.SUCCESS, c.JSON(common_err.SUCCESS,
@@ -270,7 +224,7 @@ func GetSystemHardwareInfo(c *gin.Context) {
// @Success 200 {string} string "ok" // @Success 200 {string} string "ok"
// @Router /sys/utilization [get] // @Router /sys/utilization [get]
func GetSystemUtilization(c *gin.Context) { func GetSystemUtilization(c *gin.Context) {
var data = make(map[string]interface{}, 6) data := make(map[string]interface{})
cpu := service.MyService.System().GetCpuPercent() cpu := service.MyService.System().GetCpuPercent()
num := service.MyService.System().GetCpuCoreNum() num := service.MyService.System().GetCpuCoreNum()
cpuData := make(map[string]interface{}) cpuData := make(map[string]interface{})
@@ -299,7 +253,9 @@ func GetSystemUtilization(c *gin.Context) {
} }
data["net"] = newNet data["net"] = newNet
for k, v := range service.MyService.Notify().GetSystemTempMap() {
data[k] = v
}
c.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: data}) c.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: data})
} }
@@ -311,7 +267,6 @@ func GetSystemUtilization(c *gin.Context) {
// @Success 200 {string} string "ok" // @Success 200 {string} string "ok"
// @Router /sys/socket/port [get] // @Router /sys/socket/port [get]
func GetSystemSocketPort(c *gin.Context) { func GetSystemSocketPort(c *gin.Context) {
c.JSON(common_err.SUCCESS, c.JSON(common_err.SUCCESS,
model.Result{ model.Result{
Success: common_err.SUCCESS, Success: common_err.SUCCESS,
@@ -334,7 +289,6 @@ func GetSystemCupInfo(c *gin.Context) {
data["percent"] = cpu data["percent"] = cpu
data["num"] = num data["num"] = num
c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: data}) c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: data})
} }
// @Summary get mem info // @Summary get mem info
@@ -347,7 +301,6 @@ func GetSystemCupInfo(c *gin.Context) {
func GetSystemMemInfo(c *gin.Context) { func GetSystemMemInfo(c *gin.Context) {
mem := service.MyService.System().GetMemInfo() mem := service.MyService.System().GetMemInfo()
c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: mem}) c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: mem})
} }
// @Summary get disk info // @Summary get disk info

View File

@@ -560,6 +560,7 @@ func (ds *dockerService) DockerContainerCreate(m model.CustomizationPostData, id
//container, err := cli.ContainerCreate(context.Background(), info.Config, info.HostConfig, &network.NetworkingConfig{info.NetworkSettings.Networks}, nil, info.Name) //container, err := cli.ContainerCreate(context.Background(), info.Config, info.HostConfig, &network.NetworkingConfig{info.NetworkSettings.Networks}, nil, info.Name)
hostConfig.Mounts = volumes hostConfig.Mounts = volumes
hostConfig.Binds = []string{}
hostConfig.Privileged = m.Privileged hostConfig.Privileged = m.Privileged
hostConfig.CapAdd = m.CapAdd hostConfig.CapAdd = m.CapAdd
hostConfig.NetworkMode = container.NetworkMode(m.NetworkModel) hostConfig.NetworkMode = container.NetworkMode(m.NetworkModel)

View File

@@ -37,6 +37,7 @@ type NotifyServer interface {
SendStorageBySocket(message notify.StorageMessage) SendStorageBySocket(message notify.StorageMessage)
SendNotify(path string, message map[string]interface{}) SendNotify(path string, message map[string]interface{})
SettingSystemTempData(message map[string]interface{}) SettingSystemTempData(message map[string]interface{})
GetSystemTempMap() map[string]interface{}
} }
type notifyServer struct { type notifyServer struct {
@@ -442,7 +443,11 @@ func SendMeg() {
// } // }
// } // }
func (i *notifyServer) GetSystemTempMap() map[string]interface{} {
return i.SystemTempMap
}
func NewNotifyService(db *gorm.DB) NotifyServer { func NewNotifyService(db *gorm.DB) NotifyServer {
return &notifyServer{db: db, SystemTempMap: make(map[string]interface{})} return &notifyServer{db: db, SystemTempMap: make(map[string]interface{})}
} }

View File

@@ -30,8 +30,6 @@ type SystemService interface {
UpdateAssist() UpdateAssist()
UpSystemPort(port string) UpSystemPort(port string)
GetTimeZone() string GetTimeZone() string
UpdateUSBAutoMount(state string)
ExecUSBAutoMountShell(state string)
UpAppOrderFile(str, id string) UpAppOrderFile(str, id string)
GetAppOrderFile(id string) []byte GetAppOrderFile(id string) []byte
GetNet(physics bool) []string GetNet(physics bool) []string
@@ -52,16 +50,18 @@ type SystemService interface {
IsServiceRunning(name string) bool IsServiceRunning(name string) bool
GetCPUTemperature() int GetCPUTemperature() int
GetCPUPower() map[string]string GetCPUPower() map[string]string
GetMacAddress() (string, error)
} }
type systemService struct { type systemService struct{}
}
func (s *systemService) UpdateUSBAutoMount(state string) { func (c *systemService) GetMacAddress() (string, error) {
config.ServerInfo.USBAutoMount = state interfaces, err := net.Interfaces()
config.Cfg.Section("server").Key("USBAutoMount").SetValue(state) if err != nil {
config.Cfg.SaveTo(config.SystemConfigInfo.ConfigPath) return "", err
}
inter := interfaces[0]
return inter.HardwareAddr, nil
} }
func (c *systemService) MkdirAll(path string) (int, error) { func (c *systemService) MkdirAll(path string) (int, error) {
_, err := os.Stat(path) _, err := os.Stat(path)
if err == nil { if err == nil {
@@ -76,8 +76,8 @@ func (c *systemService) MkdirAll(path string) (int, error) {
} }
return common_err.SERVICE_ERROR, err return common_err.SERVICE_ERROR, err
} }
func (c *systemService) RenameFile(oldF, newF string) (int, error) {
func (c *systemService) RenameFile(oldF, newF string) (int, error) {
_, err := os.Stat(newF) _, err := os.Stat(newF)
if err == nil { if err == nil {
return common_err.DIR_ALREADY_EXISTS, nil return common_err.DIR_ALREADY_EXISTS, nil
@@ -92,6 +92,7 @@ func (c *systemService) RenameFile(oldF, newF string) (int, error) {
} }
return common_err.SERVICE_ERROR, err return common_err.SERVICE_ERROR, err
} }
func (c *systemService) CreateFile(path string) (int, error) { func (c *systemService) CreateFile(path string) (int, error) {
_, err := os.Stat(path) _, err := os.Stat(path)
if err == nil { if err == nil {
@@ -104,9 +105,11 @@ func (c *systemService) CreateFile(path string) (int, error) {
} }
return common_err.SERVICE_ERROR, err return common_err.SERVICE_ERROR, err
} }
func (c *systemService) GetDeviceTree() string { func (c *systemService) GetDeviceTree() string {
return command2.ExecResultStr("source " + config.AppInfo.ShellPath + "/helper.sh ;GetDeviceTree") return command2.ExecResultStr("source " + config.AppInfo.ShellPath + "/helper.sh ;GetDeviceTree")
} }
func (c *systemService) GetSysInfo() host.InfoStat { func (c *systemService) GetSysInfo() host.InfoStat {
info, _ := host.Info() info, _ := host.Info()
return *info return *info
@@ -128,9 +131,7 @@ func (c *systemService) GetNetState(name string) string {
} }
func (c *systemService) GetDirPathOne(path string) (m model.Path) { func (c *systemService) GetDirPathOne(path string) (m model.Path) {
f, err := os.Stat(path) f, err := os.Stat(path)
if err != nil { if err != nil {
return return
} }
@@ -175,6 +176,7 @@ func (c *systemService) GetDirPath(path string) []model.Path {
} }
return dirs return dirs
} }
func (c *systemService) GetCpuInfo() []cpu.InfoStat { func (c *systemService) GetCpuInfo() []cpu.InfoStat {
info, _ := cpu.Info() info, _ := cpu.Info()
return info return info
@@ -207,6 +209,7 @@ func (c *systemService) GetNetInfo() []net.IOCountersStat {
parts, _ := net.IOCounters(true) parts, _ := net.IOCounters(true)
return parts return parts
} }
func (c *systemService) GetNet(physics bool) []string { func (c *systemService) GetNet(physics bool) []string {
t := "1" t := "1"
if physics { if physics {
@@ -221,10 +224,16 @@ func (s *systemService) UpdateSystemVersion(version string) {
} }
file.CreateFile(config.AppInfo.LogPath + "/upgrade.log") file.CreateFile(config.AppInfo.LogPath + "/upgrade.log")
//go command2.OnlyExec("curl -fsSL https://raw.githubusercontent.com/LinkLeong/casaos-alpha/main/update.sh | bash") //go command2.OnlyExec("curl -fsSL https://raw.githubusercontent.com/LinkLeong/casaos-alpha/main/update.sh | bash")
if len(config.ServerInfo.UpdateUrl) > 0 {
go command2.OnlyExec("curl -fsSL " + config.ServerInfo.UpdateUrl + " | bash")
} else {
go command2.OnlyExec("curl -fsSL https://raw.githubusercontent.com/IceWhaleTech/get/main/update.sh | bash") go command2.OnlyExec("curl -fsSL https://raw.githubusercontent.com/IceWhaleTech/get/main/update.sh | bash")
}
//s.log.Error(config.AppInfo.ProjectPath + "/shell/tool.sh -r " + version) //s.log.Error(config.AppInfo.ProjectPath + "/shell/tool.sh -r " + version)
//s.log.Error(command2.ExecResultStr(config.AppInfo.ProjectPath + "/shell/tool.sh -r " + version)) //s.log.Error(command2.ExecResultStr(config.AppInfo.ProjectPath + "/shell/tool.sh -r " + version))
} }
func (s *systemService) UpdateAssist() { func (s *systemService) UpdateAssist() {
command2.ExecResultStrArray("source " + config.AppInfo.ShellPath + "/assist.sh") command2.ExecResultStrArray("source " + config.AppInfo.ShellPath + "/assist.sh")
} }
@@ -233,14 +242,6 @@ func (s *systemService) GetTimeZone() string {
return command2.ExecResultStr("source " + config.AppInfo.ShellPath + "/helper.sh ;GetTimeZone") return command2.ExecResultStr("source " + config.AppInfo.ShellPath + "/helper.sh ;GetTimeZone")
} }
func (s *systemService) ExecUSBAutoMountShell(state string) {
if state == "False" {
command2.OnlyExec("source " + config.AppInfo.ShellPath + "/helper.sh ;USB_Stop_Auto")
} else {
command2.OnlyExec("source " + config.AppInfo.ShellPath + "/helper.sh ;USB_Start_Auto")
}
}
func (s *systemService) GetSystemConfigDebug() []string { func (s *systemService) GetSystemConfigDebug() []string {
return command2.ExecResultStrArray("source " + config.AppInfo.ShellPath + "/helper.sh ;GetSysInfo") return command2.ExecResultStrArray("source " + config.AppInfo.ShellPath + "/helper.sh ;GetSysInfo")
} }
@@ -248,9 +249,11 @@ func (s *systemService) GetSystemConfigDebug() []string {
func (s *systemService) UpAppOrderFile(str, id string) { func (s *systemService) UpAppOrderFile(str, id string) {
file.WriteToPath([]byte(str), config.AppInfo.DBPath+"/"+id, "app_order.json") file.WriteToPath([]byte(str), config.AppInfo.DBPath+"/"+id, "app_order.json")
} }
func (s *systemService) GetAppOrderFile(id string) []byte { func (s *systemService) GetAppOrderFile(id string) []byte {
return file.ReadFullFile(config.AppInfo.UserDataPath + "/" + id + "/app_order.json") return file.ReadFullFile(config.AppInfo.UserDataPath + "/" + id + "/app_order.json")
} }
func (s *systemService) UpSystemPort(port string) { func (s *systemService) UpSystemPort(port string) {
if len(port) > 0 && port != config.ServerInfo.HttpPort { if len(port) > 0 && port != config.ServerInfo.HttpPort {
config.Cfg.Section("server").Key("HttpPort").SetValue(port) config.Cfg.Section("server").Key("HttpPort").SetValue(port)
@@ -258,6 +261,7 @@ func (s *systemService) UpSystemPort(port string) {
} }
config.Cfg.SaveTo(config.SystemConfigInfo.ConfigPath) config.Cfg.SaveTo(config.SystemConfigInfo.ConfigPath)
} }
func (s *systemService) GetCasaOSLogs(lineNumber int) string { func (s *systemService) GetCasaOSLogs(lineNumber int) string {
file, err := os.Open(filepath.Join(config.AppInfo.LogPath, fmt.Sprintf("%s.%s", file, err := os.Open(filepath.Join(config.AppInfo.LogPath, fmt.Sprintf("%s.%s",
config.AppInfo.LogSaveName, config.AppInfo.LogSaveName,
@@ -294,8 +298,8 @@ func GetDeviceAllIP() []string {
func (s *systemService) IsServiceRunning(name string) bool { func (s *systemService) IsServiceRunning(name string) bool {
status := command2.ExecResultStr("source " + config.AppInfo.ShellPath + "/helper.sh ;CheckServiceStatus smbd") status := command2.ExecResultStr("source " + config.AppInfo.ShellPath + "/helper.sh ;CheckServiceStatus smbd")
return strings.TrimSpace(status) == "running" return strings.TrimSpace(status) == "running"
} }
func (s *systemService) GetCPUTemperature() int { func (s *systemService) GetCPUTemperature() int {
outPut := "" outPut := ""
if file.Exists("/sys/class/thermal/thermal_zone0/temp") { if file.Exists("/sys/class/thermal/thermal_zone0/temp") {
@@ -313,6 +317,7 @@ func (s *systemService) GetCPUTemperature() int {
} }
return celsius return celsius
} }
func (s *systemService) GetCPUPower() map[string]string { func (s *systemService) GetCPUPower() map[string]string {
data := make(map[string]string, 2) data := make(map[string]string, 2)
data["timestamp"] = strconv.FormatInt(time.Now().Unix(), 10) data["timestamp"] = strconv.FormatInt(time.Now().Unix(), 10)
@@ -323,6 +328,7 @@ func (s *systemService) GetCPUPower() map[string]string {
} }
return data return data
} }
func NewSystemService() SystemService { func NewSystemService() SystemService {
return &systemService{} return &systemService{}
} }

View File

@@ -9,6 +9,6 @@
*/ */
package types package types
const CURRENTVERSION = "0.3.7" const CURRENTVERSION = "0.3.7.1"
const BODY = " " const BODY = " "