-
Notifications
You must be signed in to change notification settings - Fork 3
/
configure
executable file
·111 lines (92 loc) · 2.72 KB
/
configure
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env bash
set -ue
# Defaults
################################################################################
config_file=$XDG_CONFIG_HOME/mirror-elpa.sh
show_help=
# Read arguments
################################################################################
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
"-h"|--help)
show_help=stdin
shift # past argument
;;
--config-file)
config_file=$2
shift # past argument
shift # past value
;;
*) # unknown option
>&2 echo "Unrecognised argument: $1"
show_help=stderr
shift # past argument
break
;;
esac
done
# Display help if necessary
################################################################################
help() {
echo "Usage: $(basename "$0") [options]"
echo " -h, --help print this message and exit"
echo " --config-file PATH read and write to configurations at PATH"
echo
echo "Report bugs at https://gitlab.com/d12frosted/mirror-elpa/issues"
exit
}
[ "$show_help" = "stdin" ] && help
[ "$show_help" = "stderr" ] && >&2 help
# Ask
################################################################################
ask() {
local def
local res
def="${!1}"
res=
while :; do
printf "%s: " "$2"
[ -n "$def" ] && printf "(%s) " "$def"
read -r res
[ -z "$res" ] && res="$def"
[ -n "$res" ] && break
done
readonly "$1=$res"
}
# Declare used variables
################################################################################
mirror_host="gitlab.com"
mirror_owner=
mirror_repo=
access_login=
access_token=
commit_name=
commit_email=
# Load existing configuration
################################################################################
[ -f "$config_file" ] && source "$config_file"
# Fill variables
################################################################################
ask "mirror_host" "Mirror repository host"
ask "mirror_owner" "Mirror repository owner"
ask "mirror_repo" "Mirror repository name"
access_login="$mirror_owner"
ask "access_login" "Mirror repository access login"
ask "access_token" "Mirror repository access token"
commit_name="$access_login"
ask "commit_name" "Committer name"
ask "commit_email" "Committer email"
# Write out everything we have
################################################################################
{
printf "mirror_host=%q\n" "$mirror_host"
printf "mirror_owner=%q\n" "$mirror_owner"
printf "mirror_repo=%q\n" "$mirror_repo"
printf "access_login=%q\n" "$access_login"
printf "access_token=%q\n" "$access_token"
printf "commit_name=%q\n" "$commit_name"
printf "commit_email=%q\n" "$commit_email"
} > "$config_file"
echo "Successfully wrote configuration to $config_file"