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
25 export VT_RESET=$'\e[0m'
26 export VT_BOLD=$'\e[1m'
27 export VT_UNDERLINE=$'\e[4m'
28 export VT_BLINK=$'\e[5m'
30 export VT_SET_TITLE=$'\e]0;'
31 export VT_END_TITLE=$'\007'
33 export VT_BLACK_FG=$'\e[30m'
34 export VT_RED_FG=$'\e[31m'
35 export VT_GREEN_FG=$'\e[32m'
36 export VT_YELLOW_FG=$'\e[33m'
37 export VT_BLUE_FG=$'\e[34m'
38 export VT_MAGENTA_FG=$'\e[35m'
39 export VT_CYAN_FG=$'\e[36m'
40 export VT_WHITE_FG=$'\e[37m'
42 export VT_BLACK_BG=$'\e[40m'
43 export VT_RED_BG=$'\e[41m'
44 export VT_GREEN_BG=$'\e[42m'
45 export VT_YELLOW_BG=$'\e[43m'
46 export VT_BLUE_BG=$'\e[44m'
47 export VT_MAGENTA_BG=$'\e[45m'
48 export VT_CYAN_BG=$'\e[46m'
49 export VT_WHITE_BG=$'\e[47m'
58 function authentify_on_dns323 () {
59 if [[ ! ${already_authentified} ]]; then
60 echo "Authentifying on ${DNS323_HOSTNAME}."
62 -L http://${DNS323_HOSTNAME}/goform/formLogin \
63 -d "f_LOGIN_NAME=admin&f_LOGIN_PASSWD=${DNS323_ADMIN_PASSWORD}&f_login_type=0" \
64 || (echo "Failed." >&2 && exit 1)
65 already_authentified=1
69 function check_unmounted () {
70 if [[ ! ${force_operation} ]]; then
71 if [[ $(mount | grep ^//${DNS323_HOSTNAME}) ]]; then
72 echo "//${DNS323_HOSTNAME} appears to be mounted." >&2
78 function show_help () {
80 $(basename $0) [-f|--force] [-h|--help] <status|restart|shutdown> ...
82 -h, --help shows this help.
83 -f, --force forces shutdown or restart even if it looks like the samba
85 status gets temperature and RAID info.
86 shutdown shuts the unit down.
87 restart restarts the unit.
92 ######################################################################
94 trap rm_temp SIGHUP SIGINT SIGQUIT SIGABRT SIGTERM ERR
96 if [[ ${DNS323_HOSTNAME} ]] && \
97 [[ ${DNS323_ADMIN_PASSWORD} ]]; then
103 ################################################################
109 ################################################################
115 ################################################################
121 # If you think what follows is fugly, please have a
122 # look at the DNS323's web app HTML
124 TMP=$(mktemp /tmp/status.XXXXXX)
127 -L http://${DNS323_HOSTNAME}/goform/adv_status \
132 grep "\(Sync Time Remaining\|Volume Name\|Volume Type\|Total Hard Drive Capacity\|Used Space\|Unused Space\)": | \
133 sed -e "s/^[ \t]*//" | while read line; do
134 label=$(echo ${line} | sed -e "s/:.*$//")
135 value=$(echo ${line} | sed -e "s/^[^0-9]*\([0-9]*\).*$/\1/")
137 "Total Hard Drive Capacity")
141 line="${line} ($(((value*100)/total))%)"
144 line="${line} ($(((value*100)/total))%)"
146 "Sync Time Remaining")
147 state=$(echo ${line} | sed -e "s/^[^:]*:[^A-Za-z]*//")
148 if [[ ! "${state}" == "Completed" ]]; then
149 line="${VT_RED_FG}${VT_BOLD}${line} !!! THIS IS NOT NORMAL !!!${VT_RESET}"
158 grep "var temper" ${TMP} | sed -e "s/^.*\"\([0-9]*\):\([0-9]*\)\".*$/Temperature: \1F \/ \2C/"
164 ################################################################
174 -L http://${DNS323_HOSTNAME}/goform/sysShutDown \
177 echo "Shutdown initiated."
181 ################################################################
189 curl -s > /dev/null \
190 -L http://${DNS323_HOSTNAME}/goform/System_restart \
193 echo "Restart initiated."
197 ################################################################
200 echo "Unknown operation $1" >&2
212 echo "Please set \$DNS323_HOSTNAME and \$DNS323_ADMIN_PASSWORD."