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}."
63 -L http://${DNS323_HOSTNAME}/goform/formLogin \
64 -d "f_LOGIN_NAME=admin&f_LOGIN_PASSWD=${DNS323_ADMIN_PASSWORD}&f_login_type=0" \
65 || (echo "Failed." >&2 && exit 1)
66 already_authentified=1
70 function check_unmounted () {
71 if [[ ! ${force_operation} ]]; then
72 if [[ $(mount | grep ^//${DNS323_HOSTNAME}) ]]; then
73 echo "//${DNS323_HOSTNAME} appears to be mounted." >&2
79 function show_help () {
81 $(basename $0) [-f|--force] [-h|--help] <status|restart|shutdown> ...
83 -h, --help shows this help.
84 -f, --force forces shutdown or restart even if it looks like the samba
86 status gets temperature and RAID info.
87 shutdown shuts the unit down.
88 restart restarts the unit.
93 ######################################################################
95 trap rm_temp SIGHUP SIGINT SIGQUIT SIGABRT SIGTERM ERR
97 if [[ ${DNS323_HOSTNAME} ]] && \
98 [[ ${DNS323_ADMIN_PASSWORD} ]]; then
104 ################################################################
110 ################################################################
116 ################################################################
122 # If you think what follows is fugly, please have a
123 # look at the DNS323's web app HTML
125 TMP=$(mktemp /tmp/status.XXXXXX)
128 -L http://${DNS323_HOSTNAME}/goform/adv_status \
133 grep "\(Sync Time Remaining\|Volume Name\|Volume Type\|Total Hard Drive Capacity\|Used Space\|Unused Space\)": | \
134 sed -e "s/^[ \t]*//" | while read line; do
135 label=$(echo ${line} | sed -e "s/:.*$//")
136 value=$(echo ${line} | sed -e "s/^[^0-9]*\([0-9]*\).*$/\1/")
138 "Total Hard Drive Capacity")
142 line="${line} ($(((value*100)/total))%)"
145 line="${line} ($(((value*100)/total))%)"
147 "Sync Time Remaining")
148 state=$(echo ${line} | sed -e "s/^[^:]*:[^A-Za-z]*//")
149 if [[ ! "${state}" == "Completed" ]]; then
150 line="${VT_RED_FG}${VT_BOLD}${line} !!! THIS IS NOT NORMAL !!!${VT_RESET}"
159 grep "var temper" ${TMP} | sed -e "s/^.*\"\([0-9]*\):\([0-9]*\)\".*$/Temperature: \1F \/ \2C/"
165 ################################################################
175 -L http://${DNS323_HOSTNAME}/goform/sysShutDown \
178 echo "Shutdown initiated."
182 ################################################################
192 -L http://${DNS323_HOSTNAME}/goform/System_restart \
195 echo "Restart initiated."
199 ################################################################
202 echo "Unknown operation $1" >&2
214 echo "Please set \$DNS323_HOSTNAME and \$DNS323_ADMIN_PASSWORD."