debian: use custom packages and remove dry-run
This commit is contained in:
parent
2a77358b1c
commit
076b08c583
1 changed files with 96 additions and 158 deletions
254
debian.sh
254
debian.sh
|
@ -1,39 +1,63 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
USERNAME=fernando
|
USERNAME="fernando"
|
||||||
DOTFILES_URL="https://github.com/fschauen/dotfiles.git"
|
DOTFILES_URL="https://git.schauenburg.me/fernando/dotfiles.git"
|
||||||
|
|
||||||
NEOVIM_VERSION="0.9.5"
|
CUSTOM_APT_KEY_FILE="/etc/apt/keyrings/gitea-fernando.asc"
|
||||||
GIT_DELTA_VERSION="0.16.5"
|
CUSTOM_APT_URL="https://git.schauenburg.me/api/packages/fernando/debian"
|
||||||
LF_VERSION="r31"
|
CUSTOM_APT_KEY="-----BEGIN PGP PUBLIC KEY BLOCK-----
|
||||||
EZA_VERSION="0.18.5"
|
|
||||||
|
|
||||||
STOW_DIR="/usr/local/stow"
|
xsBNBGX4KGoBCADiysyeZjwKmgHQakDpeutLq6glS1dvijb3Bdf9RGfOHwoQUPix
|
||||||
|
uPHv3b0mxfHHa9yRfySCSHNSZmCvMDztMpDKjfUKzNwj0ufd+b8vqZ9IIhD323/2
|
||||||
|
cCGpL76ARhGHaQrcfCyjU1bFnNmTRykjXvEPWiNLu9REYd18rPcwGOrITJYfevpj
|
||||||
|
NWdb+scpcMBIoob9NxkvN8V7tRvTsKnHfu6BqU22NobN2kRnqoqQ+IwDhchgrD8s
|
||||||
|
XDZCOiiL/cd3GAHyNsJ1Xu6M87Q/2YT1OHU26I2nWQuoxAHpO/wswD5lOhphUMUc
|
||||||
|
vMvzJNmwmGcHkhZdFZ/YdU0p/BNRQh+65bCNABEBAAHNEShEZWJpYW4gUmVnaXN0
|
||||||
|
cnkpwsBiBBMBCAAWBQJl+ChqCRANOnSUcFcewAIbAwIZAQAA3MUIAIF5jt1LUjQz
|
||||||
|
Cs1ucVEYOTsXVkbHQUyzDX7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||||
|
aN1GalvZk/HY3MUqPHklGF03OAn5YT2mimB6tgMpSoxwaaaIfXmUE4seqhA1wmpc
|
||||||
|
GwM1x9G/T3ZMkaV4wgEZ80RoEFRMtq2l2su/yzrYoeBkNI1h6oU9lkvd
|
||||||
|
=aOC5
|
||||||
|
-----END PGP PUBLIC KEY BLOCK-----
|
||||||
|
"
|
||||||
|
|
||||||
if [ -t 1 ]; then
|
if [ -t 1 ]; then
|
||||||
sgr0="$(printf '\033[0m')"
|
sgr0="$(printf '\033[0m')"
|
||||||
red="$(printf '\033[31m')"
|
red="$(printf '\033[31m')"
|
||||||
green="$(printf '\033[32m')"
|
# green="$(printf '\033[32m')"
|
||||||
yellow="$(printf '\033[33m')"
|
yellow="$(printf '\033[33m')"
|
||||||
blue="$(printf '\033[34m')"
|
blue="$(printf '\033[34m')"
|
||||||
magenta="$(printf '\033[35m')"
|
# magenta="$(printf '\033[35m')"
|
||||||
cyan="$(printf '\033[36m')"
|
# cyan="$(printf '\033[36m')"
|
||||||
else
|
else
|
||||||
sgr0=''
|
sgr0=''
|
||||||
red=''
|
red=''
|
||||||
green=''
|
# green=''
|
||||||
yellow=''
|
yellow=''
|
||||||
blue=''
|
blue=''
|
||||||
magenta=''
|
# magenta=''
|
||||||
cyan=''
|
# cyan=''
|
||||||
fi
|
fi
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
echo "Usage: $(basename "$0") [-h] [-n]"
|
echo "Usage: $(basename "$0") [-h]"
|
||||||
echo ""
|
echo ""
|
||||||
echo " -h print this help and exit"
|
echo " -h print this help and exit"
|
||||||
echo " -n perform dry run"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
error() {
|
error() {
|
||||||
|
@ -41,37 +65,50 @@ error() {
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
heading(){
|
title() {
|
||||||
echo "${blue}===== ${1} ==========${sgr0}"
|
echo "${blue}=> ${1}${sgr0}"
|
||||||
}
|
}
|
||||||
|
|
||||||
skipped() {
|
skipped() {
|
||||||
echo "${yellow}SKIPPED:${sgr0} ${1}"
|
echo "${yellow}SKIPPED:${sgr0} ${1}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
apt_custom_source() {
|
||||||
|
title "Set up custom APT source"
|
||||||
|
|
||||||
|
echo "${CUSTOM_APT_KEY}" >"${CUSTOM_APT_KEY_FILE}"
|
||||||
|
sed \
|
||||||
|
-i.original \
|
||||||
|
-e "1i deb [signed-by=${CUSTOM_APT_KEY_FILE}] ${CUSTOM_APT_URL} stable main\n\n" \
|
||||||
|
/etc/apt/sources.list
|
||||||
|
}
|
||||||
|
|
||||||
apt_install() {
|
apt_install() {
|
||||||
$cmd apt update
|
title "Install APT packages"
|
||||||
$cmd apt install -y \
|
|
||||||
|
apt update && apt install -y \
|
||||||
apt-file \
|
apt-file \
|
||||||
ascii \
|
ascii \
|
||||||
|
broot \
|
||||||
build-essential \
|
build-essential \
|
||||||
ca-certificates \
|
ca-certificates \
|
||||||
cmake \
|
cmake \
|
||||||
cmake-doc \
|
cmake-doc \
|
||||||
curl \
|
curl \
|
||||||
exa \
|
|
||||||
exuberant-ctags \
|
exuberant-ctags \
|
||||||
|
eza \
|
||||||
fd-find \
|
fd-find \
|
||||||
fzf \
|
|
||||||
g++ \
|
g++ \
|
||||||
gcc \
|
gcc \
|
||||||
git \
|
git \
|
||||||
git-crypt \
|
git-crypt \
|
||||||
|
git-delta \
|
||||||
gnupg \
|
gnupg \
|
||||||
htop \
|
htop \
|
||||||
jq \
|
jq \
|
||||||
make \
|
make \
|
||||||
man-db \
|
man-db \
|
||||||
|
neovim \
|
||||||
nodejs \
|
nodejs \
|
||||||
pkg-config \
|
pkg-config \
|
||||||
psmisc \
|
psmisc \
|
||||||
|
@ -86,117 +123,45 @@ apt_install() {
|
||||||
tmux \
|
tmux \
|
||||||
unzip \
|
unzip \
|
||||||
zsh
|
zsh
|
||||||
$cmd apt-file update
|
apt-file update
|
||||||
|
}
|
||||||
|
|
||||||
|
stow_custom_packages() {
|
||||||
|
title "Stow custom packages under /usr/local/stow"
|
||||||
|
(
|
||||||
|
cd /usr/local/stow
|
||||||
|
for package in ./*; do
|
||||||
|
stow -v "${package##*/}"
|
||||||
|
done
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
grub_disable_timeout() {
|
grub_disable_timeout() {
|
||||||
$cmd sed -i.original -e 's/^GRUB_TIMEOUT=.*/GRUB_TIMEOUT=0/' /etc/default/grub
|
title "Disable GRUB timeout"
|
||||||
$cmd update-grub
|
|
||||||
|
sed -i.original -e 's/^GRUB_TIMEOUT=.*/GRUB_TIMEOUT=0/' /etc/default/grub
|
||||||
|
update-grub
|
||||||
}
|
}
|
||||||
|
|
||||||
# Make `fd` available with the correct name.
|
|
||||||
ensure_usr_bin_fd() {
|
ensure_usr_bin_fd() {
|
||||||
if [ -x /usr/bin/fdfind ]; then
|
title "Make 'fd' available with the correct name"
|
||||||
$cmd ln -svf /usr/bin/fdfind /usr/local/bin/fd
|
|
||||||
|
fd_executable='/usr/local/bin/fdfind'
|
||||||
|
if [ -x "${fd_executable}" ]; then
|
||||||
|
ln -svf "${fd_executable}" /usr/local/bin/fd
|
||||||
else
|
else
|
||||||
skipped "/usr/bin/fdfind does not exist"
|
skipped "${fd_executable} does not exist"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Make sure we have directories for all man page sections (for stow).
|
|
||||||
ensure_usr_local_man_manN() {
|
ensure_usr_local_man_manN() {
|
||||||
$cmd mkdir -vp $(seq -f '/usr/local/man/man%.0f' 9)
|
title "Make sure we have directories for all man page sections"
|
||||||
}
|
mkdir -vp $(seq -f '/usr/local/man/man%.0f' 9)
|
||||||
|
|
||||||
# Download $1 to $2, if $2 not already available.
|
|
||||||
download() {
|
|
||||||
if [ -f "$2" ]; then
|
|
||||||
echo "Using locally available $2"
|
|
||||||
else
|
|
||||||
echo "Downloading $1 -> $2"
|
|
||||||
$cmd curl -SL -o "$2" "$1"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
stow_install() {
|
|
||||||
$cmd mv -v "$1" "${STOW_DIR}/"
|
|
||||||
$cmd stow -v -d "${STOW_DIR}" -t /usr/local "$1"
|
|
||||||
}
|
|
||||||
|
|
||||||
install_neovim() {
|
|
||||||
nvim_url="https://github.com/neovim/neovim/releases/download/v${NEOVIM_VERSION}/nvim-linux64.tar.gz"
|
|
||||||
nvim_tarball="nvim-${NEOVIM_VERSION}.tar.gz"
|
|
||||||
nvim_package="nvim-${NEOVIM_VERSION}"
|
|
||||||
nvim_installation="${STOW_DIR}/${nvim_package}"
|
|
||||||
|
|
||||||
if [ -d "${nvim_installation}" ]; then
|
|
||||||
skipped "${nvim_installation} exists"
|
|
||||||
elif ! download "${nvim_url}" "${nvim_tarball}"; then
|
|
||||||
skipped "${nvim_tarball} not available and failed to download ${nvim_url}"
|
|
||||||
else
|
|
||||||
$cmd tar --transform="s/^nvim-linux64/${nvim_package}/" -xf "${nvim_tarball}"
|
|
||||||
$cmd rm -vf "${nvim_tarball}"
|
|
||||||
|
|
||||||
# Remove stuff I don't want and patch the `man` location for Debian.
|
|
||||||
$cmd rm -rf $(printf "${nvim_package}/share/%s " applications icons locale)
|
|
||||||
$cmd mv -v "${nvim_package}/man" "${nvim_package}/share/"
|
|
||||||
|
|
||||||
stow_install "${nvim_package}"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
install_git_delta() {
|
|
||||||
delta_url="https://github.com/dandavison/delta/releases/download/${GIT_DELTA_VERSION}/git-delta-musl_${GIT_DELTA_VERSION}_amd64.deb"
|
|
||||||
delta_deb="git-delta-musl_${GIT_DELTA_VERSION}_amd64.deb"
|
|
||||||
delta_bin="/usr/bin/delta"
|
|
||||||
|
|
||||||
if [ -f "${delta_bin}" ]; then
|
|
||||||
skipped "${delta_bin} exists"
|
|
||||||
elif ! download "${delta_url}" "${delta_deb}"; then
|
|
||||||
skipped "${delta_deb} not available and failed to download ${delta_url}"
|
|
||||||
else
|
|
||||||
$cmd dpkg -i "${delta_deb}"
|
|
||||||
$cmd rm -vf "${delta_deb}"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
install_lf() {
|
|
||||||
lf_url="https://github.com/gokcehan/lf/releases/download/${LF_VERSION}/lf-linux-amd64.tar.gz"
|
|
||||||
lf_tarball="lf-${LF_VERSION}.tar.gz"
|
|
||||||
lf_package="lf-${LF_VERSION}"
|
|
||||||
lf_installation="${STOW_DIR}/${lf_package}"
|
|
||||||
|
|
||||||
if [ -d "${lf_installation}" ]; then
|
|
||||||
skipped "${lf_installation} exists"
|
|
||||||
elif ! download "${lf_url}" "${lf_tarball}"; then
|
|
||||||
skipped "${lf_tarball} not available and failed to download ${lf_url}"
|
|
||||||
else
|
|
||||||
$cmd tar -xf "${lf_tarball}"
|
|
||||||
$cmd rm -vf "${lf_tarball}"
|
|
||||||
|
|
||||||
$cmd mkdir -vp "${lf_package}/bin"
|
|
||||||
$cmd mv -v lf "${lf_package}/bin/lf"
|
|
||||||
|
|
||||||
stow_install "${lf_package}"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
install_eza() {
|
|
||||||
eza_url="http://deb.gierens.de/pool/main/e/eza/eza_${EZA_VERSION}_amd64.deb"
|
|
||||||
eza_deb="eza_${EZA_VERSION}_amd64.deb"
|
|
||||||
eza_bin="/usr/bin/eza"
|
|
||||||
|
|
||||||
if [ -f "${eza_bin}" ]; then
|
|
||||||
skipped "${eza_bin} exists"
|
|
||||||
elif ! download "${eza_url}" "${eza_deb}"; then
|
|
||||||
skipped "${eza_deb} not available and failed to download ${eza_url}"
|
|
||||||
else
|
|
||||||
$cmd dpkg -i "${eza_deb}"
|
|
||||||
$cmd rm -vf "${eza_deb}"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
user_setup() {
|
user_setup() {
|
||||||
|
title "Setup user: $1"
|
||||||
|
|
||||||
if user_exists "$1"; then
|
if user_exists "$1"; then
|
||||||
echo "User $1 exists. Updating..."
|
echo "User $1 exists. Updating..."
|
||||||
user_update "$1"
|
user_update "$1"
|
||||||
|
@ -215,7 +180,7 @@ user_exists() {
|
||||||
user_new() {
|
user_new() {
|
||||||
empty_skel="$(mktemp -d)"
|
empty_skel="$(mktemp -d)"
|
||||||
|
|
||||||
$cmd useradd \
|
useradd \
|
||||||
-m ` # Create home directory.` \
|
-m ` # Create home directory.` \
|
||||||
-k "$empty_skel" ` # Copy files from this directory into the new home.` \
|
-k "$empty_skel" ` # Copy files from this directory into the new home.` \
|
||||||
-U ` # Create a groups with the same name as the user.` \
|
-U ` # Create a groups with the same name as the user.` \
|
||||||
|
@ -230,72 +195,45 @@ user_new() {
|
||||||
# Add user $1 to the `staff` group...
|
# Add user $1 to the `staff` group...
|
||||||
# ...and change shell to `zsh` and get rid of bash files.
|
# ...and change shell to `zsh` and get rid of bash files.
|
||||||
user_update() {
|
user_update() {
|
||||||
$cmd usermod -aG staff "$1"
|
usermod -aG staff "$1"
|
||||||
$cmd chsh -s /bin/zsh "$1"
|
chsh -s /bin/zsh "$1"
|
||||||
$cmd rm -vf $(printf "/home/$1/%s " .bash_history .bash_logout .bashrc .profile)
|
rm -vf "$(printf "/home/$1/%s " .bash_history .bash_logout .bashrc .profile)"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Allow `sudo` without password for user $1.
|
# Allow `sudo` without password for user $1.
|
||||||
user_allow_sudo_nopasswd() {
|
user_allow_sudo_nopasswd() {
|
||||||
$cmd echo "$1 ALL=(ALL:ALL) NOPASSWD:ALL" | \
|
echo "$1 ALL=(ALL:ALL) NOPASSWD:ALL" >"/etc/sudoers.d/${1}_nopasswd"
|
||||||
$pipe_cmd dd status=none of="/etc/sudoers.d/${1}_nopasswd"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
deploy_dotfiles() {
|
deploy_dotfiles() {
|
||||||
dotfiles_dir="/home/$USERNAME/.dotfiles"
|
title "Deploy dotfiles"
|
||||||
|
|
||||||
|
dotfiles_dir="/home/$USERNAME/.dotfiles"
|
||||||
if [ -d "${dotfiles_dir}" ]; then
|
if [ -d "${dotfiles_dir}" ]; then
|
||||||
skipped "${dotfiles_dir} exists"
|
skipped "${dotfiles_dir} exists"
|
||||||
else
|
else
|
||||||
$cmd su "$USERNAME" -c "git clone $DOTFILES_URL ${dotfiles_dir}"
|
su "$USERNAME" -c "git clone $DOTFILES_URL ${dotfiles_dir}"
|
||||||
(
|
(
|
||||||
$cmd cd "${dotfiles_dir}"
|
cd "${dotfiles_dir}"
|
||||||
$cmd su "$USERNAME" -c "./install.sh -y"
|
su "$USERNAME" -c "./install.sh -y"
|
||||||
)
|
)
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
execute() {
|
execute() {
|
||||||
heading "Install APT packages"
|
apt_custom_source
|
||||||
apt_install
|
apt_install
|
||||||
|
stow_custom_packages
|
||||||
heading "Disable GRUB timeout"
|
|
||||||
grub_disable_timeout
|
grub_disable_timeout
|
||||||
|
|
||||||
heading "Filesystem tweaks"
|
|
||||||
ensure_usr_bin_fd
|
ensure_usr_bin_fd
|
||||||
ensure_usr_local_man_manN
|
ensure_usr_local_man_manN
|
||||||
|
|
||||||
heading "Install neovim v$NEOVIM_VERSION"
|
|
||||||
install_neovim # Must come after `ensure_usr_local_man_manN`.
|
|
||||||
|
|
||||||
heading "Install git-delta v$GIT_DELTA_VERSION"
|
|
||||||
install_git_delta
|
|
||||||
|
|
||||||
heading "Install lf v$LF_VERSION"
|
|
||||||
install_lf
|
|
||||||
|
|
||||||
heading "Install exa v$EZA_VERSION"
|
|
||||||
install_eza
|
|
||||||
|
|
||||||
heading "Setup user: $USERNAME"
|
|
||||||
user_setup "$USERNAME"
|
user_setup "$USERNAME"
|
||||||
|
|
||||||
heading "Deploy dotfiles"
|
|
||||||
deploy_dotfiles
|
deploy_dotfiles
|
||||||
}
|
}
|
||||||
|
|
||||||
do_pipe_cmd() { cat; echo "| $@"; }
|
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
while getopts 'hn' opt; do
|
while getopts 'hn' opt; do
|
||||||
case "$opt" in
|
case "$opt" in
|
||||||
n) # dry run
|
|
||||||
cmd=echo
|
|
||||||
pipe_cmd=do_pipe_cmd
|
|
||||||
execute
|
|
||||||
exit 0
|
|
||||||
;;
|
|
||||||
h) # help
|
h) # help
|
||||||
usage
|
usage
|
||||||
exit 0
|
exit 0
|
||||||
|
@ -311,5 +249,5 @@ main() {
|
||||||
execute
|
execute
|
||||||
}
|
}
|
||||||
|
|
||||||
main $@
|
main "$@"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue