Thiết lập Cài đặt Optware-ng (Odroid, Raspberry Pi, Banana Pi...)
Đây là hướng dẫn đầy đủ về cách cài đặt Optware thế hệ mới trên thiết bị có cpu ArmHardFloat, đã thử nghiệm trên Odroid C1, XU4, Ubuntu 14.04 & 15.10
- Tải xuống và tạo môi trường Optware
cd /
mkdir -p /opt
cd /opt
wget -O - http://oe.seadrop.info/optware-ng/bootstrap/buildroot-armeabihf-bootstrap.sh | sh
- Thêm đường dẫn
export PATH=$PATH:/opt/bin:/opt/sbin
- Cài đặt gói findutils
ipkg install findutils
- Tạo tập lệnh khởi động init.d, dán vào thiết bị đầu cuối
cat >> /etc/init.d/optware.sh << 'EOF'
#!/bin/sh
### BEGIN INIT INFO
# Provides: optware-ng
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Should-Start: $network
# Should-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Daemonized version of deluge and webui.
# Description: Starts optware-ng installed services
# Author: TeHashX / contact@hqt.ro
### END INIT INFO
# Optware-NG Author: Alllexx
# Modified: TeHashX
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
SCRIPTNAME=optware
OPT='/opt/etc/init.d/rc.unslung'
case "$1" in
start)
echo "Starting Optware-NG installed services"
sleep 5
$OPT start
;;
stop)
echo "Stopping Optware-NG installed services"
$OPT stop
;;
restart|force-reload)
echo "Restarting Optware-NG installed services"
$OPT stop
sleep 2
$OPT start
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >\&2
exit 3
;;
esac
:
EOF
- Làm cho tập lệnh có thể thực thi được
chmod +x /etc/init.d/optware.sh
- Tạo tập lệnh rc.func, dán vào thiết bị đầu cuối
cat >> /opt/etc/init.d/rc.func << 'EOF'
#!/bin/sh
ACTION=$1
CALLER=$2
ansi_red="\033[1;31m";
ansi_white="\033[1;37m";
ansi_green="\033[1;32m";
ansi_yellow="\033[1;33m";
ansi_blue="\033[1;34m";
ansi_bell="\007";
ansi_blink="\033[5m";
ansi_std="\033[m";
ansi_rev="\033[7m";
ansi_ul="\033[4m";
start() {
[ "$CRITICAL" != "yes" -a "$CALLER" = "cron" ] && return 7
[ "$ENABLED" != "yes" ] && return 8
echo -e -n "$ansi_white Starting $DESC... "
if [ -n "`pidof $PROC`" ]; then
echo -e " $ansi_yellow already running. $ansi_std"
return 0
fi
$PRECMD > /dev/null 2>&1
$PREARGS $PROC $ARGS > /dev/null 2>&1 &
#echo $PREARGS $PROC $ARGS
COUNTER=0
LIMIT=10
while [ -z "`pidof $PROC`" -a "$COUNTER" -le "$LIMIT" ]; do
sleep 1s;
COUNTER=`expr $COUNTER + 1`
done
$POSTCMD > /dev/null 2>&1
if [ -z "`pidof $PROC`" ]; then
echo -e " $ansi_red failed. $ansi_std"
logger "Failed to start $DESC from $CALLER."
return 255
else
echo -e " $ansi_green done. $ansi_std"
logger "Started $DESC from $CALLER."
return 0
fi
}
stop() {
case "$ACTION" in
stop | restart)
echo -e -n "$ansi_white Shutting down $PROC... "
killall $PROC 2>/dev/null
COUNTER=0
LIMIT=10
while [ -n "`pidof $PROC`" -a "$COUNTER" -le "$LIMIT" ]; do
sleep 1s;
COUNTER=`expr $COUNTER + 1`
done
;;
kill)
echo -e -n "$ansi_white Killing $PROC... "
killall -9 $PROC 2>/dev/null
;;
esac
if [ -n "`pidof $PROC`" ]; then
echo -e " $ansi_red failed. $ansi_std"
return 255
else
echo -e " $ansi_green done. $ansi_std"
return 0
fi
}
check() {
echo -e -n "$ansi_white Checking $DESC... "
if [ -n "`pidof $PROC`" ]; then
echo -e " $ansi_green alive. $ansi_std";
return 0
else
echo -e " $ansi_red dead. $ansi_std";
return 1
fi
}
reconfigure() {
SIGNAL=SIGHUP
echo -e "$ansi_white Sending $SIGNAL to $PROC... "
killall -$SIGNAL $PROC 2>/dev/null
}
for PROC in $PROCS; do
case $ACTION in
start)
start
;;
stop | kill )
check && stop
;;
restart)
check > /dev/null && stop
start
;;
check)
check
;;
reconfigure)
reconfigure
;;
*)
echo -e "$ansi_white Usage: $0 (start|stop|restart|check|kill|reconfigure)$ansi_std"
exit 1
;;
esac
done
EOF
- Tạo tập lệnh rc.unslung, dán vào terminal
cat >> /opt/etc/init.d/rc.unslung << 'EOF'
#!/bin/sh
# Start/stop all init scripts in /opt/etc/init.d including symlinks
# starting them in numerical order and
# stopping them in reverse numerical order
#logger "Started $0${*:+ $*}."
ACTION=$1
CALLER=$2
if [ $# -lt 1 ]; then
printf "Usage: $0 {start|stop|restart|reconfigure|check|kill}\n" >&2
exit 1
fi
[ $ACTION = stop -o $ACTION = restart -o $ACTION = kill ] && ORDER="-r"
for i in $(/opt/bin/find /opt/etc/init.d/ -perm '-u+x' -name 'S*' | sort $ORDER ) ;
do
case "$i" in
S* | *.sh )
# Source shell script for speed.
trap "" INT QUIT TSTP EXIT
#set $1
#echo "trying $i" >> /tmp/rc.log
. $i $ACTION $CALLER
;;
*)
# No sh extension, so fork subprocess.
$i $ACTION $CALLER
;;
esac
done
EOF
- Làm cho tập lệnh có thể thực thi được
chmod +x /opt/etc/init.d/*
- Cài đặt một số gói Optware được biên dịch sẵn, ví dụ. minidlna
ipkg install minidlna
- Bật tự động khởi động khi khởi động lại hệ thống
update-rc.d optware.sh defaults
- Bắt đầu tất cả các dịch vụ đã cài đặt optware
/etc/init.d/optware.sh start
Nếu bạn nhập lại thiết bị đầu cuối hoặc khởi động lại thiết bị, đường dẫn sẽ bị mất, để làm cho nó vĩnh viễn, hãy thêm đường dẫn optware vào /etc/profile.d, dán vào thiết bị đầu cuối
echo 'PATH=$PATH:/opt/bin:/opt/sbin' >> /etc/profile.d/optware-path.sh
Bây giờ hãy thưởng thức âm thanh của các gói được biên dịch sẵn