1#!/bin/sh
2
3# This is a convenience script for reporting issues that include a base
4# template of information. See https://github.com/docker/docker/pull/8845
5
6set -e
7
8DOCKER_ISSUE_URL=${DOCKER_ISSUE_URL:-"https://github.com/docker/docker/issues/new"}
9DOCKER_ISSUE_NAME_PREFIX=${DOCKER_ISSUE_NAME_PREFIX:-"Report: "}
10DOCKER=${DOCKER:-"docker"}
11DOCKER_COMMAND="${DOCKER}"
12export DOCKER_COMMAND
13
14# pulled from https://gist.github.com/cdown/1163649
15function urlencode() {
16	# urlencode <string>
17
18	local length="${#1}"
19	for ((i = 0; i < length; i++)); do
20		local c="${1:i:1}"
21		case $c in
22			[a-zA-Z0-9.~_-]) printf "$c" ;;
23			*) printf '%%%02X' "'$c" ;;
24		esac
25	done
26}
27
28function template() {
29	# this should always match the template from CONTRIBUTING.md
30	cat <<- EOM
31		Description of problem:
32
33
34		\`docker version\`:
35		$(${DOCKER_COMMAND} -D version)
36
37
38		\`docker info\`:
39		$(${DOCKER_COMMAND} -D info)
40
41
42		\`uname -a\`:
43		$(uname -a)
44
45
46		Environment details (AWS, VirtualBox, physical, etc.):
47
48
49		How reproducible:
50
51
52		Steps to Reproduce:
53		1.
54		2.
55		3.
56
57
58		Actual Results:
59
60
61		Expected Results:
62
63
64		Additional info:
65
66
67	EOM
68}
69
70function format_issue_url() {
71	if [ ${#@} -ne 2 ]; then
72		return 1
73	fi
74	local issue_name=$(urlencode "${DOCKER_ISSUE_NAME_PREFIX}${1}")
75	local issue_body=$(urlencode "${2}")
76	echo "${DOCKER_ISSUE_URL}?title=${issue_name}&body=${issue_body}"
77}
78
79echo -ne "Do you use \`sudo\` to call docker? [y|N]: "
80read -r -n 1 use_sudo
81echo ""
82
83if [ "x${use_sudo}" = "xy" -o "x${use_sudo}" = "xY" ]; then
84	export DOCKER_COMMAND="sudo ${DOCKER}"
85fi
86
87echo -ne "Title of new issue?: "
88read -r issue_title
89echo ""
90
91issue_url=$(format_issue_url "${issue_title}" "$(template)")
92
93if which xdg-open 2> /dev/null > /dev/null; then
94	echo -ne "Would like to launch this report in your browser? [Y|n]: "
95	read -r -n 1 launch_now
96	echo ""
97
98	if [ "${launch_now}" != "n" -a "${launch_now}" != "N" ]; then
99		xdg-open "${issue_url}"
100	fi
101fi
102
103echo "If you would like to manually open the url, you can open this link if your browser: ${issue_url}"
104