Skip to content

Instantly share code, notes, and snippets.

@henrikj242
Last active December 21, 2018 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henrikj242/5dd8ed47177918cec4270635e4e3dbc9 to your computer and use it in GitHub Desktop.
Save henrikj242/5dd8ed47177918cec4270635e4e3dbc9 to your computer and use it in GitHub Desktop.
peytz_mail connecting with many things
# Use mongo console command `show databases` to get the databases and their size:
dbs=$(mongo --quiet <<EOF
show dbs
quit()
EOF
)
i=0
j=0
client_dbs=()
for db in ${dbs[*]}
do
# Odd values are db names
# Even values are sizes
i=$(($i+1))
# Show db name, ignore size
if (( $i % 2 )); then
if [[ $db =~ ^mail\- ]]; then
# Print out the name of the client db:
echo "$db"
# Optionally add id to an array:
client_dbs[j]="$db"
j=$(($j+1))
fi
fi
done
# Access the client databases via the array:
for cdb in ${client_dbs[@]}; do
echo "Client db: ${cdb}"
# Perform some actions, for example export link_filters:
mongoexport -d $cdb -c link_filters -o "${cdb}-link_filters.json"
done
#!/bin/bash
# Get all Peytz Mail client repos from github
# Originally written by https://github.com/nikolajsen
GHBU_UNAME="" # the username of a GitHub account (to use with the GitHub API)
GHBU_PASSWD="" # the password for that account - get it at https://github.com/settings/tokens
GHBU_ORG="" # the github organizatoin we keep our client repos in
GHBU_GIT_CLONE_CMD="git clone git@github.com:${GHBU_ORG}/" # base command to use to clone GitHub repos
echo -n "Fetching list of repositories for ${GHBU_ORG}..."
NUM_REPOS=1 # initialize to get us started
PAGE=1
echo "" && echo "=== CLONING ===" && echo ""
while [ $NUM_REPOS -gt 0 ]
do
REPOS=`curl --silent -u $GHBU_UNAME:$GHBU_PASSWD https://api.github.com/orgs/${GHBU_ORG}/repos\?page=${PAGE}\&per_page=100 -q | grep "\"name\"" | awk -F': "' '{print $2}' | sed -e 's/",//g'`
NUM_REPOS=`echo $REPOS | wc -w`
if [ $NUM_REPOS -eq 0 ]
then
break
fi
for REPO in $REPOS; do
if [[ $REPO =~ ^mail\- ]]
then
if [ -d ${REPO} ]
then
echo "We've already got ${REPO} - skipping it"
else
echo "Cloning ${REPO}"
${GHBU_GIT_CLONE_CMD}${REPO} ${REPO}
fi
else
echo "Skipping ${REPO}"
fi
done
PAGE=$((PAGE+1))
done
echo "" && echo "=== DONE ===" && echo ""
echo "We've got all $GHBU_ORG repos starting with mail- cloned now." && echo ""
#-------------------------------------------------
# Assuming all client repos have been checked out
# -- see https://gist.github.com/henrikj242/5dd8ed47177918cec4270635e4e3dbc9
# ------------------------------------------------
echo "Views updated at..." > out.txt
for client in ./*
do
if [ -d $client ]; then
cd ./$client/
git checkout master
updated_at="$(git log -1 --format=%cd ./app/views)"
echo "${client} app/views/ was updated at: ${updated_at}" >> ../out.txt
cd ../
fi
done
# We can also connect to the installations using API and, for example get the FROM-sender
# for each mailinglist and write them to a text file:
require 'net/http'
require 'json'
froms = []
[
['test.peytzmail.com', 'API_KEY'],
].each do |client|
# With curl
# response = JSON.parse(`curl -u #{client[1]}: https://#{client[0]}/api/v1/mailinglists.json`)
# or with ruby (OS independent)
uri = URI("https://#{client[0]}/api/v1/mailinglists.json")
req = Net::HTTP::Get.new(uri)
req.basic_auth client[1], ''
response = Net::HTTP.start(uri.host, uri.port,
:use_ssl => uri.scheme == 'https') do |http|
http.request req # Net::HTTPResponse object
end
response = JSON.parse(response.body)
response["mailinglists"].each do |m|
froms << m["from_email"] unless froms.include?(m["from_email"])
end
end
File.open('senders.txt', 'w') do |file|
froms.each do |from|
file.puts from
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment