Last active
May 4, 2016 13:51
-
-
Save sheldonh/7980f090bec080cbffb9 to your computer and use it in GitHub Desktop.
Desktop bootstrap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# 1. Install Google Chrome and LastPass | |
# 2. Fetch secrets from S3 | |
# 3. Profit! | |
# | |
# To run: | |
# | |
# wget -O setup.sh https://goo.gl/htFGUu | |
# chmod +x setup.sh | |
# sudo ./setup.sh | |
if [ $(id -u) != 0 ]; then | |
echo "sudo, remember?" 1>&2 | |
exit 1 | |
fi | |
RUBY_VERSION=2.2.3 | |
RUBY_GEMS="aws-sdk-core gist bundler" | |
. /etc/os-release || exit 1 | |
DISTRO="$NAME" | |
case "$DISTRO" in | |
"Ubuntu") | |
BOOTSTRAP_PACKAGES='git gnupg gnupg-curl' | |
RUBY_PACKAGES='autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev' | |
EXTRA_VCS_PACKAGES='bzr mercurial' | |
COMFORT_PACKAGES='vim-gtk ack-grep hexchat curl jq' | |
OFFICE_PACKAGES='krb5-user openvpn' | |
CHROME_PACKAGE=google-chrome-stable_current_amd64.deb | |
install_local_package() { | |
if ! dpkg -i $1; then | |
DEBIAN_FRONTEND=noninteractive apt-get install -fy | |
dpkg -i $1 | |
fi | |
} | |
install_packages() { | |
DEBIAN_FRONTEND=noninteractive apt-get install -y $* | |
} | |
is_package_installed() { | |
dpkg -l $1 >/dev/null 2>&1 | |
} | |
install_skype() { | |
sed -i -e 's,^# \(deb http://archive.canonical.com/ubuntu .* partner\)$,\1,' /etc/apt/sources.list | |
apt-get update | |
apt-get install -y skype gtk2-engines-murrine:i386 gtk2-engines-pixbuf:i386 | |
} | |
update_vim_alternative() { | |
update-alternatives --install /usr/bin/vim vim /usr/bin/vim.gtk 900 | |
} | |
;; | |
"Fedora") | |
BOOTSTRAP_PACKAGES='git gnupg' | |
RUBY_PACKAGES='gcc openssl-devel libyaml-devel libffi-devel readline-devel zlib-devel gdbm-devel ncurses-devel' | |
EXTRA_VCS_PACKAGES='bzr mercurial' | |
COMFORT_PACKAGES='vim-X11 ack hexchat jq xfce4-whiskermenu-plugin elementary-xfce-icon-theme google-droid-sans-fonts' | |
OFFICE_PACKAGES='krb5-workstation openvpn' | |
CHROME_PACKAGE=google-chrome-stable_current_x86_64.rpm | |
install_local_package() { | |
dnf install -y $1 | |
} | |
install_packages() { | |
dnf install -y $* | |
} | |
is_package_installed() { | |
rpm -qi $1 >/dev/null 2>&1 | |
} | |
install_skype() { | |
wget -O skype.rpm http://www.skype.com/go/getskype-linux-beta-fc10 | |
install_local_package ./skype.rpm | |
} | |
update_vim_alternative() { | |
update-alternatives --install /usr/bin/vim vim /usr/bin/vimx 900 | |
} | |
;; | |
*) | |
echo "unsupported distro $DISTRO" 1>&2 | |
exit 1 | |
;; | |
esac | |
####################################### | |
# 1. Install Google Chrome and LastPass | |
####################################### | |
USER=sheldonh | |
cleanup() { | |
cd / | |
if [ -n "$tmpdir" -a -d "$tmpdir" ]; then | |
echo cleaning up $tmpdir | |
rm -rf $tmpdir | |
fi | |
if [ -n "$script" -a -e "$script" ]; then | |
echo cleaning up $script | |
rm $script | |
fi | |
} | |
trap cleanup EXIT | |
tmpdir=$(mktemp -d) | |
chown $USER $tmpdir | |
cd $tmpdir | |
if ! is_package_installed google-chrome-stable; then | |
wget https://dl.google.com/linux/direct/$CHROME_PACKAGE | |
install_local_package ./$CHROME_PACKAGE | |
else | |
echo google-chrome-stable is already installed | |
fi | |
is_lastpass_chrome_extension_installed() { | |
count=$(find /home/$USER/.config/google-chrome/Default/Extensions -name lastpass.js | wc -l) | |
[ "$count" != "0" ] | |
} | |
if ! is_lastpass_chrome_extension_installed; then | |
wget https://lastpass.com/lplinux.tar.bz2 | |
tar -xf lplinux.tar.bz2 | |
( cd lplinux && \ | |
sed -i -e 's,\(google-chrome https://lastpass.com/.*\) &,\1 >/dev/null 2>\&1 \&,' install_lastpass.sh && \ | |
sudo -u $USER ./install_lastpass.sh ) | |
else | |
echo lastpass is already installed | |
fi | |
####################################### | |
# 2. Fetch secrets from S3 | |
####################################### | |
install_packages \ | |
$BOOTSTRAP_PACKAGES $RUBY_PACKAGES $OFFICE_PACKAGES $COMFORT_PACKAGES $EXTRA_VCS_PACKAGES | |
if ! type pip >/dev/null 2>&1; then | |
wget https://bootstrap.pypa.io/get-pip.py | |
python get-pip.py | |
fi | |
pip show awscli || pip install awscli | |
update_vim_alternative | |
if [ ! -e /usr/local/bin/ruby-build ]; then | |
git clone https://github.com/sstephenson/ruby-build.git | |
( cd ruby-build && ./install.sh ) | |
fi | |
if [ ! -e /usr/local/bin/chruby-exec ]; then | |
git clone https://github.com/postmodern/chruby.git | |
( cd chruby && sed -i -e '/chruby\/auto.sh/d' ./scripts/setup.sh && ./scripts/setup.sh ) | |
fi | |
if ! is_lastpass_chrome_extension_installed; then | |
echo Waiting for LastPass extension for Chrome to be installed... | |
while ! is_lastpass_chrome_extension_installed; do | |
sleep 1 | |
done | |
fi | |
# Fix https://bugs.archlinux.org/task/43999 | |
if [ -e /etc/lightdm/lightdm-gtk-greeter.conf ] && ! grep -q ^active-monitor= /etc/lightdm/lightdm-gtk-greeter.conf; then | |
echo active-monitor=0 >> /etc/lightdm/lightdm-gtk-greeter.conf | |
fi | |
# Enable autologin on Fedora | |
if [ -e /etc/lightdm/lightdm.conf ] && grep -q '^#autologin-user=' /etc/lightdm/lightdm.conf; then | |
sed -i -e 's/^#autologin-user=$/autologin-user=sheldonh/' /etc/lightdm/lightdm.conf | |
fi | |
script=$(mktemp) | |
cat > $script <<-EOF | |
#!/bin/sh -x | |
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin | |
cd ~ | |
mkdir -p ~/.local/bin | |
aws configure set output json --profile starjuice | |
aws configure set region eu-west-1 --profile starjuice | |
aws configure set s3.signature_version s3v4 --profile starjuice | |
grep starjuice ~/.aws/credentials || aws configure --profile starjuice | |
for i in .aws .gnupg .ssh .openvpn; do | |
mkdir -p \$i | |
chmod 700 \$i | |
aws s3 sync s3://starjuice-secrets/sheldonh/\$i ~/\$i --profile starjuice --sse --exact-timestamps | |
chmod -R go-rwx \$i | |
done | |
aws s3 sync s3://starjuice-secrets/sheldonh/bin ~/bin --profile starjuice --sse --exact-timestamps | |
chmod -R 700 bin | |
for i in .bashrc .bash_profile .gist .gitconfig .gitignore_global .krb5.conf; do | |
aws s3 cp s3://starjuice-secrets/sheldonh/\$i ~/\$i --profile starjuice --sse | |
chmod 600 \$i | |
done | |
if [ -e ~/.config/xfce4/xfconf/xfce-perchannel-xml -a ! -h ~/.config/xfce4/xfconf/xfce-perchannel-xml ]; then | |
mkdir -p ~/.config/xfce4/xfconf/xfce-perchannel-xml.$DISTRO | |
mv ~/.config/xfce4/xfconf/xfce-perchannel-xml/* ~/.config/xfce4/xfconf/xfce-perchannel-xml.$DISTRO/ | |
rm -rf ~/.config/xfce4/xfconf/xfce-perchannel-xml | |
( cd ~/.config/xfce4/xfconf && ln -s xfce-perchannel-xml.$DISTRO xfce-perchannel-xml ) | |
fi | |
aws s3 sync s3://starjuice-secrets/sheldonh/.config ~/.config --profile starjuice --sse --exact-timestamps | |
if [ ! -e ~/.vim ]; then | |
cd ~ | |
rm -rf .vimrc .vim | |
git clone git://github.com/sheldonh/dotvim.git .vim | |
git clone https://github.com/gmarik/Vundle.vim.git .vim/bundle/Vundle.vim | |
ln -s .vim/vimrc .vimrc | |
vim -c :PluginInstall -c :qall | |
fi | |
if [ ! -e ~/.rubies/$RUBY_VERSION/bin/ruby ]; then | |
ruby-build $RUBY_VERSION ~/.rubies/$RUBY_VERSION | |
fi | |
for i in $RUBY_GEMS; do | |
if ! chruby-exec $RUBY_VERSION -- gem list -i \$i; then | |
chruby-exec $RUBY_VERSION -- gem install \$i | |
fi | |
done | |
if [ ! -e ~/.local/nodejs/bin/node ]; then | |
cd $tmpdir | |
nodejs_version=4.3.2 | |
nodejs_major_version=\${nodejs_version%%.*} | |
wget https://nodejs.org/dist/latest-v\${nodejs_major_version}.x/SHASUMS256.txt | |
nodejs_version=\$(sed -n -e 's/^.*node-v\([0-9.]*\)-linux-x64.tar.gz$/\1/p' SHASUMS256.txt) | |
wget https://nodejs.org/dist/latest-v\${nodejs_major_version}.x/node-v\${nodejs_version}-linux-x64.tar.gz | |
tar -xzf node-v\${nodejs_version}-linux-x64.tar.gz | |
mv node-v\${nodejs_version}-linux-x64 ~/.local/nodejs | |
fi | |
if [ ! -e ~/.local/nodejs/bin/coffee ]; then | |
~/.local/nodejs/bin/npm install -g coffee-script | |
fi | |
if [ ! -e ~/.local/go/bin/go ]; then | |
cd $tmpdir | |
wget https://storage.googleapis.com/golang/go1.5.1.linux-amd64.tar.gz | |
mkdir -p ~/.local | |
tar -C ~/.local -xzf go1.5.1.linux-amd64.tar.gz | |
fi | |
EOF | |
chmod 700 $script | |
chown sheldonh $script | |
sudo -u $USER $script | |
cat /home/sheldonh/.krb5.conf > /etc/krb5.conf | |
if ! is_package_installed skype; then | |
install_skype | |
fi | |
echo 'Remember to terminate this terminal. Enjoy!' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -e | |
if [ $(id -u) != 0 ]; then | |
echo "sudo, remember?" 1>&2 | |
exit 1 | |
fi | |
. /etc/os-release | |
DISTRO="$NAME" | |
case "$DISTRO" in | |
"Ubuntu") | |
echo "Ubuntu supports virtualbox guest additions natively" | |
exit 0 | |
;; | |
"Fedora") | |
dnf install -y gcc kernel kernel-devel kernel-headers dkms make bzip2 perl | |
dnf update -y gcc kernel kernel-devel kernel-headers dkms make bzip2 perl | |
kpkg=$(rpm -q kernel-devel | sort | tail -n 1) | |
kver=$(uname -r) | |
dver=${kpkg#kernel-devel-} | |
if [ "$kver" != "$dver" ]; then | |
echo | |
echo $kpkg does not match: | |
echo running kernel $kver | |
echo | |
echo Reboot? | |
exit 1 | |
fi | |
KERN_DIR=/usr/src/kernels/$kver | |
export KERN_DIR | |
echo KERN_DIR=$KERN_DIR | |
mkdir -p /media/VirtualBoxGuestAdditions | |
mount -o ro /dev/cdrom /media/VirtualBoxGuestAdditions || \ | |
mount -o remount,ro /dev/cdrom /media/VirtualBoxGuestAdditions | |
cd /media/VirtualBoxGuestAdditions | |
./VBoxLinuxAdditions.run | |
exit $? | |
;; | |
*) | |
echo "unsupported distro $DISTRO" 1>&2 | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment