File tree Expand file tree Collapse file tree 3 files changed +275
-0
lines changed Expand file tree Collapse file tree 3 files changed +275
-0
lines changed Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+ set -e
3+
4+ #
5+ # manage osm-teams organization managers via psql.
6+ #
7+
8+ show_help () {
9+ cat << __HELP__
10+ managers.sh
11+
12+ add or remove managers from osm-teams
13+
14+ -o | --org-id : organization id to operate on
15+ -u | --user-id : osm/mapedit user id to add/remove
16+ -r | --remove : remove the user from managers list
17+
18+ example:
19+
20+ ./managers.sh --user-id 0912311 --org-id 1
21+ ./managers.sh --remove --user-id 0912311 --org-id 1
22+
23+ __HELP__
24+ }
25+
26+ die () {
27+ printf ' %s\n' " $1 " >&2
28+ exit 1
29+ }
30+
31+
32+ if [ -z " $DSN " ]; then
33+ die " error: DSN for postgreql database is missing"
34+ fi
35+
36+ uid=
37+ oid=
38+ remove=
39+
40+ while : ; do
41+ case $1 in
42+ -h|-\? |--help)
43+ show_help
44+ exit
45+ ;;
46+ -u|--user-id)
47+ if [ " $2 " ]; then
48+ uid=$2
49+ shift
50+ else
51+ die ' error: "--user-id" requires a non-empty option argument.'
52+ fi
53+ ;;
54+ -o|--org-id)
55+ if [ " $2 " ]; then
56+ oid=$2
57+ shift
58+ else
59+ die ' error: "--org-id" requires a non-empty option argument.'
60+ fi
61+ ;;
62+ -r|--remove)
63+ remove=1
64+ ;;
65+ --)
66+ shift
67+ break
68+ ;;
69+ -?* )
70+ printf ' warn: Unknown option (ignored): %s\n' " $1 " >&2
71+ ;;
72+ * ) # Default case: No more options, so break out of the loop.
73+ break
74+ esac
75+ shift
76+ done
77+
78+ if [ -z " $uid " ]; then
79+ die " missing --user-id of osm/mapedit user to add/remove"
80+ fi
81+
82+ if [ -z " $oid " ]; then
83+ die " missing --org-id of organization to modify"
84+ fi
85+
86+ if [ -z " $remove " ]; then
87+ psql $DSN --command " insert into organization_manager (organization_id, osm_id) values ($oid , $uid )"
88+ else
89+ psql $DSN --command " delete from organization_manager where organization_id = $oid and osm_id = $uid "
90+ fi
91+
92+ psql $DSN --command " select * from organization_manager"
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+ set -e
3+
4+ #
5+ # manage osm-teams organizations via psql.
6+ #
7+
8+ show_help () {
9+ cat << __HELP__
10+ organizations.sh
11+
12+ add or remove organizations from osm-teams
13+
14+ -n | --name : organization name to add/remove
15+ -d | --description : organization description to add (optional)
16+ -r | --remove : remove the organization (requires --name)
17+
18+ example:
19+
20+ ./organizations.sh --name "my org" --description "foo"
21+ ./organizations.sh --remove --name "my org"
22+
23+ __HELP__
24+ }
25+
26+ die () {
27+ printf ' %s\n' " $1 " >&2
28+ exit 1
29+ }
30+
31+
32+ if [ -z " $DSN " ]; then
33+ die " error: DSN for postgreql database is missing"
34+ fi
35+
36+ name=
37+ description=
38+ remove=
39+
40+ while : ; do
41+ case $1 in
42+ -h|-\? |--help)
43+ show_help
44+ exit
45+ ;;
46+ -n|--name)
47+ if [ " $2 " ]; then
48+ name=$2
49+ shift
50+ else
51+ die ' error: "--name" requires a non-empty option argument.'
52+ fi
53+ ;;
54+
55+ -d|--description)
56+ if [ " $2 " ]; then
57+ description=$2
58+ shift
59+ else
60+ die ' error: "--description" requires a non-empty option argument.'
61+ fi
62+ ;;
63+ -r|--remove)
64+ remove=1
65+ ;;
66+ --)
67+ shift
68+ break
69+ ;;
70+ -?* )
71+ printf ' warn: Unknown option (ignored): %s\n' " $1 " >&2
72+ ;;
73+ * ) # Default case: No more options, so break out of the loop.
74+ break
75+ esac
76+ shift
77+ done
78+
79+ if [ -z " $name " ]; then
80+ die " missing --name of organization to add/remove"
81+ fi
82+
83+ if [ -z " $remove " ]; then
84+ org_id=` psql $DSN -t --command " insert into organization (name, description) values ('$name ', '$description ') returning id" `
85+ echo " created organization id: ${org_id} "
86+ echo
87+ else
88+ psql $DSN --command " delete from organization where name = '$name '"
89+ fi
90+
91+ psql $DSN --command " select * from organization"
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+ set -e
3+
4+ #
5+ # manage osm-teams organization owners via psql queries
6+ #
7+
8+ show_help () {
9+ cat << __HELP__
10+ owners.sh
11+
12+ add or remove owners from osm-teams
13+
14+ -o | --org-id : organization id to operate on
15+ -u | --user-id : osm/mapedit user id to add/remove
16+ -r | --remove : remove the user from owners list
17+
18+ example:
19+
20+ ./owners.sh --user-id 0912311 --org-id 1
21+ ./owners.sh --remove --user-id 0912311 --org-id 1
22+
23+ __HELP__
24+ }
25+
26+ die () {
27+ printf ' %s\n' " $1 " >&2
28+ exit 1
29+ }
30+
31+
32+ if [ -z " $DSN " ]; then
33+ die " error: DSN for postgreql database is missing"
34+ fi
35+
36+ uid=
37+ oid=
38+ remove=
39+
40+ while : ; do
41+ case $1 in
42+ -h|-\? |--help)
43+ show_help
44+ exit
45+ ;;
46+ -u|--user-id)
47+ if [ " $2 " ]; then
48+ uid=$2
49+ shift
50+ else
51+ die ' error: "--user-id" requires a non-empty option argument.'
52+ fi
53+ ;;
54+ -o|--org-id)
55+ if [ " $2 " ]; then
56+ oid=$2
57+ shift
58+ else
59+ die ' error: "--org-id" requires a non-empty option argument.'
60+ fi
61+ ;;
62+ -r|--remove)
63+ remove=1
64+ ;;
65+ --)
66+ shift
67+ break
68+ ;;
69+ -?* )
70+ printf ' warn: Unknown option (ignored): %s\n' " $1 " >&2
71+ ;;
72+ * ) # Default case: No more options, so break out of the loop.
73+ break
74+ esac
75+ shift
76+ done
77+
78+ if [ -z " $uid " ]; then
79+ die " missing --user-id of osm/mapedit user to add/remove"
80+ fi
81+
82+ if [ -z " $oid " ]; then
83+ die " missing --org-id of organization to modify"
84+ fi
85+
86+ if [ -z " $remove " ]; then
87+ psql $DSN --command " insert into organization_owner (organization_id, osm_id) values ($oid , $uid )"
88+ else
89+ psql $DSN --command " delete from organization_owner where organization_id = $oid and osm_id = $uid "
90+ fi
91+
92+ psql $DSN --command " select * from organization_owner"
You can’t perform that action at this time.
0 commit comments