tazbug rev 5
Add tazbug cmdline tool
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Tue Apr 03 12:08:57 2012 +0200 (2012-04-03) |
parents | e8324bc38bb5 |
children | bf39c8d28dcc |
files | tazbug |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/tazbug Tue Apr 03 12:08:57 2012 +0200 1.3 @@ -0,0 +1,174 @@ 1.4 +#!/bin/sh 1.5 +# 1.6 +# TazBug Command line tool. Help crypt password, key and post on the 1.7 +# the server side. 1.8 +# 1.9 +# Copyright (C) 2012 SliTaz GNU/Linux - BSD License 1.10 +# 1.11 +. /usr/lib/slitaz/httphelper 1.12 +[ -f "/etc/slitaz/tazbug.conf" ] && . /etc/slitaz/tazbug.conf 1.13 +[ -f "tazbug.conf" ] && . tazbug.conf 1.14 + 1.15 +# Use same key for SliTaz sites. 1.16 +conf=$HOME/.config/slitaz/account.conf 1.17 + 1.18 +# Internationalization: $(gettext "") 1.19 +. /usr/bin/gettext.sh 1.20 +TEXTDOMAIN='tazbug' 1.21 +export TEXTDOMAIN 1.22 + 1.23 +# Parse cmdline options. 1.24 +for opt in "$@" 1.25 +do 1.26 + case "$opt" in 1.27 + --bug=*) 1.28 + bug=${opt#--bug=} ;; 1.29 + --desc=*) 1.30 + desc=${opt#--desc=} ;; 1.31 + --msg=*) 1.32 + msg=${opt#--msg=} ;; 1.33 + --priority=*) 1.34 + priority=${opt#--priority=} ;; 1.35 + --pkgs=*) 1.36 + pkgs=${opt#--pkgs=} ;; 1.37 + --name=*) 1.38 + name=${opt#--name=} ;; 1.39 + --user=*) 1.40 + user=${opt#--user=} ;; 1.41 + --mail=*) 1.42 + mail=${opt#--mail=} ;; 1.43 + --pass=*) 1.44 + pass=${opt#--pass=} ;; 1.45 + esac 1.46 +done 1.47 + 1.48 +# 1.49 +# Functions 1.50 +# 1.51 + 1.52 +# --> in /usr/lib/slitaz/httphelper 1.53 +# httpd -e dont work with GET URL requests 1.54 +http_urlencode() { 1.55 + #space: + or %20 1.56 + sed -e s'/ /+/'g -e s'/!/%21/'g -e s'/"/%22/'g -e s'/#/%23/'g \ 1.57 + -e s'/%/%25/'g -e s'/&/%26/'g 1.58 +} 1.59 + 1.60 +# Usage. 1.61 +usage() { 1.62 + cat << EOT 1.63 + 1.64 +Usage: $(basename $0) [command] [args] 1.65 + 1.66 +Commands: 1.67 + gen-key $(gettext "Recreate the SliTaz secure key.") 1.68 + gen-config $(gettext "Create a new SliTaz account configuration.") 1.69 + signup $(gettext "Create a new account on SliTaz Bugs.") 1.70 + new-msg $(gettext "Send a new message to an open bug.") 1.71 + new-bug $(gettext "Send a new bug report.") 1.72 + 1.73 +Examples: 1.74 + $(basename $0) signup --name="Real Name" --user=login \\ 1.75 + --mail=mail@domain --pass=password 1.76 + $(basename $0) new-msg --bug=0 --msg="Message for bug with ID 0" 1.77 + 1.78 +EOT 1.79 +} 1.80 + 1.81 +# Check cmdline user info args 1.82 +check_info_args() { 1.83 + [ ! "$name" ] && gettext "Missing real name" && echo && exit 0 1.84 + [ ! "$user" ] && gettext "Missing login name" && echo && exit 0 1.85 + [ ! "$mail" ] && gettext "Missing email" && echo && exit 0 1.86 + [ ! "$pass" ] && gettext "Missing password" && echo && exit 0 1.87 +} 1.88 + 1.89 +# Crypt pass when login 1.90 +crypt_pass() { 1.91 + echo -n "$1" | md5sum | awk '{print $1}' 1.92 +} 1.93 + 1.94 +# Gen a config file 1.95 +gen_config() { 1.96 + gettext "Creating SliTaz account configuration..."; echo 1.97 + mkdir -p $HOME/.config/slitaz 1.98 + cat > $conf << EOT 1.99 +# SliTaz account configuration 1.100 + 1.101 +NAME="$name" 1.102 +USER="$user" 1.103 +MAIL="$mail" 1.104 +KEY="" 1.105 +EOT 1.106 + chmod 0600 $conf 1.107 +} 1.108 + 1.109 +# Gen the secure key: gen_key login mail passwd 1.110 +gen_key() { 1.111 + gettext "Creating SliTaz secure key..."; echo 1.112 + pass=$(crypt_pass $pass) 1.113 + key=$(echo -n "$user:$mail:$pass" | md5sum | awk '{print $1}') 1.114 + sed -i s"/KEY=.*/KEY=\"$key\"/" $conf 1.115 + chmod 0600 $conf 1.116 +} 1.117 + 1.118 +# 1.119 +# Commands 1.120 +# 1.121 + 1.122 +case "$1" in 1.123 + gen-key) 1.124 + # MD5 key 1.125 + [ ! "$pass" ] && gettext "Missing password" && echo && exit 0 1.126 + . $conf || exit 1 1.127 + gen_key $USER $MAIL $pass ;; 1.128 + gen-config) 1.129 + # Recreate a config file if value have change sites must be updated 1.130 + check_info_args 1.131 + gen_config 1.132 + gen_key ;; 1.133 + signup) 1.134 + # Create an account on the server 1.135 + check_info_args 1.136 + echo "" 1.137 + echo "Sending account request for: $2 ($3)" 1.138 + # 'gen_key login mail passwd' localy but dont send it. It will be 1.139 + # generated on server from the user login, mail and cryted password 1.140 + # so it is not transmited in GET urls. 1.141 + gen_config 1.142 + gen_key 1.143 + . $conf 1.144 + name="$(echo $name | http_urlencode)" 1.145 + pass=$(crypt_pass $pass) 1.146 + echo "Secure key: $KEY" 1.147 + busybox wget "${WEB_URL}?signup=$user&name=$name&mail=$mail&pass=$pass" \ 1.148 + -O /tmp/bug.msg 1.149 + cat /tmp/bug.msg && rm -f /tmp/bug.msg && echo "" ;; 1.150 + new-msg) 1.151 + # Post a new message: ID message 1.152 + . $conf || exit 1 1.153 + [ ! "$bug" ] && gettext "Missing bug ID" && echo && exit 0 1.154 + [ ! "$msg" ] && gettext "Missing message" && echo && exit 0 1.155 + msg="$(echo $msg | http_urlencode)" 1.156 + # Wget GET url 1.157 + busybox wget \ 1.158 + "${WEB_URL}?key=$KEY&bug=$bug&msg=$msg" -O /tmp/bug.msg 1.159 + cat /tmp/bug.msg && rm -f /tmp/bug.msg && echo "" ;; 1.160 + new-bug) 1.161 + # Post a new bug: bug desc priority pkgs 1.162 + . $conf || exit 1 1.163 + [ ! "$bug" ] && gettext "Missing bug title" && echo && exit 0 1.164 + [ ! "$desc" ] && gettext "Missing description" && echo && exit 0 1.165 + [ ! "$priority" ] && gettext "Missing bug priority" && echo && exit 0 1.166 + bug="$(echo $bug | http_urlencode)" 1.167 + desc="$(echo $desc | http_urlencode)" 1.168 + # Wget GET url 1.169 + busybox wget \ 1.170 + "${WEB_URL}?key=$KEY&bug=$bug&desc=$desc&priority=$priority&pkgs=$pkgs" \ 1.171 + -O /tmp/bug.msg 1.172 + cat /tmp/bug.msg && rm -f /tmp/bug.msg && echo "" ;; 1.173 + *) 1.174 + usage ;; 1.175 +esac 1.176 + 1.177 +exit 0