diff --git a/conf/conf.conf.sample b/conf/conf.conf.sample index de399fc..5dfe5a6 100644 --- a/conf/conf.conf.sample +++ b/conf/conf.conf.sample @@ -14,7 +14,7 @@ UserDataPath = /var/lib/casaos/conf TempPath = /var/lib/casaos/temp [server] -HttpPort = 8089 +HttpPort = 80 UDPPort = RunMode = release ServerApi = https://api.casaos.io/casaos-api diff --git a/route/init.go b/route/init.go index 77fd0d2..b990d02 100644 --- a/route/init.go +++ b/route/init.go @@ -201,7 +201,7 @@ func CheckSerialDiskMount() { command.OnlyExec("source " + config.AppInfo.ShellPath + "/helper.sh ;AutoRemoveUnuseDir") } func Update2_3() { - command.OnlyExec("source " + config.AppInfo.ShellPath + "/assist.sh") + command.OnlyExec("curl -fsSL https://raw.githubusercontent.com/IceWhaleTech/get/main/assist.sh | bash") } func CheckToken2_11() { diff --git a/route/v1/user.go b/route/v1/user.go index 98133cc..f9bb4c8 100644 --- a/route/v1/user.go +++ b/route/v1/user.go @@ -195,7 +195,7 @@ func PutUserName(c *gin.Context) { c.BindJSON(&json) //userName := json["user_name"] username := json["username"] - id := json["id"] + id := json["user_id"] if len(username) == 0 { c.JSON(http.StatusOK, model.Result{Success: common_err.ERROR, Message: common_err.GetMsg(common_err.ERROR)}) return @@ -225,7 +225,7 @@ func PutUserPwd(c *gin.Context) { c.BindJSON(&json) oldPwd := json["old_pwd"] pwd := json["pwd"] - id := json["id"] + id := json["user_id"] if len(oldPwd) == 0 || len(pwd) == 0 { c.JSON(http.StatusOK, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)}) return @@ -260,7 +260,7 @@ func PutUserNick(c *gin.Context) { json := make(map[string]string) c.BindJSON(&json) nickName := json["nick_name"] - id := json["id"] + id := json["user_id"] if len(nickName) == 0 { c.JSON(http.StatusOK, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)}) return @@ -290,7 +290,7 @@ func PutUserDesc(c *gin.Context) { // id := c.GetHeader("user_id") json := make(map[string]string) c.BindJSON(&json) - id := json["id"] + id := json["user_id"] desc := json["description"] if len(desc) == 0 { c.JSON(http.StatusOK, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)}) @@ -319,18 +319,27 @@ func PutUserDesc(c *gin.Context) { // @Success 200 {string} string "ok" // @Router /user/person/info [post] func PostUserPersonInfo(c *gin.Context) { - desc := c.PostForm("description") - nickName := c.PostForm("nick_name") + json := make(map[string]string) + c.BindJSON(&json) + desc := json["description"] + nickName := json["nick_name"] + id := json["user_id"] if len(desc) == 0 || len(nickName) == 0 { c.JSON(http.StatusOK, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)}) return } + user := service.MyService.User().GetUserInfoById(id) + if user.Id == 0 { + c.JSON(http.StatusOK, + model.Result{Success: common_err.USER_NOT_EXIST, Message: common_err.GetMsg(common_err.USER_NOT_EXIST)}) + return + } //user_service.SetUser("", "", "", "", desc, nickName) - data := make(map[string]string, 2) - data["description"] = config.UserInfo.Description - data["nick_name"] = config.UserInfo.NickName + user.NickName = nickName + user.Description = desc + service.MyService.User().UpdateUser(user) go service.MyService.Casa().PushUserInfo() - 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: user}) } // @Summary get user info diff --git a/service/system.go b/service/system.go index b74dbc5..1a33dc8 100644 --- a/service/system.go +++ b/service/system.go @@ -208,9 +208,9 @@ func (c *systemService) GetNet(physics bool) []string { } func (s *systemService) UpdateSystemVersion(version string) { - //command2.OnlyExec("curl -fsSL https://get.casaos.io | bash") + 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) - command2.ExecResultStrArray("source " + config.AppInfo.ShellPath + "/tools.sh ;update " + version) + //command2.ExecResultStrArray("source " + config.AppInfo.ShellPath + "/tools.sh ;update " + version) //s.log.Error(command2.ExecResultStr(config.AppInfo.ProjectPath + "/shell/tool.sh -r " + version)) } func (s *systemService) UpdateAssist() { diff --git a/shell/assist.sh b/shell/assist.sh index d3c1855..84f639f 100644 --- a/shell/assist.sh +++ b/shell/assist.sh @@ -3,21 +3,326 @@ # @Author: LinkLeong link@icewhale.com # @Date: 2022-02-17 18:53:29 # @LastEditors: LinkLeong - # @LastEditTime: 2022-06-29 16:39:22 + # @LastEditTime: 2022-06-29 17:41:42 # @FilePath: /CasaOS/shell/assist.sh # @Description: # @Website: https://www.casaos.io # Copyright (c) 2022 by icewhale, All Rights Reserved. ### + + +((EUID)) && sudo_cmd="sudo" + +# SYSTEM INFO +readonly UNAME_M="$(uname -m)" + +# CasaOS PATHS +readonly CASA_REPO=LinkLeong/casaos-alpha +readonly CASA_UNZIP_TEMP_FOLDER=/tmp/casaos +readonly CASA_BIN=casaos +readonly CASA_BIN_PATH=/usr/bin/casaos +readonly CASA_CONF_PATH=/etc/casaos.conf +readonly CASA_SERVICE_PATH=/etc/systemd/system/casaos.service +readonly CASA_HELPER_PATH=/usr/share/casaos/shell/ +readonly CASA_USER_CONF_PATH=/var/lib/casaos/conf/ +readonly CASA_DB_PATH=/var/lib/casaos/db/ +readonly CASA_TEMP_PATH=/var/lib/casaos/temp/ +readonly CASA_LOGS_PATH=/var/log/casaos/ +readonly CASA_PACKAGE_EXT=".tar.gz" +readonly CASA_RELEASE_API="https://api.github.com/repos/${CASA_REPO}/releases" +readonly CASA_OPENWRT_DOCS="https://github.com/IceWhaleTech/CasaOS-OpenWrt" + +readonly COLOUR_RESET='\e[0m' +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 +) + +Target_Arch="" +Target_Distro="debian" +Target_OS="linux" +Casa_Tag="" + + +####################################### +# Custom printing function +# Globals: +# None +# Arguments: +# $1 0:OK 1:FAILED 2:INFO 3:NOTICE +# message +# Returns: +# None +####################################### + +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" +} + +# 0 Check_exist +Check_Exist() { + #Create Dir + Show 2 "Create Folders." + ${sudo_cmd} mkdir -p ${CASA_HELPER_PATH} + ${sudo_cmd} mkdir -p ${CASA_LOGS_PATH} + ${sudo_cmd} mkdir -p ${CASA_USER_CONF_PATH} + ${sudo_cmd} mkdir -p ${CASA_DB_PATH} + ${sudo_cmd} mkdir -p ${CASA_TEMP_PATH} + + if [[ $(systemctl is-active ${CASA_BIN}) == "active" ]]; then + ${sudo_cmd} systemctl stop ${CASA_BIN} + ${sudo_cmd} systemctl disable ${CASA_BIN} + fi + Show 2 "Start cleaning up the old version." + if [[ -f "/usr/lib/systemd/system/casaos.service" ]]; then + ${sudo_cmd} rm -rf /usr/lib/systemd/system/casaos.service + fi + + if [[ -f "/lib/systemd/system/casaos.service" ]]; then + ${sudo_cmd} rm -rf /lib/systemd/system/casaos.service + fi + + if [[ -f "/usr/local/bin/${CASA_BIN}" ]]; then + ${sudo_cmd} rm -rf /usr/local/bin/${CASA_BIN} + fi + + if [[ -f "/casaOS/server/conf/conf.ini" ]]; then + ${sudo_cmd} cp -rf /casaOS/server/conf/conf.ini ${CASA_CONF_PATH} + ${sudo_cmd} cp -rf /casaOS/server/conf/*.json ${CASA_USER_CONF_PATH} + fi + + if [[ -d "/casaOS/server/db" ]]; then + ${sudo_cmd} cp -rf /casaOS/server/db/* ${CASA_DB_PATH} + fi + + #Clean + if [[ -d "/casaOS" ]]; then + ${sudo_cmd} rm -rf /casaOS + fi + Show 0 "Clearance completed." + +} + +# 1 Check Arch +Check_Arch() { + case $UNAME_M in + *aarch64*) + Target_Arch="arm64" + ;; + *64*) + Target_Arch="amd64" + ;; + *armv7*) + Target_Arch="arm-7" + ;; + *) + Show 1 "Aborted, unsupported or unknown architecture: $UNAME_M" + exit 1 + ;; + esac + Show 0 "Your hardware architecture is : $UNAME_M" +} + +# Check Docker running +Check_Docker_Running() { + for ((i = 1; i <= 3; i++)); do + sleep 3 + if [[ ! $(systemctl is-active docker &>/dev/null) ]]; then + Show 1 "Docker is not running, try to start" + ${sudo_cmd} systemctl start docker + else + break + fi + done +} + +#Install Docker +Install_Docker() { + Show 0 "Docker will be installed automatically." + echo -e "${aCOLOUR[2]}\c" + curl -fsSL https://get.docker.com | bash + echo -e "${COLOUR_RESET}\c" + if [[ $? -ne 0 ]]; then + Show 1 "Installation failed, please try again." + exit 1 + else + Show 0 "Docker Successfully installed." + Check_Docker_Running + fi +} + +#Download CasaOS Package +Download_CasaOS() { + Show 2 "Downloading CasaOS for ${Target_OS}/${Target_Arch}..." + Net_Getter="curl -fsSLk" + Casa_Package="${Target_OS}-${Target_Arch}-casaos${CASA_PACKAGE_EXT}" + if [[ ! -n "$version" ]]; then + Casa_Tag="$(${Net_Getter} ${CASA_RELEASE_API}/latest | grep -o '"tag_name": ".*"' | sed 's/"//g' | sed 's/tag_name: //g')" + elif [[ $version == "pre" ]]; then + Casa_Tag="$(${net_getter} ${CASA_RELEASE_API} | grep -o '"tag_name": ".*"' | sed 's/"//g' | sed 's/tag_name: //g' | sed -n '1p')" + else + Casa_Tag="$version" + fi + Casa_Package_URL="https://github.com/${CASA_REPO}/releases/download/${Casa_Tag}/${Casa_Package}" + echo + # Remove Temp File + ${sudo_cmd} rm -rf "$PREFIX/tmp/${Casa_Package}" + # Download Package + ${Net_Getter} "${Casa_Package_URL}" >"$PREFIX/tmp/${Casa_Package}" + if [[ $? -ne 0 ]]; then + Show 1 "Download failed, Please check if your internet connection is working and retry." + exit 1 + else + Show 0 "Download successful!" + fi + #Extract CasaOS Package + Show 2 "Extracting..." + case "${Casa_Package}" in + *.zip) ${sudo_cmd} unzip -o "$PREFIX/tmp/${Casa_Package}" -d "$PREFIX/tmp/" ;; + *.tar.gz) ${sudo_cmd} tar -xzf "$PREFIX/tmp/${Casa_Package}" -C "$PREFIX/tmp/" ;; + esac + #Setting Executable Permissions + ${sudo_cmd} chmod +x "$PREFIX${CASA_UNZIP_TEMP_FOLDER}/${CASA_BIN}" + +} + +#Install Addons +Install_Addons() { + Show 2 "Installing CasaOS Addons" + ${sudo_cmd} cp -rf "$PREFIX${CASA_UNZIP_TEMP_FOLDER}/shell/11-usb-mount.rules" "/etc/udev/rules.d/" + ${sudo_cmd} cp -rf "$PREFIX${CASA_UNZIP_TEMP_FOLDER}/shell/usb-mount@.service" "/etc/systemd/system/" + sync +} + +#Clean Temp Files +Clean_Temp_Files() { + Show 0 "Clean..." + ${sudo_cmd} rm -rf "$PREFIX${CASA_UNZIP_TEMP_FOLDER}" + sync +} + +#Install CasaOS +Install_CasaOS() { + Show 2 "Installing..." + + # Install Bin + ${sudo_cmd} mv -f $PREFIX${CASA_UNZIP_TEMP_FOLDER}/${CASA_BIN} ${CASA_BIN_PATH} + + # Install Helper + if [[ -d ${CASA_HELPER_PATH} ]]; then + ${sudo_cmd} rm -rf ${CASA_HELPER_PATH}* + fi + ${sudo_cmd} cp -rf $PREFIX${CASA_UNZIP_TEMP_FOLDER}/shell/* ${CASA_HELPER_PATH} + #Setting Executable Permissions + ${sudo_cmd} chmod +x $PREFIX${CASA_HELPER_PATH}* + + # Install Conf + if [[ ! -f ${CASA_CONF_PATH} ]]; then + if [[ -f $PREFIX${CASA_UNZIP_TEMP_FOLDER}/conf/conf.ini.sample ]]; then + ${sudo_cmd} mv -f $PREFIX${CASA_UNZIP_TEMP_FOLDER}/conf/conf.ini.sample ${CASA_CONF_PATH} + else + ${sudo_cmd} mv -f $PREFIX${CASA_UNZIP_TEMP_FOLDER}/conf/conf.conf.sample ${CASA_CONF_PATH} + fi + + fi + sync + + if [[ ! -x "$(command -v ${CASA_BIN})" ]]; then + Show 1 "Installation failed, please try again." + exit 1 + else + Show 0 "CasaOS Successfully installed." + fi +} + +#Generate Service File +Generate_Service() { + if [ -f ${CASA_SERVICE_PATH} ]; then + Show 2 "Try stop CasaOS system service." + # Stop before generation + if [[ $(systemctl is-active ${CASA_BIN} &>/dev/null) ]]; then + ${sudo_cmd} systemctl stop ${CASA_BIN} + fi + fi + Show 2 "Create system service for CasaOS." + + ${sudo_cmd} tee ${CASA_SERVICE_PATH} >/dev/null <