OpenGrok-Git-Python新版本離線安裝與簡單配置
0x00 前言
網上有很多現成的OpenGrok安裝與配置的文章,但大多都比較老舊,截止行文前,我使用的版本是:
opengrok-1.1-rc75tomcat-8.5.35git-2.19.2Python3.7.1(Optional)
另外,我的Ubuntu在內網,基本上是處於離線狀態,有內網的apt-get倉庫可以訪問,但是不能使用ppa,可想而知,大部分的軟體包都沒有最新版本。只能通過原始碼包編譯,如果出現依賴缺失,還得找逐一對應的依賴包,然後可能又會有新的依賴缺失,不勝其煩,我搗鼓了好幾天才完全弄好。
0x01 Tomcat
首先是最簡單的Tomcat,解壓就可以
ofollow,noindex">https://tomcat.apache.org/download-80.cgi
很可能需要更新java到1.8請到Oracle官網下載原始碼編譯,依賴比較少,過程忽略
https://www.oracle.com/technetwork/java/javase/downloads/index.html
安裝java1.8的原因還由於Opengrok需要用到java1.8以上的版本,否則部署到Tomcat後會發生各種找不到類
的錯誤,直觀體驗就是訪問網頁顯示404.
0x02 OpenGrok
建議還是先看看官方的指導頁
https://github.com/oracle/opengrok/wiki/How-to-setup-OpenGrok
Requirements
You need the following:
- JDK 1.8 or higher (剛剛已經安裝好的java8)
- OpenGrok '''binaries''' fromhttps://github.com/OpenGrok/OpenGrok/releases (.tar.gz file with binaries, not the source code tarball !)(最新版本的OpenGrok發行版)
- https://github.com/universal-ctags for analysis (avoid Exuberant ctags, they are not maintained anymore)(需要安裝universal-ctags)
- A servlet container likeGlassFish orTomcat 8.0 or later also running with Java at least 1.8(剛剛安裝了的Tomcat)
- GIT version 2.6 or higher for GIT repositories (see PR#1314 for more info)(後面會介紹,git版本過低會出現xref找不到的錯誤)
Ctags
Ctags也是大名鼎鼎的程式碼標記工具了,到它的GitHub主頁下載最新的原始碼
https://github.com/universal-ctags/ctags
How to build and install
To build with Autotools, seedocs/autotools.rst
for more information.
(To build on GNU/Linux, Autotools is your choice.)
$ ./autogen.sh # 需要安裝autogen工具,apt-get或者自行解決 $ ./configure --prefix=/where/you/want # 預設 /usr/local $ make $ make install # 如果需要安裝在系統分割槽,需要管理員許可權
Git
同樣先下載原始碼包https://github.com/git/git/releases
閱讀https://github.com/git/git/blob/master/INSTALL 安裝說明
$ make configure ;# as yourself $ ./configure --prefix=/usr ;# as yourself $ make all doc ;# as yourself # make install install-doc install-html;# as root
可能會提示缺失asciidoc
命令,apt-get或者找對應的deb包安裝即可。
小技巧:
apt-get缺失的包可以嘗試在https://launchpad.net/ubuntu 找
部署OpenGrok,Index
按照官方步驟,這時應該安裝通過Python3生成OpenGrok tool的命令方便後續的index操作的,但不是必須的,而且我安裝Python3的時候也踩到無數個坑,因此建議直接跳到部署。
https://github.com/oracle/opengrok/wiki/How-to-setup-OpenGrok#step2---deploy-the-web-application- 下載最新的Release包:https://github.com/oracle/opengrok/releases 並解壓
- 複製source.war到Tomcat的webapp目錄
- 執行Tomcat/bin/startup.sh
- 訪問http://localhost:8080/source
這時候已經可以看到OpenGrok的介面了,但會提示沒有找到configuration.xml檔案,接下來就是index工程程式碼。
Index
下面的命令中需要代入你各自安裝的目錄
[opengrok_解壓目錄] 例如:~/opengrok-1.1-rc75
[SOURCE_ROOT] 需要Index的原始碼根目錄
[WORK_ROOT] OpenGrok的工作目錄,生成配置檔案和index資料,使用者自由選擇,主要要有足夠的空間,生成的資料量跟原始碼相當
java -Djava.util.logging.config.file=[opengrok_解壓目錄]/doc/logging.properties \ -jar [opengrok_解壓目錄]/lib/opengrok.jar \ -c /usr/local/bin/ctags \ --depth 10 \ -s [SOURCE_ROOT] -d [WORK_ROOT]/data -P -S -G \ -W [WORK_ROOT]/etc/configuration.xml -U http://localhost:8080/source 2>&1
等待命令執行完(Android工程大約需要20分鐘),我們得到[WORK_ROOT]/etc/configuration.xml
檔案。
Deploy
編輯Tomcat/webapp/source/WEB-INF/web.xml
檔案,修改param-value
為剛剛生成的配置檔案
<context-param> <description>Full path to the configuration file where OpenGrok can read its configuration</description> <param-name>CONFIGURATION</param-name> <param-value>[WORK_ROOT]/etc/configuration.xml</param-value> </context-param>
正常來說,等待一下,訪問http://localhost:8080/source 就可以看到Index過的程式碼工程了。
保險起見,可以先清理一下Tomcat:
Tomcat/bin/shutdown.sh rm -rf Tomcat/work/* rm -rf Tomcat/log/* Tomcat/bin/startup.sh
0x03 附錄 安裝Python3.7.1 以及 OpenGrok tool
前面說過,可以通過Python3生成方便管理OpenGrok的命令,例如:opengrok-index
,opengrok-reindex-project
而安裝Python3又是一個大坑,因此單獨敘述。
OpenSSL 1.0.2
Python3 依賴最低 openssl-1.0.2 版本,需要手動編譯安裝:
- 下載解壓原始碼包:https://github.com/openssl/openssl/releases/tag/OpenSSL_1_0_2q
- 閱讀說明,得知步驟,下面是建議步驟https://github.com/openssl/openssl/blob/master/INSTALL
$ ./config $ make $ make test $ make install # as root
-
預設安裝在
/usr/local/ssl
,最好備份老版本的openssl,並做軟連線和配置動態連結庫
sudo mv /usr/bin/openssl /usr/bin/openssl.o sudo mv /usr/include/openssl /usr/include/openssl.o sudo ln -s /usr/local/ssl/bin/openssl /usr/bin sudo ln -s /usr/local/ssl/include/openssl /usr/include/openssl sudo echo "/usr/local/ssl/lib" >> /etc/ld.so.conf.d/openssl.conf ldconfig -v
-
執行
openssl version
輸出1.0.2即成功
安裝 Python3.7.1
./configure --with-openssl=/usr/local/ssl make sudo make install
如果出現某些模組安裝失敗,則找對應的deb包安裝上即可。
安裝 OpenGrok tool
一句python3 -m pip install opengrok-tools.tar.gz
就搞定了,那是在有網路的情況下,pip工具會自動下載對應作業系統,對應版本,對應依賴的python模組,在這裡就需要離線下載pip模組。
pip離線下載模組
網上很多文章對這個也是說的不清楚,其實原理很簡單,每個pip模組裡面都有一個requires.txt描述它的依賴,可以通過pip download命令將依賴包下載下來,然後放到離線機器上作為依賴的目錄安裝。 假設我們在Window上負責下載離線包(其實會涉及到平臺問題,
Window上
[opengrok_解壓目錄]/tools/opengrok-tools.tar.gz
python -m pip download -r E:\requires.txt -d E:\opengrok_tools_tmp
-
依賴包就會下載到
E:\opengrok_tools_tmp
,這時要留意,有些包是針對window使用的,需要到pip的網站上下載,例如:
PyYAML-3.13-cp37-cp37m-win_amd64.whl
需要到https://pypi.org/project/pip/ 搜尋 PyYAML 下載https://pypi.org/project/PyYAML/#files
PyYAML-3.13.tar.gz (270.6 kB)Copy SHA256 hash SHA256
- 把 E:\opengrok_tools_tmp 打包 放到Linux上 ~/opengrok_tools_tmp
Linux上
- 執行
python3 -m pip install --no-index --find-links=~/opengrok_tools_tmp [opengrok_解壓目錄]/tools/opengrok-tools.tar.gz
正常來說,就成功了,可能還會提示缺少模組,可以繼續從Window下載對應的模組,放到Linux的tmp目錄,重複第5步,例如,提示缺少pytest-runner:
python -m pip download -d E:\opengrok_tools_tmp --only-binary=:none: pytest-runner
0x04 結語
離線配置Linux真的好累。中間還發生過為了安裝新版本軟體,更新了錯的dpkg(用了debian發行版的deb安裝到Ubuntu上),導致正常的apt-get命令都出錯。最後不得不找回舊版本的deb包,一個個安裝回去,引以為戒
2018/11/2215:139,642,757 apache-tomcat-8.5.35.tar.gz 2018/11/2218:46181,872 ca-certificates_20161130+nmu1+deb9u1_all.deb 2018/11/2215:202,632,021 ctags-master.zip 2018/11/2219:30159,498 debconf_1.5.61_all.deb 2018/11/2220:051,595,256 dpkg-dev_1.18.25_all.deb 2018/11/2220:082,115,334 dpkg_1.18.25_amd64.deb 2018/11/2219:34779,468 libc-bin_2.24-11+deb9u3_amd64.deb 2018/11/2219:34819,858 libc-l10n_2.24-11+deb9u3_all.deb 2018/11/2219:322,693,080 libc6_2.24-11+deb9u3_amd64.deb 2018/11/2220:071,287,170 libdpkg-perl_1.18.25_all.deb 2018/11/2219:09161,174 libffi-dev_3.2.1-6_amd64.deb 2018/11/2219:0920,388 libffi6_3.2.1-6_amd64.deb 2018/11/2220:11234,010 liblzma5_5.2.2-1.2+b1_amd64.deb 2018/11/2220:13101,376 libselinux1_2.6-3+b3_amd64.deb 2018/11/2219:181,574,992 libssl-dev_1.1.0f-3+deb9u2_amd64.deb 2018/11/2219:171,343,734 libssl1.1_1.1.0f-3+deb9u2_amd64.deb 2018/11/2219:343,287,368 locales_2.24-11+deb9u3_all.deb 2018/11/2215:0845,676,887 opengrok-1.1-rc75.tar.gz 2018/11/2713:105,345,604 openssl-1.0.2q.tar.gz 2018/11/2219:18724,790 openssl_1.1.0f-3+deb9u2_amd64.deb 2018/11/2219:301,344,606 perl-base_5.24.1-3+deb9u4_amd64.deb 2018/11/2219:051,259,370 pip-18.1.tar.gz 2018/11/2215:5522,802,018 Python-3.7.1.tgz 2018/11/2218:461,405,972 python-pip-whl_9.0.1-2_all.deb 2018/11/2219:02178,870 python-pip_9.0.1-2_all.deb 2018/11/2219:06297,136 python-setuptools_33.1.1-1_all.deb 2018/11/2218:46142,204 python3-pip_9.0.1-2_all.deb 2018/11/2220:09759,354 tar_1.29b-1.1_amd64.deb