Schlagwort-Archive: Bash

Mein persönliches Uberspace-Init Script

Ich habe mir ein kleines Script gebastelt, mit dem ich neuen Uberspaces mit wenigen Befehlen einge Voreinstellungen verpassen kann.

Die Funktion in Kürze:

  • Einen Symlink für das Übergeordnete Verzeichnis der Pseudo-DOCUMENT_ROOTs. Zwar nicht unbedingt notwendig aber cd www ist schneller getippt wie cd /var/www/virtual/$USER
  • Vorbereitung für die Daemontools: uberspace-setup-svscan
  • Ein bin– und ein git-Verzeichnis – benötige ich öfters.
  • E-Mail Weiterleitung zu einer auszuwählenden E-Mail-Adresse, oder ins Maildir.
  • Außerdem hole ich mir noch angepasste bash Konfigurationsdateien, die ich bei github abgelegt habe.

Mit dem Parameter bash-config-update wird nur der letzte Punkt ausgeführt. Mit dem Parameter cleanup werden Sicherungskopien der bash Konfiguration von bash-config-update nach /dev/null befördert.

[shell]
#!/bin/bash
#
# uberspace-init.sh
#
# Init-Script to init new Uberspaces and to Update bash-config
#
#
# Copyright 2014-2015 GOLDERWEB – Jonathan Golder
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see
#

# Make sure we are in $HOME
cd $HOME;

# Download my personal default bash configuration files from github
bash-config-update() {

# Download modified bash-config from github
( test -f .bash_profile && mv .bash_profile .bash_profile.save || test -d . ) && wget -q https://gist.githubusercontent.com/golderweb/d910ae1edbe853377da5/raw/.bash_profile
( test -f .bashrc && mv .bashrc .bashrc.save || test -d . ) && wget -q https://gist.githubusercontent.com/golderweb/e912ccfafda58470e51a/raw/.bashrc
( test -f .bash_functions && mv .bash_functions .bash_functions.save || test -d . ) && wget -q https://gist.github.com/golderweb/3dbb4f897339cf5c74e7/raw/.bash_functions
( test -f .bash_aliases && mv .bash_aliases .bash_aliases.save || test -d . ) && wget -q https://gist.github.com/golderweb/79a4a2cc2cb126d30d4a/raw/.bash_aliases

echo „Test if everything works right, then run \“uberspace-init cleanup\““
}
case „$1″ in

init|““)
# Set up some predefinitions on new uberspace

# Create Symlink for www
test -e ~/www || ln -s /var/www/virtual/$USER www

# Prepare ubespace for using daemontools
test -d ~/service || uberspace-setup-svscan

# Create several dirs
test -d ~/bin || mkdir bin
test -d ~/git || mkdir git

# Enable E-Mail redirection
read -p „Enter E-Mail-Adress for redirection, leave empty for use Maildir of this uberspace:“ mail

if [ -n „$mail“ ]; then
echo -e „#Redirect incomming E-Mails on ${USER} to ${mail}\n$mail“ > .qmail || echo „ERROR: .qmail-file couldn’t be wrote! E-Mails will be delivered to Maildir“
else
echo „No E-Mail-adress was provided, E-Mails will be delivered to Maildir“
fi

#Get bash-config files from github
bash-config-update
;;

bash-config-update)

#Get bash-config files from github
bash-config-update
;;

cleanup)

#Remove backup files
rm .bash_profile.save .bashrc.save .bash_functions.save .bash_aliases.save
;;

*) echo „Invalid parameter“
;;

esac
[/shell]

Wenn dir das Uberspace-Init Script gefällt darfst du es gerne unter den Bedingungen der GNU GPLv3 weiterverwenden. Du findest es unter https://gist.github.com/golderweb/4feb43ed41b49bd7bc27. Einfach den Quelltext kopieren, mit git clonen oder einen Github-Fork erstellen.