bash脚本问题
Tofloor
poster avatar
Hello
deepin
2020-07-31 03:47
Author
我这边有个bash脚本,如果在root下运行会重置系统lib目录导致系统损坏
但我现在必须使用这个脚本,并且分发软件
但万一那个不长眼睛的root下执行了就全部木大了。

所以来询问万能的坛友,如何检测当前执行脚本的用户是否是root?
检测到了如何退出程序?


Reply Favorite View the author
All Replies
avatar
Hello
deepin
2020-07-31 03:47
#1
帮帮忙,求你搞
Reply View the author
avatar
Hello
deepin
2020-07-31 03:49
#2
顶顶顶,大家帮帮忙
Reply View the author
avatar
SamLukeYes
deepin
2020-07-31 04:02
#3
xdroid 的 install.sh 有这样的机制,你可以借鉴一下
Reply View the author
avatar
SamLukeYes
deepin
2020-07-31 04:04
#4
  1. if [ "$(id -u)" -eq 0 ] ; then
  2.         echo "ERROR: Don't run the installer.sh as root or via sudo."
  3.         echo "       Simply invoke it with your regular user."
  4.         exit 1
  5. fi
Copy the Code
Reply View the author
avatar
flydrz
deepin
2020-07-31 04:12
#5
https://baidu.apphb.com/?q=bash+root%E6%A3%80%E6%B5%8B
Reply View the author
avatar
Hello
deepin
2020-07-31 04:39
#6
https://bbs.deepin.org/post/198068
https://baidu.apphb.com/?q=bash+root%E6%A3%80%E6%B5%8B

谢了兄弟

Reply View the author
avatar
SamLukeYes
deepin
2020-07-31 05:25
#7

你连 install.sh 的文案都不改一下的吗
Reply View the author