[操作疑難] 學習 SHELL SCRIPT, #!/bin/sh /etc/rc.common 這是做什麼的

原來想在 OPENWRT 安裝 OPENVPN 以及 OPENSSL, 結果FLASH不夠, 參考人家的做法, 開機時下載安裝到RAM DISK, 抄了一個 SHELL SCRIPT, 結果沒動作. 然後看了如何寫 SHELL SCRIPT, 參考這篇, http://linux.vbird.org/linux_bas ... -scripts.php#script,
做了一個 HELLO WORLD 試驗, 應該是OK的





那個沒有動作的SHELL SCRIPT, 抄自此處, 請前輩指點一二,
https://blog.zauberstuhl.de/openwrt_tplink_openvpn/
  1. #!/bin/sh /etc/rc.common

  2. START=99

  3. . /etc/profile

  4. install() {  
  5.   local OVPNPATH=/tmp/openvpn
  6.   local OSSLPATH=/tmp/libopenssl
  7.   [ ! -d ${OVPNPATH} ] && mkdir ${OVPNPATH}
  8.   [ ! -d ${OSSLPATH} ] && mkdir ${OSSLPATH}
  9.   command opkg update || exit 1
  10.   # install openvpn
  11.   cd ${OVPNPATH}
  12.   tar xzf $(opkg download openvpn-openssl |grep Downloaded |cut -d\  -f4 |sed '$s/.$//')
  13.   tar xzf data.tar.gz
  14.   # delete unnecessary things (save space)
  15.   rm -f pkg.tar.gz data.tar.gz control.tar.gz debian-binary getopenvpn.sh
  16.   # install libopenssl
  17.   cd ${OSSLPATH}
  18.   tar xzf $(opkg download libopenssl |grep Downloaded |cut -d\  -f4 |sed '$s/.$//')
  19.   tar xzf data.tar.gz
  20.   # delete unnecessary things (save space)
  21.   rm -f control.tar.gz debian-binary data.tar.gz
  22. }

  23. start () {  
  24.   # lvl 99 is not enough the script is too
  25.   sleep 10 # fast for the install step
  26.   install # setup openvpn and libssl
  27.   command openvpn --writepid /tmp/openvpn/ovpn.pid --daemon --config /etc/openvpn/client.conf
  28. }

  29. stop() {  
  30.   PIDOF=$(ps |egrep openvpn |egrep  -v grep |awk '{print $1}')
  31.   kill ${PIDOF}
  32. }
複製代碼
附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊

as long as i can understand, it is a script to "install", "start" and "stop" the openvpn. if you script's name is xyz.sh, you can try
sh xyz.sh install -> to install openvpn
sh xyz.sh start -> to start openvpn
sh xyz.sh stop -> to stop openvpn.

correct me if i am wrong.

TOP

  1. 沒有動作
複製代碼
即係咩 error ?
估計係
要將個 script 放响 /etc/init.d
响 openwrt 當做一個 service 咁 enable,
boot up 之後, 呢個 service 最後 start
start call install ....
op 有冇, set +x mode

當做 trial run under current dir.
就咁 ./Your_script_name.xxx start
應該就 download, install, run service.
  1. export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/tmp/libopenssl/lib  
  2. export PATH=$PATH:/tmp/openvpn/bin  
複製代碼
有冇加到個 path 去 /etc/profile

TOP

i don't think there is any error since you are not actually "asking" to do something.

TOP

本帖最後由 xiao 於 2016-3-20 22:34 編輯

回覆 3# cal22cal


OpenWRT 改版了, 下載安裝後, 每條PATH都多了 /usr/. 例如, libopenssl/usr/lib, 修改後就好了.
但是另外一個問題來了, 因為放在 /etc/init.d/, 開機時可以自動啟動, PS 看看PID, 有這個SERVICE存在, 不過沒有在這個 SCRIPT 處理密碼帳號的, 所以只有啟動, 實際上沒辦法連接 VPN SERVER, 要怎樣解決呢.



另外, 完全手動,
  1. /etc/init.d/openvpn start
複製代碼
安裝完畢, 手動輸入帳號密碼, 測試連接, 觀察VPN SERVER那端, 顯示是成功的, 但是還不會設定怎樣把資料透過VPN通道傳輸, IFCONFIG 也看不到VPN有連網.
附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊

TOP

頭盔 mode++
冇玩過 vpn, 不過睇吓個 script,
  1. command openvpn --writepid /tmp/openvpn/ovpn.pid --daemon --config /etc/openvpn/client.conf
複製代碼
conf file 係响 /etc/openvpn/client.conf
要响嗰度改 config

頭盔 mode--
如果你 ref 個條 link 太舊, 可能好多嘢都唔啱用,
睇吓依個有冇用
https://wiki.openwrt.org/doc/howto/vpn.openvpn

TOP

回覆 6# cal22cal


    明白了, 謝謝.
另外一個問題.
  1. #!/bin/sh /etc/rc.common

  2. START=99 ## 這句是做甚麼的呢
複製代碼

TOP

https://wiki.openwrt.org/doc/techref/initscripts

START
估計係用嚟 boot system, 嗰時大家排隊,
越大 number, 越後起動
grep START /etc/init.d/*

TOP