因為常重灌系統的關係,為節省守在螢幕前的時間,索性將常用的安裝與更新指令寫成一個指令稿,進入系統後直接呼叫bash執行。
若全部都只是sudo apt install...那倒好辦,不過為了安裝最新的QGIS,必須去官網複製軟體庫的相關資訊,每次都要動滑鼠覺得很麻煩。利用待業時間寫出了這樣一個指令:
為方便對照起見,我就沿著官網的說明把我的指令整個介紹一遍(這裡是用Debian,但Ubuntu狀況也差不多)
0寫在前面
#這邊主要應該是要處理軟體庫公鑰認證的問題,基本上就照官方說明複製指令碼即可
sudo apt install gnupg software-properties-common;
sudo mkdir -m755 -p /etc/apt/keyrings; # not needed since apt version 2.4.0 like Debian 12 and Ubuntu 22 or newer
sudo wget -O /etc/apt/keyrings/qgis-archive-keyring.gpg https://download.qgis.org/downloads/qgis-archive-keyring.gpg;
1. 前處理(產生指令稿正本)
#但是遇到要copy and paste的時候,就要用echo指令的小技巧。(原本以為需要弄換行符號,發現其實不用)
echo "Types: deb deb-src
URIs: https://qgis.org/debian
Suites:$(lsb_release -cs) #這裡以變數的方式,讓系統自己去抓目前的環境變數,節省Ubuntu與Debian切來切去的困擾
Architectures: amd64
Components: main
Signed-By: /etc/apt/keyrings/qgis-archive-keyring.gpg" > qgis.sources;
#因為在受限制的資料夾要開sudo寫進去很麻煩,乾脆把指令稿寫好放在家目錄。然後把指令稿用cp指令複製到指定的地方。
2. 複製指令稿到指定資料夾:
sudo cp qgis.sources /etc/apt/sources.list.d/;
#這裡必須使用絕對路徑
3. 更新或安裝主程式:
sudo apt update;
sudo apt install qgis qgis-plugin-grass
至少在公鑰(第0段)沒變更的前提下,不管是重灌或大量部署於電腦教室,這指令稿可以減少許多手動的安裝步驟和時間。
同場加映:
因為最近常在Debian和Ubuntu之間切換重灌,所以加了if/elif的選擇結構,避免切換scipt的困擾。以下是(永遠不會完成的)示範:
sudo apt update;
sudo apt upgrade -y;
sudo apt install gimp krita inkscape kdenlive vlc gcin gnome-tweak-tool kazam okular kate nextcloud-desktop spyder nextcloud-desktop vnstat audacity spyder -y;
#如果你用的是Debian 11(codename="bullseye")
if [ "$(lsb_release -cs)" = "bullseye" ]; then
sudo snap install youtube-dl chromium;
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key '95C0FAF38DB3CCAD0C080A7BDC78B2DDEABC47B7';
sudo add-apt-repository "deb http://cloud.r-project.org/bin/linux/debian bullseye-cran40/";
sudo apt install r-base;
sudo apt install libatlas3-base libopenblas-base;
sudo apt install r-cran-boot r-cran-class r-cran-cluster r-cran-codetools r-cran-foreign r-cran-kernsmooth r-cran-lattice r-cran-mass r-cran-matrix r-cran-mgcv r-cran-nlme r-cran-nnet r-cran-rpart r-cran-spatial r-cran-survival
#如果用的是Ubuntu 20.04LTS(codename="focal")
elif [ "$(lsb_release -cs)" = "focal" ]; then
sudo wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | sudo tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc;
sudo add-apt-repository "deb https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/";
sudo add-apt-repository ppa:c2d4u.team/c2d4u4.0+;
sudo apt install r-cran-tidyverse r-cran-rstan -y;
fi;
#選擇結構結束
# R common needs(任何系統都要的東西)
sudo apt install r-cran-rstan ;sudo apt install r-cran-tidyverse cmake libharfbuzz-dev libfribidi-dev libfreetype-dev libpng-dev libtiff5-dev libjpeg-dev libssl-dev -y;
sudo apt install arfbuzz freetype2 fribidi;
#QGIS
sudo apt install gnupg software-properties-common;
sudo mkdir -m755 -p /etc/apt/keyrings;
sudo wget -O /etc/apt/keyrings/qgis-archive-keyring.gpg https://download.qgis.org/downloads/qgis-archive-keyring.gpg;
echo "Types: deb deb-src
URIs: https://qgis.org/debian
Suites:$(lsb_release -cs)
Architectures: amd64
Components: main
Signed-By: /etc/apt/keyrings/qgis-archive-keyring.gpg" > qgis.sources;
sudo cp qgis.sources /etc/apt/sources.list.d/;
sudo apt update;
sudo apt install qgis -y;