作者: xiao 時間: 2016-3-20 15:47 標題: 學習 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的
[attach]1874484[/attach]
那個沒有動作的SHELL SCRIPT, 抄自此處, 請前輩指點一二,
https://blog.zauberstuhl.de/openwrt_tplink_openvpn/
- #!/bin/sh /etc/rc.common
- START=99
- . /etc/profile
- install() {
- local OVPNPATH=/tmp/openvpn
- local OSSLPATH=/tmp/libopenssl
- [ ! -d ${OVPNPATH} ] && mkdir ${OVPNPATH}
- [ ! -d ${OSSLPATH} ] && mkdir ${OSSLPATH}
- command opkg update || exit 1
- # install openvpn
- cd ${OVPNPATH}
- tar xzf $(opkg download openvpn-openssl |grep Downloaded |cut -d\ -f4 |sed '$s/.$//')
- tar xzf data.tar.gz
- # delete unnecessary things (save space)
- rm -f pkg.tar.gz data.tar.gz control.tar.gz debian-binary getopenvpn.sh
- # install libopenssl
- cd ${OSSLPATH}
- tar xzf $(opkg download libopenssl |grep Downloaded |cut -d\ -f4 |sed '$s/.$//')
- tar xzf data.tar.gz
- # delete unnecessary things (save space)
- rm -f control.tar.gz debian-binary data.tar.gz
- }
- start () {
- # lvl 99 is not enough the script is too
- sleep 10 # fast for the install step
- install # setup openvpn and libssl
- command openvpn --writepid /tmp/openvpn/ovpn.pid --daemon --config /etc/openvpn/client.conf
- }
- stop() {
- PIDOF=$(ps |egrep openvpn |egrep -v grep |awk '{print $1}')
- kill ${PIDOF}
- }
作者: chancho 時間: 2016-3-20 16:54
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.
作者: cal22cal 時間: 2016-3-20 21:11
- 沒有動作
估計係
要將個 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.
- export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/tmp/libopenssl/lib
- export PATH=$PATH:/tmp/openvpn/bin
作者: chancho 時間: 2016-3-20 21:53
i don't think there is any error since you are not actually "asking" to do something.
作者: xiao 時間: 2016-3-20 22:32
本帖最後由 xiao 於 2016-3-20 22:34 編輯
回覆 3# cal22cal
OpenWRT 改版了, 下載安裝後, 每條PATH都多了 /usr/. 例如, libopenssl/usr/lib, 修改後就好了.
但是另外一個問題來了, 因為放在 /etc/init.d/, 開機時可以自動啟動, PS 看看PID, 有這個SERVICE存在, 不過沒有在這個 SCRIPT 處理密碼帳號的, 所以只有啟動, 實際上沒辦法連接 VPN SERVER, 要怎樣解決呢.
[attach]1874596[/attach]
另外, 完全手動,
- /etc/init.d/openvpn start
[attach]1874597[/attach]
作者: cal22cal 時間: 2016-3-21 09:00
頭盔 mode++
冇玩過 vpn, 不過睇吓個 script,
- command openvpn --writepid /tmp/openvpn/ovpn.pid --daemon --config /etc/openvpn/client.conf
要响嗰度改 config
頭盔 mode--
如果你 ref 個條 link 太舊, 可能好多嘢都唔啱用,
睇吓依個有冇用
https://wiki.openwrt.org/doc/howto/vpn.openvpn
作者: xiao 時間: 2016-3-21 18:18
回覆 6# cal22cal
明白了, 謝謝.
另外一個問題.
- #!/bin/sh /etc/rc.common
- START=99 ## 這句是做甚麼的呢
作者: cal22cal 時間: 2016-3-21 18:55
https://wiki.openwrt.org/doc/techref/initscripts
START
估計係用嚟 boot system, 嗰時大家排隊,
越大 number, 越後起動
grep START /etc/init.d/*
