Jpp test-rotations-old-533-g2bdbdb559
the software that should make you happy
Loading...
Searching...
No Matches
JCookie.sh
Go to the documentation of this file.
1#!/usr/bin/env zsh
2#
3# \author mdejong
4#
5script=${0##*/}
6
7if [ -z $JPP_DIR ]; then
8 echo "Variable JPP_DIR undefined."
9 exit
10fi
11
12source $JPP_DIR/setenv.sh $JPP_DIR >& /dev/null
13
14set_variable COOKIE `getCookie`
15set_variable TIMEOUT_S 20
16
17if do_usage $*; then
18 usage "$script"\
19 "\nUtility script to check database cookie file."\
20 "\nIf needed, the user is prompted to create new cookie file."
21fi
22
23# test cookie
24
25if [[ -f $COOKIE ]]; then
26
27 JPrintDB -C $COOKIE -q detector >& /dev/null
28
29 if (( $? != 0 )); then
30 echo "Remove broken cookie file $COOKIE";
31 rm -f $COOKIE
32 fi
33fi
34
35if [[ ! -f $COOKIE ]]; then
36
37 if [[ -z "$DBCOOKIE" ]]; then
38
39 echo "Enter input within $TIMEOUT_S seconds."
40 echo -n "User name: "
41 read -t $TIMEOUT_S USR
42 if (( $? != 0 )); then
43 fatal "Timeout at user input."
44 fi
45 echo -n "Password: "
46 read -t $TIMEOUT_S -s PWD
47 echo
48 if (( $? != 0 )); then
49 fatal "Timeout at user input."
50 fi
51
52 set_variable SERVER `JServerDB`
53
54 URL="https://${SERVER}/home.htm?usr=${USR}&pwd=${PWD}&persist=y&freenetbits=16"
55
56 if command -v wget >/dev/null 2>&1; then
57 wget --no-check-certificate --quiet \
58 --output-document="$COOKIE" \
59 "$URL"
60 elif command -v curl >/dev/null 2>&1; then
61 curl --insecure --silent \
62 --output "$COOKIE" \
63 "$URL"
64 else
65 echo "Error: neither wget nor curl is available." >&2
66 exit 1
67 fi
68 sed -i -- "s/sid=/.in2p3.fr\\tTRUE\\t\/\\tTRUE\\t0\\tsid\\t/g" "$COOKIE"
69
70 if [[ ! -f $COOKIE ]]; then
71 fatal "No cookie $COOKIE"
72 fi
73 else
74
75 echo "Using DBCOOKIE; unset to disable."
76 fi
77fi
78
79JPrintDB -C $COOKIE -q detector >& /dev/null
80
81CHECK_EXIT_CODE