mirror of
https://github.com/IceWhaleTech/CasaOS.git
synced 2025-06-16 05:55:33 +00:00
add shell script
This commit is contained in:
parent
727aca564b
commit
314dbdab57
1
.gitignore
vendored
1
.gitignore
vendored
@ -33,7 +33,6 @@ gen
|
|||||||
/conf/conf.json
|
/conf/conf.json
|
||||||
__debug_bin
|
__debug_bin
|
||||||
main
|
main
|
||||||
CasaOS
|
|
||||||
github.com
|
github.com
|
||||||
.all-contributorsrc
|
.all-contributorsrc
|
||||||
dist
|
dist
|
3
build/sysroot/usr/share/casaos/shell/assist.sh
Normal file
3
build/sysroot/usr/share/casaos/shell/assist.sh
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
|
105
build/sysroot/usr/share/casaos/shell/delete-old-service.sh
Normal file
105
build/sysroot/usr/share/casaos/shell/delete-old-service.sh
Normal file
@ -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
|
388
build/sysroot/usr/share/casaos/shell/helper.sh
Normal file
388
build/sysroot/usr/share/casaos/shell/helper.sh
Normal file
@ -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 <<EOF
|
||||||
|
d
|
||||||
|
$2
|
||||||
|
wq
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
#添加分区只有一个分区
|
||||||
|
#param 路径 /dev/sdb
|
||||||
|
#param 要挂载的目录
|
||||||
|
AddPartition() {
|
||||||
|
|
||||||
|
DelPartition $1
|
||||||
|
parted -s $1 mklabel gpt
|
||||||
|
|
||||||
|
parted -s $1 mkpart primary ext4 0 100%
|
||||||
|
P=`lsblk -r $1 | sort | grep part | head -n 1 | awk '{print $1}'`
|
||||||
|
mkfs.ext4 -m 1 -F /dev/${P}
|
||||||
|
|
||||||
|
partprobe $1
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#磁盘类型
|
||||||
|
GetDiskType() {
|
||||||
|
fdisk $1 -l | grep Disklabel | awk -F: '{print $2}'
|
||||||
|
}
|
||||||
|
|
||||||
|
#获磁盘的插入路径
|
||||||
|
#param 路径 /dev/sda
|
||||||
|
GetPlugInDisk() {
|
||||||
|
fdisk -l | grep 'Disk' | grep 'sd' | awk -F , '{print substr($1,11,3)}'
|
||||||
|
}
|
||||||
|
|
||||||
|
#获取磁盘状态
|
||||||
|
#param 磁盘路径
|
||||||
|
GetDiskHealthState() {
|
||||||
|
smartctl -H $1 | grep "SMART Health Status" | awk -F ":" '{print$2}'
|
||||||
|
}
|
||||||
|
|
||||||
|
#获取磁盘字节数量和扇区数量
|
||||||
|
#param 磁盘路径 /dev/sda
|
||||||
|
#result bytes
|
||||||
|
#result sectors
|
||||||
|
GetDiskSizeAndSectors() {
|
||||||
|
fdisk $1 -l | grep "$1:" | awk -F, 'BEGIN {OFS="\n"}{print $2,$3}' | awk '{print $1}'
|
||||||
|
}
|
||||||
|
|
||||||
|
#获取磁盘分区数据扇区
|
||||||
|
#param 磁盘路径 /dev/sda
|
||||||
|
#result start,end,sectors
|
||||||
|
GetPartitionSectors() {
|
||||||
|
fdisk $1 -l | grep "$1[1-9]" | awk 'BEGIN{OFS=","}{print $1,$2,$3,$4}'
|
||||||
|
}
|
||||||
|
|
||||||
|
#检查没有使用的挂载点删除文件夹
|
||||||
|
AutoRemoveUnuseDir() {
|
||||||
|
DIRECTORY="/DATA/"
|
||||||
|
dir=$(ls -l $DIRECTORY | grep "USB_Storage_sd[a-z][0-9]" | awk '/^d/ {print $NF}')
|
||||||
|
for i in $dir; do
|
||||||
|
|
||||||
|
path="$DIRECTORY$i"
|
||||||
|
mountStr=$(mountpoint $path)
|
||||||
|
notMountpoint="is not a mountpoint"
|
||||||
|
if [[ $mountStr =~ $notMountpoint ]]; then
|
||||||
|
if [ "$(ls -A $path)" = "" ]; then
|
||||||
|
rm -fr $path
|
||||||
|
else
|
||||||
|
echo "$path is not empty"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
#重载samba服务
|
||||||
|
ReloadSamba() {
|
||||||
|
/etc/init.d/smbd reload
|
||||||
|
}
|
||||||
|
|
||||||
|
# $1=sda1
|
||||||
|
# $2=volume{1}
|
||||||
|
do_mount() {
|
||||||
|
DEVBASE=$1
|
||||||
|
DEVICE="${DEVBASE}"
|
||||||
|
# See if this drive is already mounted, and if so where
|
||||||
|
MOUNT_POINT=$(lsblk -o name,mountpoint | grep ${DEVICE} | awk '{print $2}')
|
||||||
|
|
||||||
|
if [ -n "${MOUNT_POINT}" ]; then
|
||||||
|
${log} "Warning: ${DEVICE} is already mounted at ${MOUNT_POINT}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Get info for this drive: $ID_FS_LABEL and $ID_FS_TYPE
|
||||||
|
eval $(blkid -o udev ${DEVICE} | grep -i -e "ID_FS_LABEL" -e "ID_FS_TYPE")
|
||||||
|
|
||||||
|
LABEL=$2
|
||||||
|
if grep -q " ${LABEL} " /etc/mtab; then
|
||||||
|
# Already in use, make a unique one
|
||||||
|
LABEL+="-${DEVBASE}"
|
||||||
|
fi
|
||||||
|
DEV_LABEL="${LABEL}"
|
||||||
|
|
||||||
|
# Use the device name in case the drive doesn't have label
|
||||||
|
if [ -z ${DEV_LABEL} ]; then
|
||||||
|
DEV_LABEL="${DEVBASE}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
MOUNT_POINT="${DEV_LABEL}"
|
||||||
|
|
||||||
|
${log} "Mount point: ${MOUNT_POINT}"
|
||||||
|
|
||||||
|
mkdir -p ${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
|
||||||
|
}
|
||||||
|
|
||||||
|
# $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 <<EOF
|
||||||
|
$2
|
||||||
|
$2
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
# $1:username $2:host $3:share $4:port $5:mountpoint $6:password
|
||||||
|
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
|
||||||
|
}
|
||||||
|
UDEVILUmount(){
|
||||||
|
$sudo_cmd udevil umount -f $1
|
||||||
|
}
|
12
build/sysroot/usr/share/casaos/shell/update.sh
Normal file
12
build/sysroot/usr/share/casaos/shell/update.sh
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
###
|
||||||
|
# @Author: LinkLeong link@icewhale.com
|
||||||
|
# @Date: 2022-06-30 10:08:33
|
||||||
|
# @LastEditors: LinkLeong
|
||||||
|
# @LastEditTime: 2022-09-01 22:33:06
|
||||||
|
# @FilePath: /CasaOS/build/sysroot/usr/share/casaos/shell/update.sh
|
||||||
|
# @Description:
|
||||||
|
###
|
||||||
|
|
||||||
|
|
||||||
|
curl -fsSL https://raw.githubusercontent.com/LinkLeong/casaos-alpha/main/new.update.sh | bash
|
136
build/sysroot/usr/share/casaos/shell/usb-mount.sh
Normal file
136
build/sysroot/usr/share/casaos/shell/usb-mount.sh
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# copy to /casaOS/util/shell path
|
||||||
|
# chmod 755
|
||||||
|
|
||||||
|
log="logger -t usb-mount.sh -s "
|
||||||
|
|
||||||
|
ACTION=$1
|
||||||
|
|
||||||
|
DEVBASE=$2
|
||||||
|
|
||||||
|
DEVICE="/dev/${DEVBASE}"
|
||||||
|
|
||||||
|
# See if this drive is already mounted, and if so where
|
||||||
|
MOUNT_POINT=$(lsblk -l -p -o name,mountpoint | grep ${DEVICE} | awk '{print $2}')
|
||||||
|
|
||||||
|
do_mount() {
|
||||||
|
|
||||||
|
if [ -n "${MOUNT_POINT}" ]; then
|
||||||
|
${log} "Warning: ${DEVICE} is already mounted at ${MOUNT_POINT}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Get info for this drive: $ID_FS_LABEL and $ID_FS_TYPE
|
||||||
|
eval $(blkid -o udev ${DEVICE} | grep -i -e "ID_FS_LABEL" -e "ID_FS_TYPE")
|
||||||
|
|
||||||
|
#ID_FS_LABEL=新加卷
|
||||||
|
#ID_FS_LABEL_ENC=新加卷
|
||||||
|
#ID_FS_TYPE=ntfs
|
||||||
|
|
||||||
|
# Figure out a mount point to use
|
||||||
|
# LABEL=${ID_FS_LABEL}
|
||||||
|
LABEL=${DEVBASE}
|
||||||
|
if grep -q " /DATA/USB_Storage_${LABEL} " /etc/mtab; then
|
||||||
|
# Already in use, make a unique one
|
||||||
|
LABEL+="_${DEVBASE}"
|
||||||
|
fi
|
||||||
|
DEV_LABEL="${LABEL}"
|
||||||
|
|
||||||
|
# Use the device name in case the drive doesn't have label
|
||||||
|
if [ -z ${DEV_LABEL} ]; then
|
||||||
|
DEV_LABEL="${DEVBASE}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
MOUNT_POINT="/DATA/USB_Storage_${DEV_LABEL}"
|
||||||
|
|
||||||
|
${log} "Mount point: ${MOUNT_POINT}"
|
||||||
|
|
||||||
|
mkdir -p ${MOUNT_POINT}
|
||||||
|
|
||||||
|
|
||||||
|
# MOUNT_POINT="/DATA/USB_Storage1"
|
||||||
|
# arr=("/DATA/USB_Storage1" "/DATA/USB_Storage2" "/DATA/USB_Storage3" "/DATA/USB_Storage4" "/DATA/USB_Storage5" "/DATA/USB_Storage6" "/DATA/USB_Storage7" "/DATA/USB_Storage8" "/DATA/USB_Storage9" "/DATA/USB_Storage10" "/DATA/USB_Storage11" "/DATA/USB_Storage12")
|
||||||
|
# for folder in ${arr[@]}; do
|
||||||
|
# #如果文件夹不存在,创建文件夹
|
||||||
|
# if [ ! -d "$folder" ]; then
|
||||||
|
# mkdir -p ${folder}
|
||||||
|
# MOUNT_POINT=$folder
|
||||||
|
# break
|
||||||
|
# fi
|
||||||
|
# done
|
||||||
|
|
||||||
|
# ${log} "Mount point: ${MOUNT_POINT}"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# # Global mount options
|
||||||
|
# OPTS="rw,relatime"
|
||||||
|
#
|
||||||
|
# # File system type specific mount options
|
||||||
|
# if [[ ${ID_FS_TYPE} == "vfat" ]]; then
|
||||||
|
# OPTS+=",users,gid=100,umask=000,shortname=mixed,utf8=1,flush"
|
||||||
|
# fi
|
||||||
|
|
||||||
|
# if ! mount -o ${OPTS} ${DEVICE} ${MOUNT_POINT}; then
|
||||||
|
# ${log} "Error mounting ${DEVICE} (status = $?)"
|
||||||
|
# rmdir "${MOUNT_POINT}"
|
||||||
|
# exit 1
|
||||||
|
# else
|
||||||
|
# # Track the mounted drives
|
||||||
|
# echo "${MOUNT_POINT}:${DEVBASE}" | cat >>"/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
|
8
build/sysroot/usr/share/casaos/shell/usb-mount@.service
Normal file
8
build/sysroot/usr/share/casaos/shell/usb-mount@.service
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user