mjru.bash 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. mjdev.intr()
  2. {
  3. sshpass -p"$(pass show majordomo/public/mjdev.intr/root)" ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@mjdev.intr "$@"
  4. }
  5. mjru-backup()
  6. {
  7. case "$1" in
  8. list)
  9. if [ -z "$2" ]; then
  10. echo "provide unix_account_name"
  11. echo "example: backup_list u168138"
  12. (exit 1)
  13. else curl -s bareos.intr/_snapshot/slice/"$(echo -n "$2" | sha1sum | cut -c -2)/$2 | jq -r '.[] | [.dataUri.rsync, .time] | @tsv'"
  14. fi
  15. ;;
  16. mount)
  17. if [ -z "$2" ]; then
  18. echo "provide unix_account_name"
  19. echo "example: backup_mount u168138"
  20. (exit 1)
  21. else curl -s -XPOST "bareos.intr/_mount/slice/$(echo -n "$2" | sha1sum | cut -c -2)/$2?wait=True&timeout=600" | jq -r
  22. fi
  23. ;;
  24. umount)
  25. if [ -z "$2" ]; then
  26. echo "provide unix_account_name"
  27. echo "example: backup_umount u168138"
  28. (exit 1)
  29. else curl -s -XDELETE "bareos.intr/_mount/slice/$(echo -n "$2" | sha1sum | cut -c -2)/$2" | jq -r
  30. fi
  31. ;;
  32. esac
  33. }
  34. mjru-influx()
  35. {
  36. case "$1" in
  37. list)
  38. curl -G "http://influx.intr:8086/query?pretty=true" --data-urlencode "q=show databases" | jq
  39. ;;
  40. series)
  41. curl -G "http://influx.intr:8086/query?db=telegraf&pretty=true" --data-urlencode "q=SHOW SERIES"
  42. ;;
  43. esac
  44. }
  45. mjru-sshuttle()
  46. {
  47. sshuttle -r majordomo 10.0.0.0/8 172.16.0.0/16
  48. }
  49. mjru-vnc()
  50. {
  51. vncviewer "kvm$1":$(( $2 + 5900 ))
  52. }
  53. mjru-galera-df-home()
  54. {
  55. for n in 1 2 3; do
  56. echo -e "\n@ galera$n.intr"
  57. ssh "galera$n.intr" -- df -h /home
  58. done
  59. }
  60. router4.intr()
  61. {
  62. sshpass -p"$(pass show majordomo/public/router4/root)" ssh router4.intr "$@"
  63. }
  64. router.majordomo.ru()
  65. {
  66. ssh -t work
  67. # sshpass -p$(pass show majordomo/public/majordomo/router.majordomo.ru) ssh -vvv -oKexAlgorithms=+diffie-hellman-group1-sha1 -oHostKeyAlgorithms=+ssh-dss -p 1022 -l root -i ~/.ssh/id_rsa_majordomo_eng router.majordomo.ru
  68. }
  69. br1-mr14.intr-ftp-list()
  70. {
  71. curl "ftp://netcfg:$(pass show majordomo/public/172.16.103.111/netcfg)@172.16.103.111/junos/"
  72. }
  73. br1-mr14.intr-ftp()
  74. {
  75. # Example “config”: br1-mr14.intr_juniper.conf.gz_20190702_170649
  76. config="$1"
  77. wget -O- "ftp://netcfg:$(pass show majordomo/public/172.16.103.111/netcfg)@bareos.intr/junos/$config" | zcat
  78. }
  79. mjru-juneos-config()
  80. {
  81. sshpass -p"$(pass show majordomo/public/majordomo/ssh/router)" ssh -l root "$1" -- 'cli -c "show config | display xml"'
  82. }
  83. mjru-br1-mr14.intr-xq-br()
  84. {
  85. ssh -l root br1-mr14.intr -- 'cli -c "show interfaces | display xml"' \
  86. | xq -y '."rpc-reply"."interface-information"."physical-interface"[] | ."logical-interface" | select(. != null)'
  87. }
  88. mjru-backup-mount()
  89. {
  90. sudo -u majordomo-ssh-tunnel restic -r /srv/backup/majordomo mount /mnt/backup
  91. }
  92. mjru-nix-repl()
  93. {
  94. echo "overlay = lib.listToAttrs (map (drv: lib.nameValuePair drv.name drv) (import ./build.nix))"
  95. }
  96. mjru-nix-fix()
  97. {
  98. while IFS= read -r -d '' file
  99. do
  100. echo -e "\n@ $file"
  101. sed -i 's|https://gitlab.intr/pyhalov/php52-extra.git|file:///home/oleg/src/gitlab.intr/pyhalov/php52-extra|g' "$file"
  102. sed -i 's|git@gitlab.intr:shared/http_errors.git|/home/oleg/src/gitlab.intr/shared/http_errors|g' "$file"
  103. sed -i 's|git@gitlab.intr:|file:///home/oleg/src/gitlab.intr/|g' "$file"
  104. sed -i 's|https://gitlab.intr/|file:///home/oleg/src/gitlab.intr/|g' "$file"
  105. done < <(find ~/src/gitlab.intr/_ci/nixpkgs* -type f -name '*.nix' -print0)
  106. while IFS= read -r -d '' file
  107. do
  108. echo -e "\n@ $file"
  109. sed -i 's|(builtins.fetchGit { url = "git@gitlab.intr:_ci/nixpkgs.git"; ref = ".*"; })|/home/oleg/src/gitlab.intr/_ci/nixpkgs|g' "$file"
  110. sed -i 's|(builtins.fetchGit { url = "git@gitlab.intr:_ci/nixpkgs.git"; inherit ref; })|/home/oleg/src/gitlab.intr/_ci/nixpkgs|g' "$file"
  111. done < <(find . -type f -name '*.nix' -print0)
  112. }
  113. mjru-jenkins-build-php()
  114. {
  115. jobs=(
  116. apache2-php44
  117. apache2-php52
  118. apache2-php53
  119. apache2-php54
  120. apache2-php55
  121. apache2-php56
  122. apache2-php70
  123. apache2-php71
  124. apache2-php72
  125. apache2-php73
  126. apache2-php74
  127. apache2-php80
  128. apache2-php81
  129. )
  130. branch="$1"
  131. for job in "${jobs[@]}"; do
  132. echo -e "\n@ $job"
  133. curl --user "admin:$(pass show majordomo/public/majordomo/jenkins.intr/admin)" \
  134. --insecure \
  135. --request POST \
  136. "https://jenkins.intr/job/webservices/job/webservices%252F${job}/job/master/build?delay=0sec" \
  137. --header 'Content-type: application/x-www-form-urlencoded; charset=UTF-8' \
  138. --data-raw ''
  139. sleep 0.5
  140. done
  141. }
  142. mjru-wp-cron()
  143. {
  144. nice -n 19 ionice -c2 -n7 find /home/u12345 -type f -name wp-cron.php | xargs -n1 dirname | xargs -n1 -I{} sh -c "echo -n '{} ';grep -rl {} /etc/nginx/sites-available | xargs awk -F'-' '\$1~/proxy_pass/ {print \$2}' | uniq" | awk '{print "* * * * * /opt/"$NF"/bin/php",$(NF-1)"/wp-cron.php"}'
  145. }
  146. # TODO:
  147. # majordomo-ansible-galera()
  148. # {
  149. # ansible "galera$1.intr" -m copy -a "src=galera$1/mariadb-bin.0029$2 dest=/home/mariadb/mariadb-bin.0029$2" --become && ansible "galera$1.intr" -m file -a "path=/home/mariadb/mariadb-bin.0029$2 owner=mysql group=mysql" --become
  150. # }
  151. mjru-ansible-auth-hosts()
  152. {
  153. for host in $(ansible all --list-hosts |grep intr); do
  154. printf "%s%s\n" "$host" "$(ssh -oStrictHostKeyChecking=no "$host" -- uptime)"
  155. done
  156. }
  157. mjru-web-active-current()
  158. {
  159. curl -H "PRIVATE-TOKEN: $(pass show majordomo/public/gitlab.intr/tokens/terraform)" -s -k -L \
  160. 'https://gitlab.intr/hms/config-repo/raw/master/rc-staff-prod.yml'
  161. }
  162. mjru-gitlab-version()
  163. {
  164. curl --header "PRIVATE-TOKEN: $(pass show majordomo/public/gitlab.intr/tokens/terraform)" \
  165. --silent --insecure --location https://gitlab.intr/api/v4/version
  166. echo
  167. }
  168. mjru-skopeo-mj()
  169. {
  170. group="$1"
  171. image="$2" # ssh-guest-room
  172. tag="$3"
  173. tar="$4" || result # docker-archive:/nix/store/dw0qakl4g58n9idsi35vn0m1d92gs0jw-docker-image-ssh-guest-room.tar.gz
  174. skopeo copy --dest-creds=gradle:"$(pass show majordomo/public/nexus/gradle)" --dest-tls-verify=false "docker-archive:$tar" "docker://docker-registry.intr/$group/$image:$tag"
  175. }
  176. mjru-skopeo-fetch()
  177. {
  178. image="$1"
  179. dest="$2"
  180. skopeo copy --dest-creds=gradle:"$(pass show majordomo/public/nexus/gradle)" --src-tls-verify=false --dest-tls-verify=false "docker://docker-registry.intr/$image" "docker-archive:$dest"
  181. }
  182. # dockerd --insecure-registry https://docker-registry.intr
  183. mjru-nix-ls-store-kvm15()
  184. {
  185. # $1 example: /nix/store/0i2jd68mp5g6h2sa5k9c85rb80sn8hi9-hello-2.10
  186. nix ls-store --store http://kvm15.intr:5556/ -lR "$1"
  187. }
  188. mjru-nix-build-kvm15()
  189. {
  190. pkg="$1"
  191. nix-build build.nix --option substituters http://kvm15.intr:5556/ --cores 4 -A nixpkgsUnstable"$pkg" --keep-going --keep-failed "$@"
  192. }
  193. mjru-nix-build-mj()
  194. {
  195. nix-build \
  196. --option trusted-public-keys 'cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= cache.nixos.intr:6VD7bofl5zZFTEwsIDsUypprsgl7r9I+7OGY4WsubFA=' \
  197. --substituters 'https://cache.nixos.org/ https://cache.nixos.intr/' \
  198. --expr "(import <nixpkgs> {overlays = [(import $HOME/src/gitlab.intr/_ci/nixpkgs)];}).$1"
  199. }
  200. mjru-docker-jenkins()
  201. {
  202. docker -H ssh://dh4-mr.intr exec -it 4649529fa34d "$@"
  203. }
  204. mjru-hms-current-stack()
  205. {
  206. nginx1="$(curl --silent -u "jenkins:$(pass show majordomo/private/jenkins/jenkins)" -X GET http://nginx1.intr:8080/hms)"
  207. nginx2="$(curl --silent -u "jenkins:$(pass show majordomo/private/jenkins/jenkins)" -X GET http://nginx2.intr:8080/hms)"
  208. nginx1_active="$(echo "$nginx1" | jq --raw-output .active)"
  209. nginx2_active="$(echo "$nginx2" | jq --raw-output .active)"
  210. if [[ $nginx1_active == $nginx2_active ]]
  211. then
  212. echo "Current stack: ${nginx1_active}"
  213. if [[ $nginx1_active == "hms1" ]]
  214. then
  215. target="hms2"
  216. else
  217. target="hms1"
  218. fi
  219. cat <<EOF
  220. Switch stack example:
  221. curl -H "Content-Type: application/json" --data '{"available":["hms2","hms1"],"setActive":"$target"}' -u "jenkins:$(pass show majordomo/private/jenkins/jenkins)" -X POST "http://nginx1.intr:8080/hms"
  222. curl -H "Content-Type: application/json" --data '{"available":["hms2","hms1"],"setActive":"$target"}' -u "jenkins:$(pass show majordomo/private/jenkins/jenkins)" -X POST "http://nginx2.intr:8080/hms"
  223. EOF
  224. else
  225. echo "WARNING: Stacks mismatches"
  226. cat <<EOF
  227. Switch stack example:
  228. curl -H "Content-Type: application/json" --data '{"available":["hms2","hms1"],"setActive":"hms1"}' -u "jenkins:$(pass show majordomo/private/jenkins/jenkins)" -X POST "http://nginx1.intr:8080/hms"
  229. curl -H "Content-Type: application/json" --data '{"available":["hms2","hms1"],"setActive":"hms1"}' -u "jenkins:$(pass show majordomo/private/jenkins/jenkins)" -X POST "http://nginx2.intr:8080/hms"
  230. EOF
  231. fi
  232. }
  233. mjru-hms-auth ()
  234. {
  235. curl --silent \
  236. --request POST https://api.majordomo.ru/oauth/token \
  237. --header 'content-type: application/x-www-form-urlencoded' \
  238. --header 'x-requested-with: XMLHttpRequest' \
  239. -d "grant_type=password&username=$IHS_USER&password=$IHS_PASS&client_id=service&client_secret=service_secret" \
  240. | jq -r '.access_token'
  241. }
  242. mjru-es-xmlrpc()
  243. {
  244. curl -H 'Content-Type: application/json' \
  245. -X POST "http://es.intr:9200/nginx-$(date +"%Y.%m.%d")/_search/" \
  246. --data-binary '{"from":0,"query":{"query_string":{"query":"path.keyword:\"/xmlrpc.php\""}},"size":50,"sort":[{"@timestamp":{"order":"desc"}}]}'
  247. }
  248. mjru-docker-list-intr()
  249. {
  250. curl -s -X GET -k -u "gradle:$(pass show majordomo/public/nexus/gradle)" https://docker-registry.intr/v2/_catalog \
  251. | jq -r '.repositories[]'
  252. }
  253. mjru-jenkins-log()
  254. {
  255. for project in $(curl -s -k "https://admin:$(pass show majordomo/public/jenkins.intr/admin)@jenkins.intr/api/json?pretty=true" | jq -r '.jobs[] | .name'); do
  256. mkdir -p "$project"
  257. cd "$project" || return
  258. for job in $(curl -s -k "https://admin:$(pass show majordomo/public/jenkins.intr/admin)@jenkins.intr/job/$project/api/json" | jq -r '.jobs[] | .url'); do
  259. job_name="$(echo "$job" | rev | cut -d/ -f 2 | rev)"
  260. echo "@ $job"
  261. curl -u "admin:$(pass show majordomo/public/jenkins.intr/admin)" -s -k "$job/job/master/lastBuild/consoleText" > "$job_name.log"
  262. done
  263. cd - || return
  264. done
  265. }
  266. mjru-ansible-swarm-ps-inspect()
  267. {
  268. # shellcheck disable=SC2016
  269. ansible swarm -m shell -a 'for c in $(docker ps | grep -v CONTAINER | cut -d " " -f 1 | xargs echo); do docker inspect $c; done' --become
  270. }
  271. mjru-ansible-swarm-network-inspect()
  272. {
  273. ansible swarm -m shell -a 'docker network ls | cut -d " " -f 1 | grep -v NETWORK | xargs docker network inspect' --become
  274. }
  275. mjru-dns-check()
  276. {
  277. for dns in 172.16.103.2 172.16.100.3; do
  278. (echo $dns; time dig +short a "${1:-cerberus.intr}" @$dns) |& xargs echo
  279. done
  280. }
  281. mjru-jenkins()
  282. {
  283. JENKINS_URL=https://jenkins.intr \
  284. JENKINS_USER=admin \
  285. JENKINS_PASSWORD="$(pass show majordomo/public/jenkins.intr/admin)" \
  286. jenkins "$@"
  287. }
  288. mjru-vm-vnc()
  289. {
  290. (
  291. set -ex
  292. host="$1"
  293. vm="$2"
  294. vncviewer "$host":"$(connect ssh "$host" virsh dumpxml "$vm" | xq -r '.domain.devices.graphics["@port"]')" &
  295. password="$(ihs vm passwords "$vm" | awk '{ print $NF }')"
  296. sleep 1
  297. echo "(window-send-string (format nil \"~a~%\" \"$password\"))" | stumpish -e eval
  298. sleep 2
  299. echo "(window-send-string (format nil \"~a~%\" \"root\"))" | stumpish -e eval
  300. sleep 0.5
  301. echo "(window-send-string (format nil \"~a~%\" \"$password\"))" | stumpish -e eval
  302. )
  303. }
  304. mjru-proxy()
  305. {
  306. ssh -Nf -D 5557 workstation.intr
  307. }
  308. mjru-vlan()
  309. {
  310. echo "PXE is on VLAN 254"
  311. echo "chef-server '/usr/sbin/in.tftpd -L -a 192.168.254.1 -s /var/tftpboot'"
  312. }
  313. mjru-python()
  314. {
  315. echo "Setting HMS_MONGO_PASSWORD environment variable."
  316. HMS_MONGO_PASSWORD="$(pass show majordomo/public/mongo/hms/admin)" python3
  317. }
  318. mjru-network()
  319. {
  320. awk '/A\t/ || /A / { print "(\"", $NF, "/32\" . ,(string-to-symbols \"", $1, ".intr\"))" }' \
  321. ~/src/gitlab.intr/net/dns-intr/intr-miran.zone ~/src/gitlab.intr/net/dns-intr/intr-datahouse.zone \
  322. | sed 's/" /"/g; s@ /@/@g; s/ ")/")/g; s/"\./" ./; s/ \.intr/.intr/; s/\"\;/"/'
  323. awk '/A\t/ || /A / { print "(\"inet" , $NF, "/24\" . ,(string-to-symbols \"", $1, ".intr\"))" }' \
  324. ~/src/gitlab.intr/net/dns-intr/intr-miran.zone ~/src/gitlab.intr/net/dns-intr/intr-datahouse.zone \
  325. | sed 's/" /"/g; s@ /@/@g; s/ ")/")/g; s/"\./" ./; s/ \.intr/.intr/; s/\"\;/"/'
  326. awk '/A\t/ || /A / { print "(\"", $NF, "\" . ,(string-to-symbols \"", $1, ".intr\"))" }' \
  327. ~/src/gitlab.intr/net/dns-intr/intr-miran.zone ~/src/gitlab.intr/net/dns-intr/intr-datahouse.zone \
  328. | sed 's/" /"/g; s@ /@/@g; s/ ")/")/g; s/ "\./" ./; s/ \.intr/.intr/; s/\"\;/"/'
  329. }
  330. vault1()
  331. {
  332. VAULT_TOKEN="$(pass show majordomo/public/vault/root)" VAULT_ADDR=http://dh1-mr.intr:8210 "${HOME}/.nix-profile/bin/vault" "$@"
  333. }
  334. vault2()
  335. {
  336. VAULT_TOKEN="$(pass show majordomo/public/vault/root)" VAULT_ADDR=http://dh2-mr.intr:8220 "${HOME}/.nix-profile/bin/vault" "$@"
  337. }
  338. vault3()
  339. {
  340. VAULT_TOKEN="$(pass show majordomo/public/vault/root)" VAULT_ADDR=http://dh3-mr.intr:8230 "${HOME}/.nix-profile/bin/vault" "$@"
  341. }
  342. vault4()
  343. {
  344. VAULT_TOKEN="$(pass show majordomo/public/vault-unseal/root)" VAULT_ADDR=http://dh4-mr.intr:8240 "${HOME}/.nix-profile/bin/vault" "$@"
  345. }
  346. vault-ci()
  347. {
  348. VAULT_TOKEN="$(pass show majordomo/public/vault-dev/root)" VAULT_ADDR=http://ci.intr:8210 "${HOME}/.nix-profile/bin/vault" "$@"
  349. }
  350. mjru-gitlab()
  351. {
  352. GITLAB_HOST=https://gitlab.intr \
  353. GITLAB_TOKEN="$(pass show majordomo/private/gitlab.intr/tokens/pyhalov)" \
  354. command glab "$@"
  355. }
  356. if [ -f "${HOME}/.nix-profile/bin/glab" ]
  357. then
  358. if [[ $(type -t compopt) = "builtin" ]]; then
  359. complete -o default -F __start_glab mjru-gitlab
  360. else
  361. complete -o default -o nospace -F __start_glab mjru-gitlab
  362. fi
  363. fi
  364. mjru-curl()
  365. {
  366. curl --header "Authorization: Bearer $(mjru-auth)" \
  367. --header 'Content-Type: application/json' \
  368. "$@"
  369. }
  370. mongo()
  371. {
  372. case "$1" in
  373. cluster1)
  374. command mongo "mongodb://admin:$(pass show majordomo/public/mongo/ci.intr/admin)@mongodb.hms.development.corp1.majordomo.ru:27017/admin" \
  375. "${@:2}"
  376. ;;
  377. ci)
  378. command mongo "mongodb://admin:$(pass show majordomo/public/mongo/ci.intr/admin)@ci.intr:27017/admin" \
  379. "${@:2}"
  380. ;;
  381. production)
  382. command mongo "mongodb://admin:$(pass show majordomo/public/mongo/ci.intr/admin)@hms01-mr.intr:27017,hms02-mr.intr:27017,hms03-mr.intr:27017/admin?replicaSet=hms-rs0" \
  383. "${@:2}"
  384. ;;
  385. *)
  386. command mongo "$@"
  387. esac
  388. }
  389. mongodump()
  390. {
  391. case "$1" in
  392. cluster1)
  393. command mongodump \
  394. --authenticationDatabase=admin \
  395. --username=admin \
  396. --password="$(pass show majordomo/public/mongo/ci.intr/admin)" \
  397. --uri="mongodb://mongodb.hms.development.corp1.majordomo.ru:27017/" \
  398. "${@:2}"
  399. ;;
  400. ci)
  401. command mongodump \
  402. --authenticationDatabase=admin \
  403. --username=admin \
  404. --password="$(pass show majordomo/public/mongo/ci.intr/admin)" \
  405. --uri="mongodb://ci.intr:27017/" \
  406. "${@:2}"
  407. ;;
  408. production)
  409. command mongodump \
  410. --authenticationDatabase=admin \
  411. --username=admin \
  412. --password="$(pass show majordomo/public/mongo/ci.intr/admin)" \
  413. --uri="mongodb://hms01-mr.intr:27017,hms02-mr.intr:27017,hms03-mr.intr:27017/?replicaSet=hms-rs0" \
  414. "${@:2}"
  415. ;;
  416. *)
  417. command mongodump "$@"
  418. esac
  419. }
  420. mongorestore()
  421. {
  422. case "$1" in
  423. cluster1)
  424. command mongorestore \
  425. --authenticationDatabase=admin \
  426. --username=admin \
  427. --password="$(pass show majordomo/public/mongo/ci.intr/admin)" \
  428. --uri="mongodb://mongodb.hms.development.corp1.majordomo.ru:27017/" \
  429. "${@:2}"
  430. ;;
  431. ci)
  432. command mongorestore \
  433. --authenticationDatabase=admin \
  434. --username=admin \
  435. --password="$(pass show majordomo/public/mongo/ci.intr/admin)" \
  436. --uri="mongodb://ci.intr:27017/" \
  437. "${@:2}"
  438. ;;
  439. alerta)
  440. command mongorestore \
  441. --authenticationDatabase=admin \
  442. --username=root \
  443. --password="$(pass show majordomo/public/alerta/mongodb/root)" \
  444. --uri="mongodb://localhost:27017/" \
  445. "${@:2}"
  446. ;;
  447. production)
  448. command mongorestore \
  449. --authenticationDatabase=admin \
  450. --username=admin \
  451. --password="$(pass show majordomo/public/mongo/ci.intr/admin)" \
  452. --uri="mongodb://hms01-mr.intr:27017,hms02-mr.intr:27017,hms03-mr.intr:27017/?replicaSet=hms-rs0" \
  453. "${@:2}"
  454. ;;
  455. *)
  456. command mongorestore "$@"
  457. esac
  458. }
  459. mongoexport()
  460. {
  461. case "$1" in
  462. cluster1)
  463. command mongoexport \
  464. --authenticationDatabase=admin \
  465. --username=admin \
  466. --password="$(pass show majordomo/public/mongo/ci.intr/admin)" \
  467. --uri="mongodb://mongodb.hms.development.corp1.majordomo.ru:27017/" \
  468. "${@:2}"
  469. ;;
  470. ci)
  471. command mongoexport \
  472. --authenticationDatabase=admin \
  473. --username=admin \
  474. --password="$(pass show majordomo/public/mongo/ci.intr/admin)" \
  475. --uri="mongodb://ci.intr:27017/" \
  476. "${@:2}"
  477. ;;
  478. production)
  479. command mongoexport --authenticationDatabase=admin \
  480. --username=admin \
  481. --password="$(pass show majordomo/public/mongo/ci.intr/admin)" \
  482. --uri="mongodb://hms01-mr.intr:27017,hms02-mr.intr:27017,hms03-mr.intr:27017/?replicaSet=hms-rs0" \
  483. "${@:2}"
  484. ;;
  485. *)
  486. command mongoexport "$@"
  487. esac
  488. }
  489. mongoimport()
  490. {
  491. case "$1" in
  492. cluster1)
  493. command mongoimport \
  494. --authenticationDatabase=admin \
  495. --username=admin \
  496. --password="$(pass show majordomo/public/mongo/ci.intr/admin)" \
  497. --uri="mongodb://mongodb.hms.development.corp1.majordomo.ru:27017/" \
  498. "${@:2}"
  499. ;;
  500. ci)
  501. command mongoimport \
  502. --authenticationDatabase=admin \
  503. --username=admin \
  504. --password="$(pass show majordomo/public/mongo/ci.intr/admin)" \
  505. --uri="mongodb://ci.intr:27017/" \
  506. "${@:2}"
  507. ;;
  508. production)
  509. command mongoimport --authenticationDatabase=admin \
  510. --username=admin \
  511. --password="$(pass show majordomo/public/mongo/ci.intr/admin)" \
  512. --uri="mongodb://hms01-mr.intr:27017,hms02-mr.intr:27017,hms03-mr.intr:27017/?replicaSet=hms-rs0" \
  513. "${@:2}"
  514. ;;
  515. *)
  516. command mongoimport "$@"
  517. esac
  518. }