[Modify the use of sudo commands]

This commit is contained in:
plum-lihui 2019-07-19 15:39:51 +08:00
parent 2a36659e10
commit e06f24448f
1 changed files with 23 additions and 7 deletions

View File

@ -76,12 +76,17 @@ function is_using_systemd() {
fi fi
} }
csudo=""
if command -v sudo > /dev/null; then
csudo="sudo"
fi
# Stop the service if running # Stop the service if running
if pidof taosd &> /dev/null; then if pidof taosd &> /dev/null; then
if is_using_systemd; then if is_using_systemd; then
sudo systemctl stop taosd || : ${csudo} systemctl stop taosd || :
else else
sudo service taosd stop || : ${csudo} service taosd stop || :
fi fi
echo "Stop taosd service success!" echo "Stop taosd service success!"
sleep 1 sleep 1
@ -89,20 +94,28 @@ fi
# if taos.cfg already softlink, remove it # if taos.cfg already softlink, remove it
if [ -f %{cfg_install_dir}/taos.cfg ]; then if [ -f %{cfg_install_dir}/taos.cfg ]; then
sudo rm -f %{homepath}/cfg/taos.cfg || : ${csudo} rm -f %{homepath}/cfg/taos.cfg || :
fi fi
#Scripts executed after installation #Scripts executed after installation
%post %post
csudo=""
if command -v sudo > /dev/null; then
csudo="sudo"
fi
cd %{homepath}/script cd %{homepath}/script
sudo ./post.sh ${csudo} ./post.sh
# Scripts executed before uninstall # Scripts executed before uninstall
%preun %preun
csudo=""
if command -v sudo > /dev/null; then
csudo="sudo"
fi
# only remove package to call preun.sh, not but update(2) # only remove package to call preun.sh, not but update(2)
if [ $1 -eq 0 ];then if [ $1 -eq 0 ];then
cd %{homepath}/script cd %{homepath}/script
sudo ./preun.sh ${csudo} ./preun.sh
fi fi
# Scripts executed after uninstall # Scripts executed after uninstall
@ -110,14 +123,17 @@ fi
# clean build dir # clean build dir
%clean %clean
rm -rf %{buildroot} csudo=""
if command -v sudo > /dev/null; then
csudo="sudo"
fi
${csudo} rm -rf %{buildroot}
#Specify the files to be packaged #Specify the files to be packaged
%files %files
/* /*
#%doc #%doc
#Setting default permissions #Setting default permissions
%defattr (-,root,root,0755) %defattr (-,root,root,0755)
#%{prefix} #%{prefix}