Automatic Minecraft server update

For this script to work you need a “version.txt” file in the same folder as the script. The file has to contain your current server version(1.12.1).

NEWVERSION=$(curl -s 'https://launchermeta.mojang.com/mc/game/version_manifest.json' | python3 -c "import sys, json; print(json.load(sys.stdin)['latest']['release'])")
    if [ $NEWVERSION != $(cat version.txt) ]; then
       echo $NEWVERSION > version.txt
       wget 'https://s3.amazonaws.com/Minecraft.Download/versions/'$NEWVERSION'/minecraft_server.'$NEWVERSION'.jar'
       ps aux | grep -i minecraft_server | awk {'print $2'} | xargs kill -9
       nohup java -Xmx1324M -Xms1324M -jar 'minecraft_server.'$NEWVERSION'.jar' &
fi

Send Emails from the Command-line

Install all all necessary packages:

sudo apt-get install postfix mailutils libsasl2-2 ca-certificates libsasl2-modules

Open your postfix config file:

sudo nano /etc/postfix/main.cf

Add the following lines (there might allready be a empty “relayhost” line):

relayhost = [smtp.example.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_use_tls = yes

Open:

sudo nano /etc/postfix/sasl_passwd

Add:

[smtp.example.com]:587    USERNAME@example.com:PASSWORD

Change permission and update postfix config to use sasl_passwd file:

sudo chmod 400 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd

Reload postfix config:

sudo /etc/init.d/postfix reload

The following command should send an Email if you have done everything right:

echo "Test" | mail -s "Test" example@example.com

Let Ubuntu send you Emails if security updates are available

Install update-notifier:

sudo apt-get install update-notifier

You can see here how to make the mail part work. Save the script and make it executable with “chmod +x script.sh”:

updates=$(/usr/lib/update-notifier/apt-check 2>&1)

pending=$(echo "${updates}" | cut -d ";" -f 2)
if [ "$pending" != "0" ]; then
    echo "${pending} security update(s) pending." | mail -s "Security update pending" example@example.me
    exit
fi

pending=$(echo "${updates}" | cut -d ";" -f 1)
if [ "$pending" != "0" ]; then
    echo "${pending} non-security update(s) pending." | mail -s "Non-Security update pending" example@example.me
fi

Open crontab:

crontab -e

Add a line that executes the script as often as you like. In this case it is executed once a day at 5:00.

* 5 * * * bash /path/to/your/script.sh

Wikipedia context menu search Firefox addon

If you just want to install the addon you can do that here. As the name implies it adds an entry to the context menu to search Wikipedia for highlighted text. The code can be found below. background.js

browser.contextMenus.create({
    id: "log-selection",
    title: "Search Wikipedia",
    contexts: ["selection"]
});

browser.contextMenus.onClicked.addListener(function(info, tab) {
    if (info.menuItemId == "log-selection") {
        var selectedText = info.selectionText;
        browser.storage.local.get({
                "language": "en",
                "tabBehaviour": "new",
                "tabActive": "yes"
            },
            function(item) {
                var language = item.language;
                var tabBehaviour = item.tabBehaviour;
                var tabActive = item.tabActive;

                var url = "https://" + language + ".wikipedia.org/w/index.php?search=" + encodeURIComponent(selectedText) + "&title=Special%3ASearch&fulltext=Search";
                if (tabBehaviour == "new") {
                    if (tabActive == "no") {
                        chrome.tabs.create({
                            url: url,
                            active: false
                        });
                    } else {
                        chrome.tabs.create({
                            url: url
                        });
                    }
                } else {
                    chrome.tabs.update({
                        url: url
                    });
                }
            });

    };
});

options.js

document.addEventListener('DOMContentLoaded', loadOptions);
document.querySelector('form').addEventListener('submit', saveOptions);

var storage = chrome.storage.local;
var language = document.querySelector('#language');
var tabBehaviour = document.querySelector('#tabBehaviour');
var tabActive = document.querySelector('#tabActive');

function saveOptions(e) {
    e.preventDefault();
    storage.set({
        'language': language.value,
        'tabBehaviour': tabBehaviour.value,
	'tabActive': tabActive.value
    }), function () {}
}

function loadOptions() {
    storage.get({
        'language': 'en',
        'tabBehaviour': 'new',
	'tabActive': 'yes'
    }, function (items) {
        language.value = items.language;
        tabBehaviour.value = items.tabBehaviour;
	tabActive.value = items.tabActive;
    });
}

options.html

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <link rel="stylesheet" type="text/css" href="options.css">
</head>

<body>
    <form>
        <p>
            <h3>Language</h3>
        </p>
        <select id="language" size="5">
			<option value="simple">Simple English</option>
			<option value="ar">العربية</option>
			<option value="id">Bahasa Indonesia</option>
			<option value="ms">Bahasa Melayu</option>
			<option value="bs">Bosanski</option>
			<option value="bg">Български</option>
			<option value="ca">Català</option>
			<option value="cs">Čeština</option>
			<option value="da">Dansk</option>
			<option value="de">Deutsch</option> 
			<option value="et">Eesti</option> 
			<option value="el">Ελληνικά</option> 
			<option value="en">English</option> 
			<option value="es">Español</option> 
			<option value="eo">Esperanto</option> 
			<option value="eu">Euskara</option>
			<option value="fr">Français</option>
			<option value="fa">فارسی</option> 
			<option value="gl">Galego</option> 
			<option value="ko">한국어</option> 
			<option value="he">Hrvatski</option> 
			<option value="it">Italiano</option> 
			<option value="ka">ქართული</option> 
			<option value="lv">Latviešu</option> 
			<option value="lt">Lietuvių</option> 
			<option value="hu">Magyar</option> 
			<option value="nl">Nederlands</option> 
			<option value="ja">日本語</option> 
			<option value="no">Norsk bokmål</option>
			<option value="nn">Norsk nynorsk</option> 
			<option value="pt">Português</option> 
			<option value="ro">Română</option> 
			<option value="ru">Русский</option> 
			<option value="sk">Slovenčina</option> 
			<option value="sl">Српски / srpski</option> 
			<option value="sh">Srpskohrvatski / српскохрватски</option> 
			<option value="fi">Suomi</option> 
			<option value="sv">Svenska</option> 
			<option value="th">ไทย</option>
			<option value="vi">Tiếng Việt</option> 
			<option value="uk">Українська</option> 
			<option value="zh">中文</option> 
			</select>
        <p>
            <h3>Tab behaviour</h3>
        </p>
        <select id="tabBehaviour" size="2">
			<option value="new">Open in new tab</option>
			<option value="old">Open in active tab</option>
			
			</select>
        <select id="tabActive" size="2">
			<option value="yes">New tab becomes active</option>
			<option value="no">New tab becomes not active</option>
			</select>
        <p><button type="submit" class="button">Save</button></p>
    </form>
    <script src="options.js"></script>
</body>

</html>

options.css

.button {
    border-style: hidden;
    background-color: rgb(76, 175, 80);
    padding: 0.5em 3em;
    color: white;
}

.button:hover {
    box-shadow: 0px 0px 20px #aaa;
}

manifest.json

{

    "description": "Select text. Right click. Search Wikipedia for the selected text.",
    "manifest_version": 2,
    "name": "Wikipedia Context Menu Search",
    "version": "1.2",
    "homepage_url": "https://diedrich.me/contact/",
    "icons": {
        "64": "icons/page-64.png"

    },

    "applications": {
        "gecko": {
            "id": "@wikipediacontextmenusearch",
            "strict_min_version": "52.0"
        }
    },

    "background": {
        "scripts": ["background.js"]
    },

    "options_ui": {
        "page": "options.html"
    },


    "permissions": [
        "tabs",
        "storage",
        "contextMenus"
    ]


}

Star time lapse

The video is 65mb large and only 4 seconds long. Might take a moment to load. The video is made from 87 photos i took.