mjru.bash 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  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. apache2-php83
  130. )
  131. branch="$1"
  132. for job in "${jobs[@]}"; do
  133. echo -e "\n\n@ ${job}"
  134. /home/oleg/.guix-profile/bin/curl \
  135. --user "admin:$(pass show majordomo/public/majordomo/jenkins.intr/admin)" \
  136. --request POST \
  137. --header 'Content-type: application/x-www-form-urlencoded; charset=UTF-8' \
  138. -o /dev/null \
  139. -v \
  140. "https://jenkins.corp1.majordomo.ru/job/webservices/job/${job}/job/master/build?delay=0sec"
  141. sleep 0.5
  142. done
  143. }
  144. mjru-wp-cron()
  145. {
  146. 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"}'
  147. }
  148. # TODO:
  149. # majordomo-ansible-galera()
  150. # {
  151. # 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
  152. # }
  153. mjru-ansible-auth-hosts()
  154. {
  155. for host in $(ansible all --list-hosts |grep intr); do
  156. printf "%s%s\n" "$host" "$(ssh -oStrictHostKeyChecking=no "$host" -- uptime)"
  157. done
  158. }
  159. mjru-web-active-current()
  160. {
  161. curl -H "PRIVATE-TOKEN: $(pass show majordomo/public/gitlab.intr/tokens/terraform)" -s -k -L \
  162. 'https://gitlab.intr/hms/config-repo/raw/master/rc-staff-prod.yml'
  163. }
  164. mjru-gitlab-version()
  165. {
  166. curl --header "PRIVATE-TOKEN: $(pass show majordomo/public/gitlab.intr/tokens/terraform)" \
  167. --silent --insecure --location https://gitlab.intr/api/v4/version
  168. echo
  169. }
  170. mjru-skopeo-mj()
  171. {
  172. group="$1"
  173. image="$2" # ssh-guest-room
  174. tag="$3"
  175. tar="$4" || result # docker-archive:/nix/store/dw0qakl4g58n9idsi35vn0m1d92gs0jw-docker-image-ssh-guest-room.tar.gz
  176. 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"
  177. }
  178. mjru-skopeo-fetch()
  179. {
  180. image="$1"
  181. dest="$2"
  182. 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"
  183. }
  184. # dockerd --insecure-registry https://docker-registry.intr
  185. mjru-nix-ls-store-kvm15()
  186. {
  187. # $1 example: /nix/store/0i2jd68mp5g6h2sa5k9c85rb80sn8hi9-hello-2.10
  188. nix ls-store --store http://kvm15.intr:5556/ -lR "$1"
  189. }
  190. mjru-nix-build-kvm15()
  191. {
  192. pkg="$1"
  193. nix-build build.nix --option substituters http://kvm15.intr:5556/ --cores 4 -A nixpkgsUnstable"$pkg" --keep-going --keep-failed "$@"
  194. }
  195. mjru-nix-build-mj()
  196. {
  197. nix-build \
  198. --option trusted-public-keys 'cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= cache.nixos.intr:6VD7bofl5zZFTEwsIDsUypprsgl7r9I+7OGY4WsubFA=' \
  199. --substituters 'https://cache.nixos.org/ https://cache.nixos.intr/' \
  200. --expr "(import <nixpkgs> {overlays = [(import $HOME/src/gitlab.intr/_ci/nixpkgs)];}).$1"
  201. }
  202. mjru-docker-jenkins()
  203. {
  204. docker -H ssh://dh4-mr.intr exec -it 4649529fa34d "$@"
  205. }
  206. mjru-hms-current-stack()
  207. {
  208. nginx1="$(curl --silent -u "jenkins:$(pass show majordomo/private/jenkins/jenkins)" -X GET http://nginx1.intr:8080/hms)"
  209. nginx2="$(curl --silent -u "jenkins:$(pass show majordomo/private/jenkins/jenkins)" -X GET http://nginx2.intr:8080/hms)"
  210. nginx1_active="$(echo "$nginx1" | jq --raw-output .active)"
  211. nginx2_active="$(echo "$nginx2" | jq --raw-output .active)"
  212. if [[ $nginx1_active == $nginx2_active ]]
  213. then
  214. echo "Current stack: ${nginx1_active}"
  215. if [[ $nginx1_active == "hms1" ]]
  216. then
  217. target="hms2"
  218. else
  219. target="hms1"
  220. fi
  221. cat <<EOF
  222. Switch stack example:
  223. 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"
  224. 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"
  225. EOF
  226. else
  227. echo "WARNING: Stacks mismatches"
  228. cat <<EOF
  229. Switch stack example:
  230. 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"
  231. 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"
  232. EOF
  233. fi
  234. }
  235. mjru-hms-auth ()
  236. {
  237. curl --silent \
  238. --request POST https://api.majordomo.ru/oauth/token \
  239. --header 'content-type: application/x-www-form-urlencoded' \
  240. --header 'x-requested-with: XMLHttpRequest' \
  241. -d "grant_type=password&username=$IHS_USER&password=$IHS_PASS&client_id=service&client_secret=service_secret" \
  242. | jq -r '.access_token'
  243. }
  244. mjru-es-xmlrpc()
  245. {
  246. curl -H 'Content-Type: application/json' \
  247. -X POST "http://es.intr:9200/nginx-$(date +"%Y.%m.%d")/_search/" \
  248. --data-binary '{"from":0,"query":{"query_string":{"query":"path.keyword:\"/xmlrpc.php\""}},"size":50,"sort":[{"@timestamp":{"order":"desc"}}]}'
  249. }
  250. mjru-docker-list-intr()
  251. {
  252. curl -s -X GET -k -u "gradle:$(pass show majordomo/public/nexus/gradle)" https://docker-registry.intr/v2/_catalog \
  253. | jq -r '.repositories[]'
  254. }
  255. mjru-jenkins-log()
  256. {
  257. 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
  258. mkdir -p "$project"
  259. cd "$project" || return
  260. 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
  261. job_name="$(echo "$job" | rev | cut -d/ -f 2 | rev)"
  262. echo "@ $job"
  263. curl -u "admin:$(pass show majordomo/public/jenkins.intr/admin)" -s -k "$job/job/master/lastBuild/consoleText" > "$job_name.log"
  264. done
  265. cd - || return
  266. done
  267. }
  268. mjru-ansible-swarm-ps-inspect()
  269. {
  270. # shellcheck disable=SC2016
  271. 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
  272. }
  273. mjru-ansible-swarm-network-inspect()
  274. {
  275. ansible swarm -m shell -a 'docker network ls | cut -d " " -f 1 | grep -v NETWORK | xargs docker network inspect' --become
  276. }
  277. mjru-dns-check()
  278. {
  279. for dns in 172.16.103.2 172.16.100.3; do
  280. (echo $dns; time dig +short a "${1:-cerberus.intr}" @$dns) |& xargs echo
  281. done
  282. }
  283. mjru-jenkins()
  284. {
  285. JENKINS_URL=https://jenkins.corp1.majordomo.ru \
  286. JENKINS_USER=admin \
  287. JENKINS_PASSWORD="$(pass show majordomo/public/jenkins.intr/admin)" \
  288. jenkins "$@"
  289. }
  290. mjru-vm-vnc()
  291. {
  292. (
  293. set -ex
  294. host="$1"
  295. vm="$2"
  296. vncviewer "$host":"$(connect ssh "$host" virsh dumpxml "$vm" | xq -r '.domain.devices.graphics["@port"]')" &
  297. password="$(ihs vm passwords "$vm" | awk '{ print $NF }')"
  298. sleep 1
  299. echo "(window-send-string (format nil \"~a~%\" \"$password\"))" | stumpish -e eval
  300. sleep 2
  301. echo "(window-send-string (format nil \"~a~%\" \"root\"))" | stumpish -e eval
  302. sleep 0.5
  303. echo "(window-send-string (format nil \"~a~%\" \"$password\"))" | stumpish -e eval
  304. )
  305. }
  306. mjru-proxy()
  307. {
  308. ssh -Nf -D 5557 workstation.intr
  309. }
  310. mjru-vlan()
  311. {
  312. echo "PXE is on VLAN 254"
  313. echo "chef-server '/usr/sbin/in.tftpd -L -a 192.168.254.1 -s /var/tftpboot'"
  314. }
  315. mjru-python()
  316. {
  317. echo "Setting HMS_MONGO_PASSWORD environment variable."
  318. HMS_MONGO_PASSWORD="$(pass show majordomo/public/mongo/hms/admin)" python3
  319. }
  320. mjru-network()
  321. {
  322. awk '/A\t/ || /A / { print "(\"", $NF, "/32\" . ,(string-to-symbols \"", $1, ".intr\"))" }' \
  323. ~/src/gitlab.intr/net/dns-intr/intr-miran.zone ~/src/gitlab.intr/net/dns-intr/intr-datahouse.zone \
  324. | sed 's/" /"/g; s@ /@/@g; s/ ")/")/g; s/"\./" ./; s/ \.intr/.intr/; s/\"\;/"/'
  325. awk '/A\t/ || /A / { print "(\"inet" , $NF, "/24\" . ,(string-to-symbols \"", $1, ".intr\"))" }' \
  326. ~/src/gitlab.intr/net/dns-intr/intr-miran.zone ~/src/gitlab.intr/net/dns-intr/intr-datahouse.zone \
  327. | sed 's/" /"/g; s@ /@/@g; s/ ")/")/g; s/"\./" ./; s/ \.intr/.intr/; s/\"\;/"/'
  328. awk '/A\t/ || /A / { print "(\"", $NF, "\" . ,(string-to-symbols \"", $1, ".intr\"))" }' \
  329. ~/src/gitlab.intr/net/dns-intr/intr-miran.zone ~/src/gitlab.intr/net/dns-intr/intr-datahouse.zone \
  330. | sed 's/" /"/g; s@ /@/@g; s/ ")/")/g; s/ "\./" ./; s/ \.intr/.intr/; s/\"\;/"/'
  331. }
  332. vault1()
  333. {
  334. VAULT_TOKEN="$(pass show majordomo/public/vault/root)" VAULT_ADDR=http://dh1-mr.intr:8210 "${HOME}/.nix-profile/bin/vault" "$@"
  335. }
  336. vault2()
  337. {
  338. VAULT_TOKEN="$(pass show majordomo/public/vault/root)" VAULT_ADDR=http://dh2-mr.intr:8220 "${HOME}/.nix-profile/bin/vault" "$@"
  339. }
  340. vault3()
  341. {
  342. VAULT_TOKEN="$(pass show majordomo/public/vault/root)" VAULT_ADDR=http://dh3-mr.intr:8230 "${HOME}/.nix-profile/bin/vault" "$@"
  343. }
  344. vault4()
  345. {
  346. VAULT_TOKEN="$(pass show majordomo/public/vault-unseal/root)" VAULT_ADDR=http://dh4-mr.intr:8240 "${HOME}/.nix-profile/bin/vault" "$@"
  347. }
  348. vault-ci()
  349. {
  350. VAULT_TOKEN="$(pass show majordomo/public/vault-dev/root)" VAULT_ADDR=http://ci.intr:8210 "${HOME}/.nix-profile/bin/vault" "$@"
  351. }
  352. mjru-gitlab()
  353. {
  354. GITLAB_HOST=https://gitlab.intr \
  355. GITLAB_TOKEN="$(pass show majordomo/private/gitlab.intr/tokens/pyhalov)" \
  356. command glab "$@"
  357. }
  358. if [ -f "${HOME}/.nix-profile/bin/glab" ]
  359. then
  360. if [[ $(type -t compopt) = "builtin" ]]; then
  361. complete -o default -F __start_glab mjru-gitlab
  362. else
  363. complete -o default -o nospace -F __start_glab mjru-gitlab
  364. fi
  365. fi
  366. mjru-curl()
  367. {
  368. curl --header "Authorization: Bearer $(mjru-auth)" \
  369. --header 'Content-Type: application/json' \
  370. "$@"
  371. }
  372. mongo()
  373. {
  374. case "$1" in
  375. cluster1)
  376. command mongo "mongodb://admin:$(pass show majordomo/public/mongo/ci.intr/admin)@mongodb.hms.development.corp1.majordomo.ru:27017/admin" \
  377. "${@:2}"
  378. ;;
  379. ci)
  380. command mongo "mongodb://admin:$(pass show majordomo/public/mongo/ci.intr/admin)@ci.intr:27017/admin" \
  381. "${@:2}"
  382. ;;
  383. production)
  384. 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" \
  385. "${@:2}"
  386. ;;
  387. *)
  388. command mongo "$@"
  389. esac
  390. }
  391. mongodump()
  392. {
  393. case "$1" in
  394. cluster1)
  395. command mongodump \
  396. --authenticationDatabase=admin \
  397. --username=admin \
  398. --password="$(pass show majordomo/public/mongo/ci.intr/admin)" \
  399. --uri="mongodb://mongodb.hms.development.corp1.majordomo.ru:27017/" \
  400. "${@:2}"
  401. ;;
  402. ci)
  403. command mongodump \
  404. --authenticationDatabase=admin \
  405. --username=admin \
  406. --password="$(pass show majordomo/public/mongo/ci.intr/admin)" \
  407. --uri="mongodb://ci.intr:27017/" \
  408. "${@:2}"
  409. ;;
  410. production)
  411. command mongodump \
  412. --authenticationDatabase=admin \
  413. --username=admin \
  414. --password="$(pass show majordomo/public/mongo/ci.intr/admin)" \
  415. --uri="mongodb://hms01-mr.intr:27017,hms02-mr.intr:27017,hms03-mr.intr:27017/?replicaSet=hms-rs0" \
  416. "${@:2}"
  417. ;;
  418. *)
  419. command mongodump "$@"
  420. esac
  421. }
  422. mongorestore()
  423. {
  424. case "$1" in
  425. cluster1)
  426. command mongorestore \
  427. --authenticationDatabase=admin \
  428. --username=admin \
  429. --password="$(pass show majordomo/public/mongo/ci.intr/admin)" \
  430. --uri="mongodb://mongodb.hms.development.corp1.majordomo.ru:27017/" \
  431. "${@:2}"
  432. ;;
  433. ci)
  434. command mongorestore \
  435. --authenticationDatabase=admin \
  436. --username=admin \
  437. --password="$(pass show majordomo/public/mongo/ci.intr/admin)" \
  438. --uri="mongodb://ci.intr:27017/" \
  439. "${@:2}"
  440. ;;
  441. alerta)
  442. command mongorestore \
  443. --authenticationDatabase=admin \
  444. --username=root \
  445. --password="$(pass show majordomo/public/alerta/mongodb/root)" \
  446. --uri="mongodb://localhost:27017/" \
  447. "${@:2}"
  448. ;;
  449. production)
  450. command mongorestore \
  451. --authenticationDatabase=admin \
  452. --username=admin \
  453. --password="$(pass show majordomo/public/mongo/ci.intr/admin)" \
  454. --uri="mongodb://hms01-mr.intr:27017,hms02-mr.intr:27017,hms03-mr.intr:27017/?replicaSet=hms-rs0" \
  455. "${@:2}"
  456. ;;
  457. *)
  458. command mongorestore "$@"
  459. esac
  460. }
  461. mongoexport()
  462. {
  463. case "$1" in
  464. cluster1)
  465. command mongoexport \
  466. --authenticationDatabase=admin \
  467. --username=admin \
  468. --password="$(pass show majordomo/public/mongo/ci.intr/admin)" \
  469. --uri="mongodb://mongodb.hms.development.corp1.majordomo.ru:27017/" \
  470. "${@:2}"
  471. ;;
  472. ci)
  473. command mongoexport \
  474. --authenticationDatabase=admin \
  475. --username=admin \
  476. --password="$(pass show majordomo/public/mongo/ci.intr/admin)" \
  477. --uri="mongodb://ci.intr:27017/" \
  478. "${@:2}"
  479. ;;
  480. production)
  481. command mongoexport --authenticationDatabase=admin \
  482. --username=admin \
  483. --password="$(pass show majordomo/public/mongo/ci.intr/admin)" \
  484. --uri="mongodb://hms01-mr.intr:27017,hms02-mr.intr:27017,hms03-mr.intr:27017/?replicaSet=hms-rs0" \
  485. "${@:2}"
  486. ;;
  487. *)
  488. command mongoexport "$@"
  489. esac
  490. }
  491. mongoimport()
  492. {
  493. case "$1" in
  494. cluster1)
  495. command mongoimport \
  496. --authenticationDatabase=admin \
  497. --username=admin \
  498. --password="$(pass show majordomo/public/mongo/ci.intr/admin)" \
  499. --uri="mongodb://mongodb.hms.development.corp1.majordomo.ru:27017/" \
  500. "${@:2}"
  501. ;;
  502. ci)
  503. command mongoimport \
  504. --authenticationDatabase=admin \
  505. --username=admin \
  506. --password="$(pass show majordomo/public/mongo/ci.intr/admin)" \
  507. --uri="mongodb://ci.intr:27017/" \
  508. "${@:2}"
  509. ;;
  510. production)
  511. command mongoimport --authenticationDatabase=admin \
  512. --username=admin \
  513. --password="$(pass show majordomo/public/mongo/ci.intr/admin)" \
  514. --uri="mongodb://hms01-mr.intr:27017,hms02-mr.intr:27017,hms03-mr.intr:27017/?replicaSet=hms-rs0" \
  515. "${@:2}"
  516. ;;
  517. *)
  518. command mongoimport "$@"
  519. esac
  520. }