3 #########################################################################
4 # This program is free software: you can redistribute it and/or modify #
5 # it under the terms of the version 3 of the GNU General Public License #
6 # as published by the Free Software Foundation. #
8 # This program is distributed in the hope that it will be useful, but #
9 # WITHOUT ANY WARRANTY; without even the implied warranty of #
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
11 # General Public License for more details. #
13 # You should have received a copy of the GNU General Public License #
14 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
16 # Written by and Copyright (C) Francois Fleuret #
17 # Contact <francois@fleuret.org> for comments & bug reports #
18 #########################################################################
20 # A command-line tool to restart, shutdown or get the status of a
26 if [[ ${TEMP} ]]; then
32 function authentify_on_dns323 () {
33 if [[ ! ${already_authentified} ]]; then
34 echo "Authentifying on ${DNS323_HOSTNAME}."
36 -L http://${DNS323_HOSTNAME}/goform/formLogin \
37 -d "f_LOGIN_NAME=admin&f_LOGIN_PASSWD=${DNS323_ADMIN_PASSWORD}&f_login_type=0" \
38 || (echo "Failed." >&2 && exit 1)
39 already_authentified=1
43 function check_unmounted () {
44 if [[ ! ${force_operation} ]]; then
45 if [[ $(mount | grep ^//${DNS323_HOSTNAME}) ]]; then
46 echo "//${DNS323_HOSTNAME} appears to be mounted." >&2
52 function show_help () {
54 $(basename $0) [-f|--force] [-h|--help] <status|restart|shutdown> ...
56 -h, --help shows this help.
57 -f, --force forces shutdown or restart even if it looks like the samba
59 status gets temperature and RAID info.
60 shutdown shuts the unit down.
61 restart restarts the unit.
66 ######################################################################
68 trap rm_temp SIGHUP SIGINT SIGQUIT SIGABRT SIGTERM ERR
70 if [[ ${DNS323_HOSTNAME} ]] && \
71 [[ ${DNS323_ADMIN_PASSWORD} ]]; then
77 ################################################################
83 ################################################################
89 ################################################################
95 # If you think what follows is fugly, please have a
96 # look at the DNS323's web app HTML
98 TEMP=$(mktemp /tmp/status.XXXXXX)
101 -L http://${DNS323_HOSTNAME}/goform/adv_status \
106 grep "\(Sync Time Remaining\|Volume Name\|Volume Type\|Total Hard Drive Capacity\|Used Space\|Unused Space\)": | \
109 grep "var temper" ${TEMP} | sed -e "s/^.*\"\([0-9]*\):\([0-9]*\)\".*$/Temperature: \1F \/ \2C/"
115 ################################################################
125 -L http://${DNS323_HOSTNAME}/goform/sysShutDown \
128 echo "Shutdown initiated."
132 ################################################################
140 curl -s > /dev/null \
141 -L http://${DNS323_HOSTNAME}/goform/System_restart \
144 echo "Restart initiated."
148 ################################################################
151 echo "Unknown operation $1" >&2
163 echo "Please set \$DNS323_HOSTNAME and \$DNS323_ADMIN_PASSWORD."