dotfiles/scripts/install.sh

499 lines
13 KiB
Bash
Raw Normal View History

#!/bin/bash
set -e
# install.sh
2018-06-02 17:17:16 +02:00
# This script installs my basic setup for a debian machine
USERNAME=fschl
2018-10-23 18:22:03 +02:00
SUDO="sudo"
check_root() {
# We need root rights at some point
if [ "$(whoami)" != "root" ]; then
2019-01-02 12:42:16 +01:00
if ! which $SUDO >/dev/null; then
echo "ERROR: $0 is not run as root and $SUDO is not available" >&2
exit 1
fi
2018-10-23 18:22:03 +02:00
else
2019-01-02 12:42:16 +01:00
SUDO="" # We're already root
2018-10-23 18:22:03 +02:00
fi
}
apt_sources() {
2018-10-23 18:22:03 +02:00
# http://deb.debian.org/
ddist=$1
DIST="${ddist:-stable}"
2019-01-02 12:42:16 +01:00
allowed_dists=("testing stable stretch buster")
if [ ! ${DIST} in "${allowed_dists[@]}" ]; then
echo "... $DIST was not in allowed dists... setting to stable"
DIST="stable"
2018-06-14 09:51:51 +02:00
fi
2019-01-02 12:42:16 +01:00
echo "writing /etc/apt/sources.list..."
echo "using ${DIST}"
cat <<-EOF > /etc/apt/sources.list
deb http://deb.debian.org/debian ${DIST} main
deb-src http://deb.debian.org/debian ${DIST} main
deb http://deb.debian.org/debian-security/ ${DIST}/updates main
deb-src http://deb.debian.org/debian-security/ ${DIST}/updates main
deb http://deb.debian.org/debian ${DIST}-updates main
deb-src http://deb.debian.org/debian ${DIST}-updates main
EOF
}
base_applications() {
2016-07-01 01:37:22 +02:00
echo "update and installing baseapps..."
2018-10-23 18:22:03 +02:00
$SUDO apt update
$SUDO apt upgrade
DEBIAN_FRONTEND=noninteractive
2018-10-23 18:22:03 +02:00
$SUDO apt install -y \
apt-transport-https \
automake \
bash-completion \
bmon \
bzip2 \
ca-certificates \
cmake \
coreutils \
2018-11-12 11:48:01 +01:00
cryptsetup \
curl \
dnsutils \
gcc \
git \
gnupg \
2019-01-02 12:42:16 +01:00
gnupg-agent \
2018-05-28 19:55:53 +02:00
gnupg2 \
grep \
htop \
iotop \
locales \
make \
mount \
net-tools \
rsync \
ssh \
sudo \
tar \
tmux \
tree \
2018-11-12 11:48:01 +01:00
unzip \
vim \
vpnc \
vpnc-scripts \
zip \
--no-install-recommends
2016-07-01 01:37:22 +02:00
echo "... DONE... cleaning up\n\n"
2018-10-23 18:22:03 +02:00
$SUDO apt autoremove
$SUDO apt autoclean
$SUDO apt clean
2017-01-04 23:44:35 +01:00
}
install_server_base() {
echo "update and installing server base tools..."
DEBIAN_FRONTEND=noninteractive
apt update
apt install -y \
fail2ban \
logwatch \
unattended-upgrades \
--no-install-recommends
2017-01-04 23:44:35 +01:00
echo "... DONE... cleaning up\n\n"
apt autoremove
apt autoclean
apt clean
2017-01-04 23:44:35 +01:00
echo "setting up logwatch..."
2019-01-02 12:42:16 +01:00
echo "... TODO require email to be set as parameter"
echo "... TODO require email to be set as parameter"
2017-01-04 23:44:35 +01:00
cat <<-EOF > /etc/cron.daily/00logwatch
/usr/sbin/logwatch --output mail --mailto you@example.com --detail high
EOF
echo " ... DONE"
2019-01-02 12:42:16 +01:00
# TODO: is this really needed? or default behavior anyway?
2017-01-04 23:44:35 +01:00
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
}
2016-08-26 13:46:32 +02:00
no_suspend() {
# https://wiki.debian.org/SystemdSuspendSedation
2018-10-23 18:22:03 +02:00
$SUDO sed -i "s/HandleLidSwitch=.*/HandleLidSwitch=ignore/" /etc/systemd/logind.conf
$SUDO sed -i "s/HandleLidSwitchDocked=.*/HandleLidSwitchDocked=ignore/" /etc/systemd/logind.conf
$SUDO sed -i "s/IdleActionSec=.*/IdleActionSec=90min/" /etc/systemd/logind.conf
2016-09-12 11:00:50 +02:00
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
2018-10-23 18:22:03 +02:00
$SUDO systemctl restart systemd-logind.service
2016-08-26 13:46:32 +02:00
}
2018-11-12 11:48:09 +01:00
install_nvidia_docker() {
# get latest driver from https://www.nvidia.com/object/unix.html
# https://github.com/NVIDIA/nvidia-docker/wiki/Installation-(version-2.0)#prerequisites
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | \
sudo tee /etc/apt/sources.list.d/nvidia-docker.list
sudo apt-get update
# Install nvidia-docker2 and reload the Docker daemon configuration
sudo apt-get install -y nvidia-docker2
sudo pkill -SIGHUP dockerd
}
2019-01-02 12:42:16 +01:00
2019-01-14 23:28:37 +01:00
install_latex() {
apt update
apt install -y \
evince \
texlive \
texlive-bibtex-extra \
texlive-lang-english \
texlive-lang-german \
texlive-latex-extra \
texlive-latex-recommended \
texlive-pictures \
--no-install-recommends
}
install_i3() {
2016-08-26 13:46:32 +02:00
echo "update and installing i3wm and some tools..."
# check if CJK and other eastern letters are displayed correctly:
# https://meta.wikimedia.org/wiki/List_of_Wikipedias
2018-06-14 09:45:13 +02:00
# tlp: Advanced Linux Power Management
# http://linrunner.de/en/tlp/docs/tlp-linux-advanced-power-management.html
2019-01-02 12:42:16 +01:00
# deb http://repo.linrunner.de/debian sid main
2018-06-14 09:45:13 +02:00
# add the tlp apt-repo gpg key
2019-01-02 12:42:16 +01:00
# apt-key adv --keyserver pool.sks-keyservers.net --recv-keys CD4E8809
2018-06-14 09:45:13 +02:00
DEBIAN_FRONTEND=noninteractive
# TODO add non-free to apt/sources.list
apt update
apt install -y \
alsa-utils \
2018-05-28 19:55:53 +02:00
aspell \
aspell-de \
aspell-en \
2018-12-22 20:09:58 +01:00
emacs \
feh \
2019-01-02 12:42:16 +01:00
firefox-esr \
firmware-iwlwifi \
firmware-linux-nonfree \
firmware-realtek \
2018-05-28 19:55:53 +02:00
fonts-font-awesome \
fonts-noto \
fonts-noto-cjk \
fswebcam \
gimp \
i3 \
i3lock \
2019-01-02 12:42:16 +01:00
i3lock-fancy \
i3status \
2018-12-27 23:36:11 +01:00
keepassxc \
2019-01-14 23:28:37 +01:00
libreoffice-calc \
libreoffice-impress \
libreoffice-l10n-de \
libreoffice-l10n-en-gb \
2019-03-22 16:27:40 +01:00
libreoffice-writer \
network-manager-gnome \
network-manager-vpnc \
network-manager-vpnc-gnome \
2019-03-22 16:27:40 +01:00
nextcloud-desktop \
ntfs-3g \
2019-02-01 13:57:36 +01:00
nmap \
pulseaudio \
remmina \
rxvt-unicode-256color \
scrot \
shotwell \
slim \
thunderbird \
thunderbird-l10n-de \
thunderbird-l10n-en-gb \
vlc \
xclip \
xorg \
--no-install-recommends
2016-07-01 01:37:22 +02:00
echo "... DONE... cleaning up\n\n"
apt autoremove
apt autoclean
apt clean
2016-08-26 13:46:32 +02:00
TARGET="/home/$USERNAME/.emacs.d"
git clone https://github.com/syl20bnr/spacemacs "${TARGET}"
rm -rf "${TARGET}"/private/snippets
git clone https://github.com/AndreaCrotti/yasnippet-snippets "${TARGET}"/private/yas-snips
ln -s "${TARGET}"/private/yas-snips/snippets "${TARGET}"/private/snippets/
2018-12-22 20:09:58 +01:00
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() {
# https://docs.docker.com/install/linux/docker-ce/debian/#install-using-the-repository
# bad experiences with static binaries...
# https://docs.docker.com/engine/installation/binaries/#install-static-binaries
echo "installing docker binary Version $VERS ..."
# https://github.com/tianon/cgroupfs-mount/blob/master/cgroupfs-mount
2018-10-23 18:22:03 +02:00
apt install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg2 \
2018-10-23 18:22:03 +02:00
software-properties-common \
--no-install-recommends
2018-10-23 18:22:03 +02:00
curl -fsSL https://download.docker.com/linux/debian/gpg | $SUDO apt-key add -
# add docker apt repo
cat <<-EOF > /etc/apt/sources.list.d/docker.list
deb [arch=amd64] https://download.docker.com/linux/debian stretch stable
# deb [arch=amd64] https://download.docker.com/linux/debian stretch test
# deb [arch=amd64] https://download.docker.com/linux/debian stretch nightly
EOF
2018-10-23 18:22:03 +02:00
apt update
apt install -y \
docker-ce \
--no-install-recommends
addgroup ${USERNAME} docker
2018-10-23 18:22:03 +02:00
docker version
docker info
2016-07-01 01:37:22 +02:00
}
install_compose() {
2017-03-07 18:05:48 +01:00
# https://github.com/docker/compose/releases
# btw: *not* for raspbian! you got 3 choices: hypriot, install via pip or build yourself
# https://www.berthon.eu/2017/getting-docker-compose-on-raspberry-pi-arm-the-easy-way/
VERS="1.24.1"
FILE="docker-compose-$(uname -s)-$(uname -m)"
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}/${FILE}" -o /tmp/${FILE}
curl -SL "https://github.com/docker/compose/releases/download/${VERS}/${FILE}.sha256" -o /tmp/${FILE}.sha256
if [ ! $(cat /tmp/${FILE}.sha256 | sha256sum -c -) ]; then
echo "... checksum failed... stopping"
exit 1;
fi
2017-03-07 18:05:48 +01:00
chmod +x /tmp/${FILE}
mv /tmp/${FILE} /usr/bin/docker-compose
rm /tmp/${FILE}.sha256
2016-07-01 01:37:22 +02:00
echo "... done"
/usr/bin/docker-compose version
}
2018-12-22 20:09:58 +01:00
install_virtualbox() {
# https://wiki.debian.org/VirtualBox#Installation_of_non-free_edition
apt install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg2 \
software-properties-common \
--no-install-recommends
curl -fsSL https://download.docker.com/linux/debian/gpg | $SUDO apt-key add -
# add docker apt repo
cat <<-EOF > /etc/apt/sources.list.d/docker.list
deb [arch=amd64] https://download.docker.com/linux/debian stretch stable
# deb [arch=amd64] https://download.docker.com/linux/debian stretch test
# deb [arch=amd64] https://download.docker.com/linux/debian stretch nightly
EOF
apt update
apt install -y \
docker-ce \
--no-install-recommends
groupadd docker
addgroup ${USERNAME} docker
docker version
docker info
}
get_dotfiles() {
(
2017-03-16 14:49:27 +01:00
# git clone https://gitlab.com/fschl/dotfiles.git "/home/$USERNAME/dotfiles"
# cd "/home/$USERNAME/dotfiles" && make
2017-03-16 14:49:27 +01:00
# TODO: propbably dont really need the whole repo
git clone https://gitlab.com/fschl/dockerfiles.git "/home/$USERNAME/dockerfiles"
)
}
2016-09-12 11:00:50 +02:00
# install/update golang from source
install_golang() {
2018-11-12 11:47:43 +01:00
export GO_VERSION=1.11.2
2016-09-12 11:00:50 +02:00
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`
(
2018-10-23 18:22:03 +02: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
2018-11-12 11:47:43 +01:00
go get -u -v github.com/rogpeppe/godef
go get -u -v golang.org/x/tools/cmd/guru
go get -u -v golang.org/x/tools/cmd/gorename
go get -u -v golang.org/x/tools/cmd/goimports
go get github.com/mdempsky/gocode
2016-12-05 22:54:47 +01:00
#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
2017-03-16 14:49:27 +01:00
projectsdir=$GOPATH/src/gitlab.com/fschl
2016-09-12 11:00:50 +02:00
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
2018-06-02 17:17:16 +02:00
echo "Usage: \n base | desktop | server | dotfiles | update-docker | go"
2017-01-04 23:44:35 +01:00
fi
2018-06-02 17:17:16 +02:00
case "$cmd" in
base)
apt_sources buster
2018-06-02 17:17:16 +02:00
base_applications
install_docker
install_compose
;;
dotfiles)
get_dotfiles
;;
server)
install_server_base
;;
desktop)
# apt_sources buster
base_applications
install_docker
install_compose
2018-06-02 17:17:16 +02:00
install_i3
if [ -f "./get_private_stuff.sh" ]; then
source get_private_stuff.sh
fi
;;
2019-01-14 23:28:37 +01:00
latex)
install_latex
;;
2018-06-02 17:17:16 +02:00
update-docker)
# install_docker
install_compose
;;
go)
install_golang
2018-11-12 11:47:43 +01:00
# get_public_go_projects
2018-06-02 17:17:16 +02:00
;;
esac
}
main "$@"