[Linux] 建立 .deb 檔案時,修改安裝目錄的權限

[Linux] 建立 .deb 檔案時,修改安裝目錄的權限

今天在處理一個 .deb 檔案安裝好後,安裝目錄權限是 744 (drwxr–r–) 的問題。

這會讓其他使用者都可以進來我們的目錄,

因此會想要把它預設設成 700 (drwx——)。

 

比較好的方法是在建立 deb 檔案的規則檔裡,就直接把權限設好。

一開始我以為先用 chmod 把目錄權限設好,

之後 debuild 包起來的目錄權限就會是對的,

卻發現用 dpkg -c test.deb 檢查內容時,權限依然是 644…

 

這個 644 權限是 dh_fixperms 這個動作做的,

想修改它的話,爬文了一下,

大家似乎是建議使用 override_dh_fixperms 這個 target,

加在 .deb 的 rules 規則檔 (也是一種 Makefile) 裡,例如:

binary-arch: build 
    dh_testdir
    dh_testroot
    dh_install --autodest debian/tmp/*
    dh_installchangelogs
    dh_compress
    dh_installdeb
    dh_gencontrol
    dh_fixperms
    dh_md5sums
    dh_builddeb

override_dh_fixperms:
    dh_fixperms
    chmod 0700 debian/test/opt/mytestproj

 

只是不知道為什麼,我在跑 debuild 的時候,

它看起來跑了 dh_fixperms 指令,但沒有跑到 override_dh_fixperms 的部分…

(對 debuild 真的太不熟…)

 

不過因為 rules 就是一個 Makefile,

所以另一個解法就是直接把 chmod 指令加在 dh_fixperms 後面:

binary-arch: build 
    dh_testdir
    dh_testroot
    dh_install --autodest debian/tmp/*
    dh_installchangelogs
    dh_compress
    dh_fixperms
    chmod 0700 debian/test/opt/mytestproj
    dh_installdeb
    dh_gencontrol
    dh_md5sums
    dh_builddeb

 

這樣子在建立好的 .deb 檔案裡,/opt/mytestproj 目錄的權限就是 700 了~

 

參考資料:

(本頁面已被瀏覽過 502 次)

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料