dotfiles/install.sh

344 lines
9.1 KiB
Bash
Raw Normal View History

#!/bin/bash
set -e
# install.sh
# This script installs my basic setup for a debian laptop
USERNAME=fschl
apt_sources() {
cat <<-EOF > /etc/apt/sources.list
2015-12-20 23:49:15 +01:00
deb http://ftp.de.debian.org/debian/ stable main contrib non-free
deb-src http://ftp.de.debian.org/debian/ stable main contrib non-free
2015-12-20 23:49:15 +01:00
deb http://security.debian.org/ stable/updates main contrib non-free
deb-src http://security.debian.org/ stable/updates main contrib non-free
2015-12-20 23:49:15 +01:00
# stable-updates, previously known as 'volatile'
deb http://ftp.de.debian.org/debian/ stable-updates main contrib non-free
deb-src http://ftp.de.debian.org/debian/ stable-updates main contrib non-free
2016-07-01 01:37:22 +02:00
deb http://ftp.de.debian.org/debian/ stable-proposed-updates main
deb http://ftp.de.debian.org/debian/ testing main
EOF
2015-12-20 23:49:15 +01:00
}
base_applications() {
2016-07-01 01:37:22 +02:00
echo "update and installing baseapps..."
apt-get update
apt-get upgrade
apt-get install -y \
apt-transport-https \
automake \
bash-completion \
2016-08-26 13:46:08 +02:00
bmon \
bzip2 \
ca-certificates \
cmake \
coreutils \
curl \
2016-12-05 22:54:47 +01:00
dnsutils \
gcc \
git \
gnupg \
2016-12-05 22:54:47 +01:00
gnupg2 \
gnupg-agent \
gnupg-curl \
grep \
2015-12-20 23:49:15 +01:00
htop \
2016-08-26 13:46:08 +02:00
iotop \
locales \
make \
mount \
net-tools \
2016-08-26 13:46:08 +02:00
rsync \
ssh \
sudo \
tar \
2017-03-07 15:35:13 +01:00
tinc \
2016-12-05 22:54:47 +01:00
tmux \
tree \
2017-03-07 15:35:13 +01:00
vim \
zip \
--no-install-recommends
2016-07-01 01:37:22 +02:00
echo "... DONE... cleaning up\n\n"
apt-get autoremove
apt-get autoclean
apt-get clean
2017-01-04 23:44:35 +01:00
}
install_server_base() {
echo "update and installing server base tools..."
apt-get update
apt-get install -y \
fail2ban \
logwatch \
unattended-upgrades \
--no-install-recommends
echo "... DONE... cleaning up\n\n"
apt-get autoremove
apt-get autoclean
apt-get clean
echo "setting up logwatch..."
cat <<-EOF > /etc/cron.daily/00logwatch
/usr/sbin/logwatch --output mail --mailto you@example.com --detail high
EOF
echo " ... DONE"
# TODO: is this really needed?
echo "set unattended upgrades..."
cat <<-EOF > /etc/apt/apt.conf.d/10periodic
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Download-Upgradeable-Packages "1";
APT::Periodic::AutocleanInterval "7";
APT::Periodic::Unattended-Upgrade "1";
EOF
echo " ... DONE"
2016-08-10 16:33:19 +02:00
}
2017-01-04 23:44:35 +01:00
2016-08-26 13:46:32 +02:00
no_suspend() {
# https://wiki.debian.org/SystemdSuspendSedation
sudo sed -i "s/HandleLidSwitch=.*/HandleLidSwitch=ignore/" /etc/systemd/logind.conf
sudo sed -i "s/HandleLidSwitchDocked=.*/HandleLidSwitchDocked=ignore/" /etc/systemd/logind.conf
2016-09-12 11:00:50 +02:00
sudo sed -i "s/IdleActionSec=.*/IdleActionSec=90min/" /etc/systemd/logind.conf
2017-01-04 23:44:35 +01:00
# turn off screen blanking
# https://www.raspberrypi.org/forums/viewtopic.php?f=66&t=18200&sid=135af53eb82496bc64f4c0eefbc86d2c&start=25
# http://raspberrypi.stackexchange.com/questions/752/how-do-i-prevent-the-screen-from-going-blank
xset s noblank
2016-08-26 13:46:32 +02:00
sudo systemctl restart systemd-logind.service
}
install_i3() {
2016-07-01 01:37:22 +02:00
2016-08-26 13:46:32 +02:00
echo "update and installing i3wm and some tools..."
apt-get update
apt-get install -y \
2016-12-05 22:54:47 +01:00
alsa-utils \
2017-03-07 15:35:13 +01:00
clipit \
2017-01-04 23:44:35 +01:00
emacs25 \
feh \
2016-08-26 13:46:32 +02:00
fswebcam \
i3 \
i3lock \
i3status \
2016-12-05 22:54:47 +01:00
keepass2 \
pulseaudio \
rxvt-unicode-256color \
scrot \
2016-12-05 22:54:47 +01:00
shotwell \
slim \
2017-03-07 15:35:13 +01:00
xclip \
2015-12-20 23:49:15 +01:00
xorg \
--no-install-recommends
2016-07-01 01:37:22 +02:00
echo "... DONE... cleaning up\n\n"
apt-get autoremove
apt-get autoclean
apt-get clean
2016-08-26 13:46:32 +02:00
no_suspend
echo "... setting capslock to control"
sed -i "s/^XKBOPTIONS=.*/XKBOPTIONS=\"ctrl:nocaps\"/" /etc/default/keyboard
2015-12-20 23:49:15 +01:00
}
install_docker() {
2016-07-01 01:37:22 +02:00
# https://docs.docker.com/engine/installation/binaries/#install-static-binaries
VERS="17.03.0-ce"
echo "installing docker binary Version $VERS ..."
# https://github.com/tianon/cgroupfs-mount/blob/master/cgroupfs-mount
curl -SL https://get.docker.com/builds/Linux/x86_64/docker-$VERS.tgz \
-o /tmp/docker.tgz
curl -SL https://get.docker.com/builds/Linux/x86_64/docker-$VERS.tgz.sha256 \
-o /tmp/docker.tgz.sha256
if [ ! $(cat /tmp/docker.tgz.sha256 | sha256sum -c -) ]; then
echo "... checksum failed... stopping"
exit 1;
fi
tar -xvzf docker.tgz
mv docker/* /usr/bin
rm /tmp/docker.tgz
rm /tmp/docker.tgz.sha256
sudo groupadd docker
sudo adduser -aG docker "$USERNAME"
# curl -sSL https://get.docker.com/ | sh
# sudo apt-get update
# sudo apt-get install apt-transport-https ca-certificates gnupg2
# sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
2015-12-20 23:49:15 +01:00
# cat <<-EOF > /etc/apt/sources.list.d/docker.list
# deb https://apt.dockerproject.org/repo $REPO main
# EOF
2015-12-20 23:49:15 +01:00
# apt-get update
# apt-cache policy docker-engine
# apt-get update && apt-get install docker-engine
2016-07-01 01:37:22 +02:00
}
install_compose() {
VERS="1.11.2"
2016-07-01 01:37:22 +02:00
echo "installing docker-compose $VERS ... curling from github"
curl -SL https://github.com/docker/compose/releases/download/$VERS/docker-compose-Linux-x86_64 \
2015-12-20 23:49:15 +01:00
-o /usr/bin/docker-compose
chmod +x /usr/bin/docker-compose
2016-07-01 01:37:22 +02:00
echo "... done"
/usr/bin/docker-compose version
}
get_dotfiles() {
(
git clone https://github.com/fschl/dotfiles.git "/home/$USERNAME/dotfiles"
2016-03-08 10:37:50 +01:00
cd "/home/$USERNAME/dotfiles" && make
git clone https://github.com/fschl/dockerfiles.git "/home/$USERNAME/dockerfiles"
2015-12-20 23:49:15 +01:00
git clone https://github.com/fschl/.emacs.d.git "/home/$USERNAME/.emacs.d"
)
}
2016-09-12 11:00:50 +02:00
# install/update golang from source
install_golang() {
export GO_VERSION=1.6.2
export GO_SRC=/usr/local/go
# if we are passing the version
if [[ ! -z "$1" ]]; then
export GO_VERSION=$1
fi
# subshell because we `cd`
(
2016-12-05 22:54:47 +01:00
curl -sSL "https://storage.googleapis.com/golang/go${GO_VERSION}.linux-amd64.tar.gz" | sudo tar -v -C /usr/local -xz
2016-09-12 11:00:50 +02:00
)
# get commandline tools
(
2016-12-05 22:54:47 +01:00
set -x
set +e
go get github.com/golang/lint/golint
go get golang.org/x/tools/cmd/cover
go get golang.org/x/review/git-codereview
go get golang.org/x/tools/cmd/goimports
go get golang.org/x/tools/cmd/gorename
go get github.com/FiloSottile/vendorcheck
go get github.com/nsf/gocode
#done
2016-09-12 11:00:50 +02:00
)
}
get_public_go_projects() {
(
aliases=( Masterminds/glide onsi/ginkgo onsi/gomega gogits/gogs fschl/CompileDaemon )
2016-09-12 11:00:50 +02:00
for project in "${aliases[@]}"; do
owner=$(dirname "$project")
repo=$(basename "$project")
if [[ -d "${HOME}/${repo}" ]]; then
rm -rf "${HOME}/${repo}"
fi
mkdir -p "${GOPATH}/src/github.com/${owner}"
if [[ ! -d "${GOPATH}/src/github.com/${project}" ]]; then
(
# clone the repo
cd "${GOPATH}/src/github.com/${owner}"
git clone "https://github.com/${project}.git"
# fix the remote path, since our gitconfig will make it git@
cd "${GOPATH}/src/github.com/${project}"
git remote set-url origin "https://github.com/${project}.git"
)
else
echo "found ${project} already in gopath"
fi
# make sure we create the right git remotes
# if [[ "$owner" != "fschl" ]]; then
# (
# cd "${GOPATH}/src/github.com/${project}"
# git remote set-url --push origin no_push
# git remote add jfrazelle "https://github.com/fschl/${repo}.git"
# )
# fi
# create the alias
# ln -snvf "${GOPATH}/src/github.com/${project}" "${HOME}/${repo}"
done
# create symlinks from personal projects to
# the ${HOME} directory
projectsdir=$GOPATH/src/github.com/fschl
base=$(basename "$projectsdir")
find "$projectsdir" -maxdepth 1 -not -name "$base" -type d -print0 | while read -d '' -r dir; do
base=$(basename "$dir")
ln -snvf "$dir" "${HOME}/${base}"
done
)
}
if [ -f "./get_private_stuff.sh" ]; then
2017-01-04 23:44:35 +01:00
source get_private_stuff.sh
fi
2016-09-12 11:00:50 +02:00
main() {
2016-07-01 01:37:22 +02:00
local cmd=$1
2016-07-01 01:37:22 +02:00
if [[ -z "$cmd" ]]; then
2017-01-04 23:44:35 +01:00
echo "Usage: \n base | desktop | server | dotfiles | compose | go"
fi
if [[ $cmd == "compose" ]]; then
install_compose
elif [[ $cmd == "base" ]]; then
2016-07-01 01:37:22 +02:00
apt_sources
2016-07-01 01:37:22 +02:00
base_applications
install_docker
elif [[ $cmd == "dotfiles" ]]; then
get_dotfiles
2016-08-26 13:47:08 +02:00
elif [[ $cmd == "go" ]]; then
install_golang
elif [[ $cmd == "goprojects" ]]; then
get_public_go_projects
2017-01-04 23:44:35 +01:00
elif [[ $cmd == "server" ]]; then
install_server_base
elif [[ $cmd == "desktop" ]]; then
2016-08-26 13:47:08 +02:00
install_i3
2016-07-01 01:37:22 +02:00
fi
2015-12-20 23:49:15 +01:00
}
main "$@"