Linux下自動化測試環境搭建-一鍵安裝shell腳本


#!/bin/bash

# 獲取系統sudo權限
echo "1" | sudo -S su

# 方法:檢查apt安裝的包是否成功
function apt_check(){
    dpkg -l | grep -i $1

    if [ $? -eq 0 ];then
        echo "======$1 已安裝!======="
    else
        echo "======$1 安裝失敗!======="
    fi
}

# 方法:檢查pip安裝的包是否成功
function pip_check(){
    pip3 list | grep -i $1

    if [ $? -eq 0 ];then
        echo "======$1 已安裝!======="
    else
        echo "======$1 安裝失敗!======="
    fi
}

# 寫日志
echo "# " | sudo tee -a /home/$USER/Documents/test_env_report.log
echo "# " | sudo tee -a /home/$USER/Documents/test_env_report.log
echo "# " | sudo tee -a /home/$USER/Documents/test_env_report.log
echo "# ==================查詢測試環境是否安裝成功======================= #" | sudo tee -a /home/$USER/Documents/test_env_report.log

echo $(date) | sudo tee -a /home/$USER/Documents/test_env_report.log

echo "# ============================================================= #" | sudo tee -a /home/$USER/Documents/test_env_report.log

#===================================更新三方庫的源==================================
sudo mv /etc/apt/sources.list /etc/apt/sources.list.bak
sudo cp ./sources.list.other /etc/apt/sources.list && echo "三方源復制成功" | sudo tee -a /home/$USER/Documents/test_env_report.log
sudo apt-get update && echo "三方源更新成功" | sudo tee -a /home/$USER/Documents/test_env_report.log


#===================================測試環境安裝==================================

# pip3
sudo apt-get -y install python3-pip
# git
sudo apt-get -y install git
# 安裝pyautogui
sudo pip3 install pillow
sudo pip3 install python3-xlib
sudo apt-get -y install scrot
sudo apt-get -y install python3-tk
sudo apt-get -y install python3-dev
sudo pip3 install pyautogui -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
# 安裝dogtail
sudo apt-get -y install python3-pyatspi
sudo pip3 install dogtail -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
# pip三方庫
sudo pip3 install ddt
sudo pip3 install BeautifulReport
#sudo pip3 install unittestreport
sudo pip3 install unittest-xml-reporting
sudo pip3 install xlrd
sudo pip3 install PyYAML
sudo pip3 install pyscreenshot
sudo pip3 install pytesseract
# apt三方庫
sudo apt-get -y install tesseract-ocr
sudo apt-get -y install tesseract-ocr-eng
sudo apt-get -y install tesseract-ocr-chi-sim
# opencv
sudo apt-get -y install python3-opencv || sudo apt install -f && sudo apt-get -y install python3-opencv
sudo apt-get -y install python3-numpy

# =======================檢查測試是否安裝成功==============================

for i in python3-pip scrot python3-tk python3-dev python3-pyatspi tesseract-ocr
do
    apt_check $i | sudo tee -a /home/$USER/Documents/test_env_report.log
done

for i in pillow python3-xlib pyautogui dogtail ddt BeautifulReport xlrd PyYAML pyscreenshot python3-opencv
do
    pip_check $i | sudo tee -a /home/$USER/Documents/test_env_report.log
done



#===================================應用版本==================================

echo "# " | sudo tee -a /home/$USER/Documents/app_version.log
echo "# " | sudo tee -a /home/$USER/Documents/app_version.log
echo "# " | sudo tee -a /home/$USER/Documents/app_version.log
echo "# ==================查詢應用版本======================= #" | sudo tee -a /home/$USER/Documents/app_version.log

echo $(date) | sudo tee -a /home/$USER/Documents/app_version.log

echo "# =================================================== #" | sudo tee -a /home/$USER/Documents/app_version.log

#=======================更新多媒體應用的源============================
sudo cp ./sources.list.media /etc/apt/sources.list && echo "多媒體源復制成功" | sudo tee -a /home/$USER/Documents/app_version.log
sudo apt-get update && echo "多媒體源更新成功" | sudo tee -a /home/$USER/Documents/app_version.log

for i in libdde-file-manager dde-file-manager dde-desktop dde-disk-mount-plugin deepin-screen-recorder deepin-album deepin-music deepin-movie deepin-draw deepin-image-viewer
do
  apt_get $i
done

# ========================查詢應用版本=============================

for i in libdde-file-manager dde-file-manager dde-desktop dde-disk-mount-plugin deepin-screen-recorder deepin-album deepin-music deepin-movie deepin-draw deepin-image-viewer
do
  sudo apt policy $i | head -2 | sudo tee -a /home/$USER/Documents/app_version.log
done



# ========================從gitlab拉取代碼=============================


cd /home/$USER/Documents/

CONUSER=$( echo "dXQwMDEyMDMK" | base64 -d )
CONPASS=$( echo "MjAyMEBobXF6eQo" | base64 -d )

#cd /data/web/
git reset --hard
expect -c "spawn git clone https://gitlabcd.uniontech.com/autotest/cd-desktop-app.git; expect \"*Username*\" { send \"${CONUSER}\n\"; exp_continue } \"*Password*\" { send \"${CONPASS}\n\" }; interact"

# =======================================================================
# 復制靜態資源到圖片目錄
cd -
sudo cp -R ./ATimage /home/$USER/Pictures/ && echo "圖片資源復制成功" | sudo tee -a /home/$USER/Documents/app_version.log
cd /home/$USER/Pictures/
sudo chmod -R 777 ATimage
cd -
# 復制視頻資源
rm -rf /home/$USER/Videos/*.mp4
if [ -f /usr/share/dde-introduction/introduction.mp4 ];then
  cp /usr/share/dde-introduction/introduction.mp4 ~/Videos/introduction.mp4
  echo '視頻文件復制成功。'
  else
  echo '視頻文件不存在!'
fi
# 替換tree.py
sudo cp ./tree.py /usr/local/lib/python3.7/dist-packages/dogtail/tree.py
# 將畫板、看圖、影院發送到任務欄
dbus-send --session --print-reply --dest=com.deepin.dde.daemon.Dock /com/deepin/dde/daemon/Dock com.deepin.dde.daemon.Dock.RequestDock string:/usr/share/applications/deepin-draw.desktop int32:0
dbus-send --session --print-reply --dest=com.deepin.dde.daemon.Dock /com/deepin/dde/daemon/Dock com.deepin.dde.daemon.Dock.RequestDock string:/usr/share/applications/deepin-image-viewer.desktop int32:0
dbus-send --session --print-reply --dest=com.deepin.dde.daemon.Dock /com/deepin/dde/daemon/Dock com.deepin.dde.daemon.Dock.RequestDock string:/usr/share/applications/deepin-movie.desktop int32:0

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM