如何在Deepin 20系统下配置webdav免密码登录和开机自启动?

嚯嚯 发表于2020-11-21 00:29
浏览次数:
在手机上阅读
此文章约为974字,阅读需要3 分钟

本文介绍在deepin 20系统下配置webdav免密码登录和开机自启动,可实现在deepin V20系统下开机联网自动挂载webdav,不会开机卡死。

一、安装webdav支持

sudo apt-get install davfs2 -y

二、配置webdav免密码登录

sudo echo "use_locks 0"  >>/etc/davfs2/davfs2.conf
sudo echo "webdav的地址 用户名 密码" >>/etc/davfs2/secrets
sudo chmod 0600 /etc/davfs2/secrets

三、配置webdav开机自启动

1、webdav自启项

touch  ~/.config/autostart/mount_auto_boot.desktop
dedit ~/.config/autostart/mount_auto_boot.desktop

内容如下:

[Desktop Entry]
Type=ApplicATIon
Exec="/opt/mount_auto_boot/mount_auto_boot.sh"
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name[en_IN]=mount-auto
Name=mount-auto
Comment[en_IN]=mount-auto
Comment=mount-auto

2、webdav自启脚本,这里需要修改实际webdav的地址跟实际挂载目录,如下自行修改

sudo mkdir /opt/mount_auto_boot/
sudo touch /opt/mount_auto_boot/mount_auto_boot.sh
dedit /opt/mount_auto_boot/mount_auto_boot.sh

内容如下:

#!/bin/bash
#moount webdav
#随便设置两个可以ping通的ip或者地址,联网检测,IP2为webdav地址,自行修改
IP1="180.76.76.76"
IP2="www.*.com"
mount_count=1
#设置webdav的地址:
webdav='https://www.*.com'
#webdav='https://www.*.com:5006'
#设置webdav挂载目的地址:
mnt_webdav='/mnt/webdav'
mkdir $mnt_webdav >/dev/null 2>&1
while true
do
df -Th|grep $webdav
if [ "$?" != "0" ]
then
echo "mount webdav..........fail" >>/opt/mount_auto_boot/mount_auto_boot.log
sleep 1
ping -s 1 -c 1 $IP1 #去PING第1个IP
if [ "$?" = "0" ]
then
echo "ping $IP1 Success" >>/opt/mount_auto_boot/mount_auto_boot.log
ping -s 1 -c 2 $IP2 #去PING第2个IP
if [ "$?" != "0" ]
then
echo "ping $IP2 ERROR" >>/opt/mount_auto_boot/mount_auto_boot.log
else
echo "ping $IP2 SUCCESS,mount webdav.........." >>/opt/mount_auto_boot/mount_auto_boot.log
sudo /usr/bin/mount -t davfs $webdav /mnt/webdav >>/opt/mount_auto_boot/mount_auto_boot.log 2>&1
sleep 3
df -Th|grep $webdav
if [ "$?" != "0" ]
then
echo "mount webdav..........fail" >>/opt/mount_auto_boot/mount_auto_boot.log
continue
else
echo "mount_count:$mount_count"
echo "mount webdav..........done" >>/opt/mount_auto_boot/mount_auto_boot.log
df -Th|grep $webdav >>/opt/mount_auto_boot/mount_auto_boot.log
echo "mount_count:$mount_count" >>/opt/mount_auto_boot/mount_auto_boot.log
break
fi
fi
else
echo "ping IP1 ERROR"
mount_count=$[$mount_count+1]
sleep 5 #设置多长时间去PING一次
continue
fi
else
echo "mount_count:$mount_count"
echo "mount webdav..........done" >>/opt/mount_auto_boot/mount_auto_boot.log
df -Th|grep $webdav >>/opt/mount_auto_boot/mount_auto_boot.log
echo "mount_count:$mount_count" >>/opt/mount_auto_boot/mount_auto_boot.log
break
fi
done
exit 0

注:把该内容保存起来,重新启动电脑,再登录连接网络,它会自动挂载好的。

418 个用户觉得很有用

uc电脑园提供的技术方案或与您产品的实际情况有所差异,您需在完整阅读方案并知晓其提示风险的情况下谨慎操作,避免造成任何损失。

如此好文,分享给朋友

图片来源:网络

发表评论
验证码:
评论列表
共0条