Artifact
4fc79e58e78234fdb198cec039f93d7da58066c2:
0000: 23 21 2f 62 69 6e 2f 62 61 73 68 0a 0a 23 20 20 #!/bin/bash..#
0010: 43 6f 70 79 72 69 67 68 74 20 32 30 30 36 2d 32 Copyright 2006-2
0020: 30 31 37 2c 20 4d 61 74 74 68 65 77 20 57 65 6c 017, Matthew Wel
0030: 6c 61 6e 64 2e 0a 23 20 0a 23 20 54 68 69 73 20 land..# .# This
0040: 66 69 6c 65 20 69 73 20 70 61 72 74 20 6f 66 20 file is part of
0050: 4d 65 67 61 74 65 73 74 2e 0a 23 20 0a 23 20 20 Megatest..# .#
0060: 20 20 20 4d 65 67 61 74 65 73 74 20 69 73 20 66 Megatest is f
0070: 72 65 65 20 73 6f 66 74 77 61 72 65 3a 20 79 6f ree software: yo
0080: 75 20 63 61 6e 20 72 65 64 69 73 74 72 69 62 75 u can redistribu
0090: 74 65 20 69 74 20 61 6e 64 2f 6f 72 20 6d 6f 64 te it and/or mod
00a0: 69 66 79 0a 23 20 20 20 20 20 69 74 20 75 6e 64 ify.# it und
00b0: 65 72 20 74 68 65 20 74 65 72 6d 73 20 6f 66 20 er the terms of
00c0: 74 68 65 20 47 4e 55 20 47 65 6e 65 72 61 6c 20 the GNU General
00d0: 50 75 62 6c 69 63 20 4c 69 63 65 6e 73 65 20 61 Public License a
00e0: 73 20 70 75 62 6c 69 73 68 65 64 20 62 79 0a 23 s published by.#
00f0: 20 20 20 20 20 74 68 65 20 46 72 65 65 20 53 6f the Free So
0100: 66 74 77 61 72 65 20 46 6f 75 6e 64 61 74 69 6f ftware Foundatio
0110: 6e 2c 20 65 69 74 68 65 72 20 76 65 72 73 69 6f n, either versio
0120: 6e 20 33 20 6f 66 20 74 68 65 20 4c 69 63 65 6e n 3 of the Licen
0130: 73 65 2c 20 6f 72 0a 23 20 20 20 20 20 28 61 74 se, or.# (at
0140: 20 79 6f 75 72 20 6f 70 74 69 6f 6e 29 20 61 6e your option) an
0150: 79 20 6c 61 74 65 72 20 76 65 72 73 69 6f 6e 2e y later version.
0160: 0a 23 20 0a 23 20 20 20 20 20 4d 65 67 61 74 65 .# .# Megate
0170: 73 74 20 69 73 20 64 69 73 74 72 69 62 75 74 65 st is distribute
0180: 64 20 69 6e 20 74 68 65 20 68 6f 70 65 20 74 68 d in the hope th
0190: 61 74 20 69 74 20 77 69 6c 6c 20 62 65 20 75 73 at it will be us
01a0: 65 66 75 6c 2c 0a 23 20 20 20 20 20 62 75 74 20 eful,.# but
01b0: 57 49 54 48 4f 55 54 20 41 4e 59 20 57 41 52 52 WITHOUT ANY WARR
01c0: 41 4e 54 59 3b 20 77 69 74 68 6f 75 74 20 65 76 ANTY; without ev
01d0: 65 6e 20 74 68 65 20 69 6d 70 6c 69 65 64 20 77 en the implied w
01e0: 61 72 72 61 6e 74 79 20 6f 66 0a 23 20 20 20 20 arranty of.#
01f0: 20 4d 45 52 43 48 41 4e 54 41 42 49 4c 49 54 59 MERCHANTABILITY
0200: 20 6f 72 20 46 49 54 4e 45 53 53 20 46 4f 52 20 or FITNESS FOR
0210: 41 20 50 41 52 54 49 43 55 4c 41 52 20 50 55 52 A PARTICULAR PUR
0220: 50 4f 53 45 2e 20 20 53 65 65 20 74 68 65 0a 23 POSE. See the.#
0230: 20 20 20 20 20 47 4e 55 20 47 65 6e 65 72 61 6c GNU General
0240: 20 50 75 62 6c 69 63 20 4c 69 63 65 6e 73 65 20 Public License
0250: 66 6f 72 20 6d 6f 72 65 20 64 65 74 61 69 6c 73 for more details
0260: 2e 0a 23 20 0a 23 20 20 20 20 20 59 6f 75 20 73 ..# .# You s
0270: 68 6f 75 6c 64 20 68 61 76 65 20 72 65 63 65 69 hould have recei
0280: 76 65 64 20 61 20 63 6f 70 79 20 6f 66 20 74 68 ved a copy of th
0290: 65 20 47 4e 55 20 47 65 6e 65 72 61 6c 20 50 75 e GNU General Pu
02a0: 62 6c 69 63 20 4c 69 63 65 6e 73 65 0a 23 20 20 blic License.#
02b0: 20 20 20 61 6c 6f 6e 67 20 77 69 74 68 20 4d 65 along with Me
02c0: 67 61 74 65 73 74 2e 20 20 49 66 20 6e 6f 74 2c gatest. If not,
02d0: 20 73 65 65 20 3c 68 74 74 70 3a 2f 2f 77 77 77 see <http://www
02e0: 2e 67 6e 75 2e 6f 72 67 2f 6c 69 63 65 6e 73 65 .gnu.org/license
02f0: 73 2f 3e 2e 0a 0a 70 72 65 66 69 78 3d 24 31 0a s/>...prefix=$1.
0300: 63 6d 64 3d 24 32 0a 74 61 72 67 65 74 3d 24 33 cmd=$2.target=$3
0310: 0a 63 66 67 66 69 6c 65 3d 22 24 70 72 65 66 69 .cfgfile="$prefi
0320: 78 2f 62 69 6e 2f 2e 24 28 6c 73 62 5f 72 65 6c x/bin/.$(lsb_rel
0330: 65 61 73 65 20 2d 73 72 29 2f 63 66 67 2e 73 68 ease -sr)/cfg.sh
0340: 22 0a 6c 69 62 64 69 72 3d 22 24 70 72 65 66 69 ".libdir="$prefi
0350: 78 2f 62 69 6e 2f 2e 24 28 6c 73 62 5f 72 65 6c x/bin/.$(lsb_rel
0360: 65 61 73 65 20 2d 73 72 29 2f 6c 69 62 22 0a 0a ease -sr)/lib"..
0370: 23 20 77 65 20 77 69 73 68 20 74 6f 20 63 72 65 # we wish to cre
0380: 61 74 65 20 61 20 76 61 72 20 69 6e 20 63 66 67 ate a var in cfg
0390: 2e 73 68 20 66 6f 72 20 66 69 6e 64 69 6e 67 20 .sh for finding
03a0: 73 71 6c 69 74 65 33 20 65 78 65 63 75 74 61 62 sqlite3 executab
03b0: 6c 65 0a 63 68 69 63 6b 65 6e 5f 62 69 6e 5f 64 le.chicken_bin_d
03c0: 69 72 3d 24 28 64 69 72 6e 61 6d 65 20 24 28 77 ir=$(dirname $(w
03d0: 68 69 63 68 20 63 73 69 29 29 0a 69 66 20 5b 5b hich csi)).if [[
03e0: 20 2d 65 20 24 63 68 69 63 6b 65 6e 5f 62 69 6e -e $chicken_bin
03f0: 5f 64 69 72 2f 73 71 6c 69 74 65 33 20 5d 5d 3b _dir/sqlite3 ]];
0400: 74 68 65 6e 0a 20 20 20 20 73 71 6c 69 74 65 33 then. sqlite3
0410: 5f 65 78 65 3d 24 63 68 69 63 6b 65 6e 5f 62 69 _exe=$chicken_bi
0420: 6e 5f 64 69 72 2f 73 71 6c 69 74 65 33 0a 65 6c n_dir/sqlite3.el
0430: 73 65 0a 20 20 20 20 73 71 6c 69 74 65 33 5f 65 se. sqlite3_e
0440: 78 65 3d 24 28 77 68 69 63 68 20 73 71 6c 69 74 xe=$(which sqlit
0450: 65 33 29 0a 66 69 0a 0a 69 66 20 5b 20 22 24 4c e3).fi..if [ "$L
0460: 44 5f 4c 49 42 52 41 52 59 5f 50 41 54 48 22 20 D_LIBRARY_PATH"
0470: 21 3d 20 22 22 20 5d 3b 74 68 65 6e 0a 20 20 65 != "" ];then. e
0480: 63 68 6f 20 22 49 4e 46 4f 3a 20 55 73 69 6e 67 cho "INFO: Using
0490: 20 4c 44 5f 4c 49 42 52 41 52 59 5f 50 41 54 48 LD_LIBRARY_PATH
04a0: 3d 24 4c 44 5f 4c 49 42 52 41 52 59 5f 50 41 54 =$LD_LIBRARY_PAT
04b0: 48 22 20 3e 26 32 0a 20 20 65 63 68 6f 20 22 49 H" >&2. echo "I
04c0: 4e 46 4f 3a 20 57 72 69 74 69 6e 67 20 24 63 66 NFO: Writing $cf
04d0: 67 66 69 6c 65 22 20 3e 26 32 0a 28 20 63 61 74 gfile" >&2.( cat
04e0: 20 3c 3c 20 5f 5f 45 4f 46 0a 69 66 20 5b 20 2d << __EOF.if [ -
04f0: 7a 20 5c 24 4d 54 5f 4f 52 49 47 5f 45 4e 56 20 z \$MT_ORIG_ENV
0500: 5d 3b 20 74 68 65 6e 0a 20 20 20 20 65 78 70 6f ]; then. expo
0510: 72 74 20 4d 54 5f 4f 52 49 47 5f 45 4e 56 3d 5c rt MT_ORIG_ENV=\
0520: 24 28 20 24 70 72 65 66 69 78 2f 62 69 6e 2f 73 $( $prefix/bin/s
0530: 65 72 69 61 6c 69 7a 65 2d 65 6e 76 20 29 0a 66 erialize-env ).f
0540: 69 0a 0a 69 66 20 5b 20 22 5c 24 4c 44 5f 4c 49 i..if [ "\$LD_LI
0550: 42 52 41 52 59 5f 50 41 54 48 22 20 21 3d 20 22 BRARY_PATH" != "
0560: 22 20 5d 3b 74 68 65 6e 0a 20 20 65 78 70 6f 72 " ];then. expor
0570: 74 20 4c 44 5f 4c 49 42 52 41 52 59 5f 50 41 54 t LD_LIBRARY_PAT
0580: 48 3d 24 4c 44 5f 4c 49 42 52 41 52 59 5f 50 41 H=$LD_LIBRARY_PA
0590: 54 48 3a 5c 24 4c 44 5f 4c 49 42 52 41 52 59 5f TH:\$LD_LIBRARY_
05a0: 50 41 54 48 3a 24 6c 69 62 64 69 72 0a 65 6c 73 PATH:$libdir.els
05b0: 65 0a 20 20 65 78 70 6f 72 74 20 4c 44 5f 4c 49 e. export LD_LI
05c0: 42 52 41 52 59 5f 50 41 54 48 3d 24 4c 44 5f 4c BRARY_PATH=$LD_L
05d0: 49 42 52 41 52 59 5f 50 41 54 48 3a 24 6c 69 62 IBRARY_PATH:$lib
05e0: 64 69 72 0a 66 69 0a 0a 65 78 70 6f 72 74 20 4d dir.fi..export M
05f0: 54 5f 53 51 4c 49 54 45 33 5f 45 58 45 3d 24 73 T_SQLITE3_EXE=$s
0600: 71 6c 69 74 65 33 5f 65 78 65 0a 0a 68 74 74 70 qlite3_exe..http
0610: 5f 76 61 72 73 3d 22 68 74 74 70 5f 70 72 6f 78 _vars="http_prox
0620: 79 20 68 74 74 70 73 5f 70 72 6f 78 79 20 48 54 y https_proxy HT
0630: 54 50 5f 50 52 4f 58 59 20 48 54 54 50 53 5f 50 TP_PROXY HTTPS_P
0640: 52 4f 58 59 22 0a 66 6f 72 20 69 20 69 6e 20 5c ROXY".for i in \
0650: 24 68 74 74 70 5f 76 61 72 73 0a 64 6f 0a 6a 3d $http_vars.do.j=
0660: 5c 24 7b 21 69 7d 0a 69 66 20 5b 20 22 5c 24 6a \${!i}.if [ "\$j
0670: 22 20 21 3d 20 22 22 20 5d 3b 20 74 68 65 6e 0a " != "" ]; then.
0680: 20 20 20 75 6e 73 65 74 20 5c 24 69 0a 66 69 0a unset \$i.fi.
0690: 64 6f 6e 65 0a 5f 5f 45 4f 46 0a 29 20 3e 20 24 done.__EOF.) > $
06a0: 63 66 67 66 69 6c 65 0a 20 20 65 63 68 6f 20 0a cfgfile. echo .
06b0: 65 6c 73 65 0a 20 20 65 63 68 6f 20 22 49 4e 46 else. echo "INF
06c0: 4f 3a 20 4c 44 5f 4c 49 42 52 41 52 59 5f 50 41 O: LD_LIBRARY_PA
06d0: 54 48 20 6e 6f 74 20 73 65 74 22 20 3e 26 32 0a TH not set" >&2.
06e0: 66 69 0a 0a 65 63 68 6f 20 22 23 21 2f 62 69 6e fi..echo "#!/bin
06f0: 2f 62 61 73 68 22 20 3e 20 24 74 61 72 67 65 74 /bash" > $target
0700: 0a 0a 69 66 20 5b 5b 20 24 63 6d 64 20 3d 7e 20 ..if [[ $cmd =~
0710: 64 62 6f 61 72 64 20 5d 5d 3b 20 74 68 65 6e 0a dboard ]]; then.
0720: 20 20 20 20 63 61 74 20 3e 3e 20 24 74 61 72 67 cat >> $targ
0730: 65 74 20 3c 3c 27 45 4f 46 27 0a 0a 23 20 23 20 et <<'EOF'..# #
0740: 64 69 73 61 62 6c 65 20 69 66 20 6e 6f 74 20 72 disable if not r
0750: 75 6e 6e 69 6e 67 20 6f 6e 20 68 6f 6d 65 68 6f unning on homeho
0760: 73 74 0a 23 20 69 66 20 5b 5b 20 2d 65 20 2e 68 st.# if [[ -e .h
0770: 6f 6d 65 68 6f 73 74 20 5d 5d 3b 20 74 68 65 6e omehost ]]; then
0780: 0a 23 20 20 20 68 6f 6d 65 68 6f 73 74 6e 61 6d .# homehostnam
0790: 65 3d 24 28 20 68 6f 73 74 20 60 63 61 74 20 2e e=$( host `cat .
07a0: 68 6f 6d 65 68 6f 73 74 60 20 7c 20 61 77 6b 20 homehost` | awk
07b0: 27 7b 70 72 69 6e 74 20 24 4e 46 7d 27 20 7c 20 '{print $NF}' |
07c0: 73 65 64 20 27 73 2f 5c 2e 24 2f 2f 27 20 29 0a sed 's/\.$//' ).
07d0: 23 20 20 20 68 6f 73 74 6e 61 6d 65 3d 24 28 20 # hostname=$(
07e0: 68 6f 73 74 6e 61 6d 65 20 2d 66 20 29 0a 23 20 hostname -f ).#
07f0: 0a 23 20 20 20 69 66 20 5b 5b 20 21 20 28 24 68 .# if [[ ! ($h
0800: 6f 6d 65 68 6f 73 74 6e 61 6d 65 20 3d 3d 20 24 omehostname == $
0810: 68 6f 73 74 6e 61 6d 65 29 20 5d 5d 3b 20 74 68 hostname) ]]; th
0820: 65 6e 0a 23 20 20 20 20 20 65 63 68 6f 20 22 45 en.# echo "E
0830: 52 52 4f 52 3a 20 74 68 69 73 20 68 6f 73 74 20 RROR: this host
0840: 28 24 68 6f 73 74 6e 61 6d 65 29 20 69 73 20 6e ($hostname) is n
0850: 6f 74 20 74 68 65 20 68 6f 6d 65 68 6f 73 74 20 ot the homehost
0860: 28 24 68 6f 6d 65 68 6f 73 74 6e 61 6d 65 29 20 ($homehostname)
0870: 66 6f 72 20 74 68 69 73 20 6d 65 67 61 74 65 73 for this megates
0880: 74 20 72 75 6e 20 61 72 65 61 2e 20 20 43 61 6e t run area. Can
0890: 6e 6f 74 20 73 74 61 72 74 20 64 61 73 68 62 6f not start dashbo
08a0: 61 72 64 2e 22 0a 23 20 20 20 20 20 65 63 68 6f ard.".# echo
08b0: 20 22 20 20 20 20 20 20 20 50 6c 65 61 73 65 20 " Please
08c0: 6c 6f 67 20 69 6e 74 6f 20 68 6f 6d 65 68 6f 73 log into homehos
08d0: 74 20 62 65 66 6f 72 65 20 6c 61 75 6e 63 68 69 t before launchi
08e0: 6e 67 20 64 61 73 68 62 6f 61 72 64 2e 22 0a 23 ng dashboard.".#
08f0: 20 20 20 20 20 65 78 69 74 20 31 0a 23 20 20 20 exit 1.#
0900: 66 69 0a 23 20 66 69 0a 0a 23 20 63 68 65 63 6b fi.# fi..# check
0910: 20 74 68 61 74 20 24 44 49 53 50 4c 41 59 20 69 that $DISPLAY i
0920: 73 20 73 65 74 0a 69 66 20 5b 5b 20 2d 7a 20 24 s set.if [[ -z $
0930: 44 49 53 50 4c 41 59 20 5d 5d 3b 20 74 68 65 6e DISPLAY ]]; then
0940: 0a 20 20 20 65 63 68 6f 20 27 45 52 52 4f 52 3a . echo 'ERROR:
0950: 20 24 44 49 53 50 4c 41 59 20 65 6e 76 69 72 6f $DISPLAY enviro
0960: 6e 6d 65 6e 74 20 76 61 72 69 61 62 6c 65 20 69 nment variable i
0970: 73 20 6e 6f 74 20 73 65 74 3b 20 6d 65 67 61 74 s not set; megat
0980: 65 73 74 20 64 61 73 68 62 6f 61 72 64 20 72 65 est dashboard re
0990: 71 75 69 72 65 73 20 58 20 64 69 73 70 6c 61 79 quires X display
09a0: 20 61 64 64 72 65 73 73 20 74 6f 20 62 65 20 73 address to be s
09b0: 65 74 20 69 6e 20 24 44 49 53 50 4c 41 59 2e 27 et in $DISPLAY.'
09c0: 0a 20 20 20 65 78 69 74 20 31 0a 66 69 0a 0a 23 . exit 1.fi..#
09d0: 20 63 68 65 63 6b 20 74 68 61 74 20 24 44 49 53 check that $DIS
09e0: 50 4c 41 59 20 69 73 20 70 72 6f 70 65 72 0a 69 PLAY is proper.i
09f0: 66 20 5b 5b 20 2d 78 20 24 28 77 68 69 63 68 20 f [[ -x $(which
0a00: 78 64 70 79 69 6e 66 6f 20 20 32 3e 2f 64 65 76 xdpyinfo 2>/dev
0a10: 2f 6e 75 6c 6c 29 20 5d 5d 3b 20 74 68 65 6e 0a /null) ]]; then.
0a20: 20 20 69 66 20 21 20 78 64 70 79 69 6e 66 6f 20 if ! xdpyinfo
0a30: 2d 64 69 73 70 6c 61 79 20 22 24 44 49 53 50 4c -display "$DISPL
0a40: 41 59 22 20 26 3e 2f 64 65 76 2f 6e 75 6c 6c 3b AY" &>/dev/null;
0a50: 20 74 68 65 6e 0a 20 20 20 20 65 63 68 6f 20 27 then. echo '
0a60: 45 52 52 4f 52 3a 20 6d 65 67 61 74 65 73 74 20 ERROR: megatest
0a70: 64 61 73 68 62 6f 61 72 64 20 63 61 6e 6e 6f 74 dashboard cannot
0a80: 20 6f 70 65 6e 20 64 69 73 70 6c 61 79 20 22 27 open display "'
0a90: 24 44 49 53 50 4c 41 59 27 22 2e 20 20 50 6c 65 $DISPLAY'". Ple
0aa0: 61 73 65 20 63 68 65 63 6b 20 24 44 49 53 50 4c ase check $DISPL
0ab0: 41 59 20 65 6e 76 69 72 6f 6e 6d 65 6e 74 20 76 AY environment v
0ac0: 61 72 69 61 62 6c 65 2e 27 0a 20 20 20 20 65 78 ariable.'. ex
0ad0: 69 74 20 31 0a 20 20 66 69 0a 66 69 0a 45 4f 46 it 1. fi.fi.EOF
0ae0: 0a 0a 66 69 0a 0a 63 61 74 20 3e 3e 20 24 74 61 ..fi..cat >> $ta
0af0: 72 67 65 74 20 3c 3c 20 45 4f 46 20 0a 69 66 20 rget << EOF .if
0b00: 5b 5b 20 5c 24 28 75 6c 69 6d 69 74 20 2d 61 20 [[ \$(ulimit -a
0b10: 7c 20 67 72 65 70 20 27 6f 70 65 6e 20 66 69 6c | grep 'open fil
0b20: 65 73 27 20 7c 20 61 77 6b 20 27 7b 70 72 69 6e es' | awk '{prin
0b30: 74 20 5c 24 34 7d 27 29 20 2d 67 74 20 31 30 30 t \$4}') -gt 100
0b40: 30 30 20 5d 5d 3b 74 68 65 6e 20 75 6c 69 6d 69 00 ]];then ulimi
0b50: 74 20 2d 6e 20 31 30 30 30 30 3b 66 69 0a 45 4f t -n 10000;fi.EO
0b60: 46 0a 0a 23 20 65 63 68 6f 20 22 23 21 2f 62 69 F..# echo "#!/bi
0b70: 6e 2f 62 61 73 68 22 20 3e 20 24 74 61 72 67 65 n/bash" > $targe
0b80: 74 0a 23 20 65 63 68 6f 20 22 65 78 65 63 20 24 t.# echo "exec $
0b90: 70 72 65 66 69 78 2f 62 69 6e 2f 2e 5c 24 28 6c prefix/bin/.\$(l
0ba0: 73 62 5f 72 65 6c 65 61 73 65 20 2d 73 72 29 2f sb_release -sr)/
0bb0: 24 63 6d 64 20 5c 22 5c 24 40 5c 22 22 20 3e 3e $cmd \"\$@\"" >>
0bc0: 20 24 74 61 72 67 65 74 0a 0a 65 63 68 6f 20 22 $target..echo "
0bd0: 6c 73 62 72 3d 5c 24 28 6c 73 62 5f 72 65 6c 65 lsbr=\$(lsb_rele
0be0: 61 73 65 20 2d 73 72 29 22 20 3e 3e 20 24 74 61 ase -sr)" >> $ta
0bf0: 72 67 65 74 0a 65 63 68 6f 20 22 73 6f 75 72 63 rget.echo "sourc
0c00: 65 20 24 70 72 65 66 69 78 2f 62 69 6e 2f 2e 5c e $prefix/bin/.\
0c10: 24 6c 73 62 72 2f 63 66 67 2e 73 68 22 20 3e 3e $lsbr/cfg.sh" >>
0c20: 20 24 74 61 72 67 65 74 0a 0a 23 20 65 63 68 6f $target..# echo
0c30: 20 22 69 66 20 5b 5b 20 2d 65 20 5c 24 6c 73 62 "if [[ -e \$lsb
0c40: 72 20 5d 5d 3b 74 68 65 6e 20 73 6f 75 72 63 65 r ]];then source
0c50: 20 5c 24 6c 73 62 72 3b 66 69 22 20 3e 3e 20 24 \$lsbr;fi" >> $
0c60: 74 61 72 67 65 74 0a 65 63 68 6f 20 22 65 78 65 target.echo "exe
0c70: 63 20 24 70 72 65 66 69 78 2f 62 69 6e 2f 2e 5c c $prefix/bin/.\
0c80: 24 6c 73 62 72 2f 24 63 6d 64 20 5c 22 5c 24 40 $lsbr/$cmd \"\$@
0c90: 5c 22 22 20 3e 3e 20 24 74 61 72 67 65 74 0a \"" >> $target.