From 727aca564b5c73a0b4f1e35b5055a8a6f196be3f Mon Sep 17 00:00:00 2001 From: John Guan Date: Tue, 6 Sep 2022 20:40:14 +0800 Subject: [PATCH 1/2] Update CHANGELOG.md Signed-off-by: John Guan --- CHANGELOG.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf48de8f0..9058ae4a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,11 +22,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [0.3.6-alpha.1] - 2022-09-06 ### Added -- [System] Added display of power and temperature to performance widget (Intel) -- [Apps] Added support for adding custom links in the APP module +- [System] Added power and temperature info to performance widget (Intel) +- [Apps] Custom links can be added to Apps section ### Fixed -- [Apps] Fixed the problem of not being able to modify the application pairing ([#510](https://github.com/IceWhaleTech/CasaOS/issues/510)) +- [Apps] Fixed the problem of not being able to modify some App settings ([#510](https://github.com/IceWhaleTech/CasaOS/issues/510)) + ### Changed - [System] Architecture optimization. Improved performance. From 314dbdab5767891698fe91cb023e658773b79b24 Mon Sep 17 00:00:00 2001 From: "a624669980@163.com" Date: Fri, 9 Sep 2022 11:28:30 +0800 Subject: [PATCH 2/2] add shell script --- .gitignore | 1 - .../cleanup/script.d/01-cleanup-casaos.sh | 0 .../sysroot/usr/share/casaos/shell/assist.sh | 3 + .../share/casaos/shell/delete-old-service.sh | 105 +++++ .../sysroot/usr/share/casaos/shell/helper.sh | 388 ++++++++++++++++++ .../sysroot/usr/share/casaos/shell/update.sh | 12 + .../usr/share/casaos/shell/usb-mount.sh | 136 ++++++ .../usr/share/casaos/shell/usb-mount@.service | 8 + 8 files changed, 652 insertions(+), 1 deletion(-) create mode 100644 build/sysroot/usr/share/casaos/cleanup/script.d/01-cleanup-casaos.sh create mode 100644 build/sysroot/usr/share/casaos/shell/assist.sh create mode 100644 build/sysroot/usr/share/casaos/shell/delete-old-service.sh create mode 100644 build/sysroot/usr/share/casaos/shell/helper.sh create mode 100644 build/sysroot/usr/share/casaos/shell/update.sh create mode 100644 build/sysroot/usr/share/casaos/shell/usb-mount.sh create mode 100644 build/sysroot/usr/share/casaos/shell/usb-mount@.service diff --git a/.gitignore b/.gitignore index 75580a0d9..51d11d0a2 100644 --- a/.gitignore +++ b/.gitignore @@ -33,7 +33,6 @@ gen /conf/conf.json __debug_bin main -CasaOS github.com .all-contributorsrc dist \ No newline at end of file diff --git a/build/sysroot/usr/share/casaos/cleanup/script.d/01-cleanup-casaos.sh b/build/sysroot/usr/share/casaos/cleanup/script.d/01-cleanup-casaos.sh new file mode 100644 index 000000000..e69de29bb diff --git a/build/sysroot/usr/share/casaos/shell/assist.sh b/build/sysroot/usr/share/casaos/shell/assist.sh new file mode 100644 index 000000000..7a693aac0 --- /dev/null +++ b/build/sysroot/usr/share/casaos/shell/assist.sh @@ -0,0 +1,3 @@ +#!/bin/bash + + diff --git a/build/sysroot/usr/share/casaos/shell/delete-old-service.sh b/build/sysroot/usr/share/casaos/shell/delete-old-service.sh new file mode 100644 index 000000000..41ccb8885 --- /dev/null +++ b/build/sysroot/usr/share/casaos/shell/delete-old-service.sh @@ -0,0 +1,105 @@ +#!/bin/bash +### + # @Author: LinkLeong link@icewhale.com + # @Date: 2022-06-30 10:08:33 + # @LastEditors: LinkLeong + # @LastEditTime: 2022-07-01 11:17:54 + # @FilePath: /CasaOS/shell/delete-old-service.sh + # @Description: +### + +((EUID)) && sudo_cmd="sudo" + +# SYSTEM INFO +readonly UNAME_M="$(uname -m)" + +# CasaOS PATHS +readonly CASA_REPO=IceWhaleTech/CasaOS +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} + + + Show 2 "Start cleaning up the old version." + + ${sudo_cmd} rm -rf /usr/lib/systemd/system/casaos.service + + ${sudo_cmd} rm -rf /lib/systemd/system/casaos.service + + ${sudo_cmd} rm -rf /usr/local/bin/${CASA_BIN} + + #Clean + if [[ -d "/casaOS" ]]; then + ${sudo_cmd} rm -rf /casaOS + fi + Show 0 "Clearance completed." + + $sudo_cmd systemctl restart ${CASA_BIN} +} +Check_Exist diff --git a/build/sysroot/usr/share/casaos/shell/helper.sh b/build/sysroot/usr/share/casaos/shell/helper.sh new file mode 100644 index 000000000..cfb001d0c --- /dev/null +++ b/build/sysroot/usr/share/casaos/shell/helper.sh @@ -0,0 +1,388 @@ +#!/bin/bash + +# 获取系统信息 +GetSysInfo() { + if [ -s "/etc/redhat-release" ]; then + SYS_VERSION=$(cat /etc/redhat-release) + elif [ -s "/etc/issue" ]; then + SYS_VERSION=$(cat /etc/issue) + fi + SYS_INFO=$(uname -a) + SYS_BIT=$(getconf LONG_BIT) + MEM_TOTAL=$(free -m | grep Mem | awk '{print $2}') + CPU_INFO=$(getconf _NPROCESSORS_ONLN) + + echo -e ${SYS_VERSION} + echo -e Bit:${SYS_BIT} Mem:${MEM_TOTAL}M Core:${CPU_INFO} + echo -e ${SYS_INFO} +} + +#获取网卡信息 +GetNetCard() { + if [ "$1" == "1" ]; then + if [ -d "/sys/devices/virtual/net" ]; then + ls /sys/devices/virtual/net + fi + else + if [ -d "/sys/devices/virtual/net" ] && [ -d "/sys/class/net" ]; then + ls /sys/class/net/ | grep -v "$(ls /sys/devices/virtual/net/)" + fi + fi +} + + +GetTimeZone(){ + timedatectl | grep "Time zone" | awk '{printf $3}' +} + +#查看网卡状态 +#param 网卡名称 +CatNetCardState() { + if [ -e "/sys/class/net/$1/operstate" ]; then + cat /sys/class/net/$1/operstate + fi +} + +#获取docker根目录 +GetDockerRootDir() { + if hash docker 2>/dev/null; then + docker info | grep 'Docker Root Dir' | awk -F ':' '{print $2}' + else + echo "" + fi +} + +#删除安装应用文件夹 +#param 需要删除的文件夹路径 +DelAppConfigDir() { + if [ -d $1 ]; then + rm -fr $1 + fi +} + +#zerotier本机已加入的网络 +#result start,end,sectors +GetLocalJoinNetworks() { + zerotier-cli listnetworks -j +} + +#移除挂载点,删除已挂在的文件夹 +UMountPorintAndRemoveDir() { + DEVICE=$1 + MOUNT_POINT=$(mount | grep ${DEVICE} | awk '{ print $3 }') + if [[ -z ${MOUNT_POINT} ]]; then + ${log} "Warning: ${DEVICE} is not mounted" + else + umount -lf ${DEVICE} + /bin/rmdir "${MOUNT_POINT}" + fi +} + +#格式化fat32磁盘 +#param 需要格式化的目录 /dev/sda1 +#param 格式 +FormatDisk() { + if [ "$2" == "fat32" ]; then + mkfs.vfat -F 32 $1 + elif [ "$2" == "ntfs" ]; then + mkfs.ntfs $1 + elif [ "$2" == "ext4" ]; then + mkfs.ext4 -m 1 -F $1 + elif [ "$2" == "exfat" ]; then + mkfs.exfat $1 + else + mkfs.ext4 -m 1 -F $1 + fi +} + +#删除分区 +#param 路径 /dev/sdb +#param 删除分区的区号 +DelPartition() { + fdisk $1 </dev/null 2>&1 + ;; + exfat) + mount -t exfat ${DEVICE} ${MOUNT_POINT} >/dev/null 2>&1 + ;; + ntfs) + ntfs-3g ${DEVICE} ${MOUNT_POINT} + ;; + iso9660) + mount -t iso9660 ${DEVICE} ${MOUNT_POINT} + ;; + *) + /bin/rmdir "${MOUNT_POINT}" + exit 0 + ;; + esac +} + +# $1=sda1 +do_umount() { + log="logger -t usb-mount.sh -s " + DEVBASE=$1 + DEVICE="${DEVBASE}" + MOUNT_POINT=$(mount | grep ${DEVICE} | awk '{ print $3 }') + + if [[ -z ${MOUNT_POINT} ]]; then + ${log} "Warning: ${DEVICE} is not mounted" + else + /bin/kill -9 $(lsof ${MOUNT_POINT}) + umount -l ${DEVICE} + ${log} "Unmounted ${DEVICE} from ${MOUNT_POINT}" + if [ "`ls -A ${MOUNT_POINT}`" = "" ]; then + /bin/rm -fr "${MOUNT_POINT}" + fi + + sed -i.bak "\@${MOUNT_POINT}@d" /var/log/usb-mount.track + fi + +} +# $1=/mnt/volume1/data.img +# $2=100G +PackageDocker() { + image=$1 + docker="/mnt/casa_docker" + #判断目录docker存在不存在则创建,存在检查是否为空 + + if [ ! -d "$docker" ]; then + mkdir ${docker} + fi + + if [ "$(ls -A $docker)" = "" ]; then + echo "$docker count is 0" + else + mkdir ${docker}_bak + mv -r ${docker} ${docker}_bak + fi + + daemon="/etc/docker/daemon.json" + #1创建img文件在挂载的目录 + fallocate -l $2 $image + #2初始化img文件 + mkfs -t ext4 $image + #3挂载img文件 + sudo mount -o loop $image $docker + #4给移动/var/lib/docker数据到img挂载的目录 + systemctl stop docker.socket + systemctl stop docker + cp -r /var/lib/docker/* ${docker}/ + #5在/etc/docker写入daemon.json(需要检查) + if [ -d "$daemon" ]; then + mv -r $daemon ${daemon}.bak + fi + echo "{\"data-root\": \"$docker\"}" >$daemon + #删除老数据腾出空间 + #rm -fr /var/lib/docker + systemctl start docker.socket + systemctl start docker +} + +DockerImgMove() { + image=$1 + systemctl stop docker.socket + systemctl stop docker + sudo umount -f $image +} + +GetDockerDataRoot() { + docker info | grep "Docker Root Dir:" +} + +SetLink() { + ln -s /mnt/casa_sda1/AppData /DATA/AppData + #删除所有软链 + find /DATA -type l -delete +} + +#压缩文件夹 + +TarFolder() { + #压缩 + tar -zcvf data.tar.gz -C/DATA/ AppDataBak/ + + #解压 + tar zxvf data.tar.gz + + #查看某文件夹下的所有包括子文件夹文件 + ls /DATA/Media -lR | grep "^-" | wc -l + # ls -lR|grep "^d"| wc -l 查看某个文件夹下文件夹的个数,包括子文件夹下的文件夹个数。 + + #查看固定文件夹大小 + du -sh /DATA +} + +USB_Start_Auto() { + ((EUID)) && sudo_cmd="sudo" + $sudo_cmd systemctl enable devmon@devmon + $sudo_cmd systemctl start devmon@devmon +} + +USB_Stop_Auto() { + ((EUID)) && sudo_cmd="sudo" + $sudo_cmd systemctl stop devmon@devmon + $sudo_cmd systemctl disable devmon@devmon + $sudo_cmd udevil clean +} + +GetDeviceTree(){ + cat /proc/device-tree/model +} + +# restart samba service +RestartSMBD(){ + $sudo_cmd systemctl restart smbd +} + +# edit user password $1:username +EditSmabaUserPassword(){ + $sudo_cmd smbpasswd $1 +} + +AddSmabaUser(){ + $sudo_cmd useradd $1 + $sudo_cmd smbpasswd -a $1 <>"/var/log/usb-mount.track" + # fi + # + # ${log} "Mounted ${DEVICE} at ${MOUNT_POINT}" + + case ${ID_FS_TYPE} in + vfat) + mount -t vfat -o rw,relatime,users,gid=100,umask=000,shortname=mixed,utf8=1,flush ${DEVICE} ${MOUNT_POINT} + ;; + ext[2-4]) + mount -o noatime ${DEVICE} ${MOUNT_POINT} >/dev/null 2>&1 + ;; + exfat) + mount -t exfat ${DEVICE} ${MOUNT_POINT} >/dev/null 2>&1 + ;; + ntfs) + ntfs-3g ${DEVICE} ${MOUNT_POINT} + ;; + iso9660) + mount -t iso9660 ${DEVICE} ${MOUNT_POINT} + ;; + *) + /bin/rmdir "${MOUNT_POINT}" + exit 0 + ;; + esac +} + +do_umount() { + + if [[ -z ${MOUNT_POINT} ]]; then + ${log} "Warning: ${DEVICE} is not mounted" + else + #/bin/kill -9 $(lsof ${MOUNT_POINT}) + umount -l ${DEVICE} + ${log} "Unmounted ${DEVICE} from ${MOUNT_POINT}" + if [ "`ls -A ${MOUNT_POINT}`" = "" ]; then + /bin/rm -fr "${MOUNT_POINT}" + fi + sed -i.bak "\@${MOUNT_POINT}@d" /var/log/usb-mount.track + fi + +} + +case "${ACTION}" in +add) + do_mount + ;; +remove) + do_umount + ;; +*) + exit 1 + ;; +esac diff --git a/build/sysroot/usr/share/casaos/shell/usb-mount@.service b/build/sysroot/usr/share/casaos/shell/usb-mount@.service new file mode 100644 index 000000000..bec2f859d --- /dev/null +++ b/build/sysroot/usr/share/casaos/shell/usb-mount@.service @@ -0,0 +1,8 @@ +# copy to /etc/systemd/system path +[Unit] +Description=Mount USB Drive on %i +[Service] +Type=oneshot +RemainAfterExit=true +ExecStart=/casaOS/server/shell/usb-mount.sh add %i +ExecStop=/casaOS/server/shell/usb-mount.sh remove %i