This commit is contained in:
manuel-192
2022-03-18 16:52:35 +02:00
parent 5c08081328
commit fd84091e2f
-255
View File
@@ -1,255 +0,0 @@
#!/bin/bash
ERROR() { echo "==> Error: $1" ; }
INFO() { echo "==> Info: $1" ; }
Check() {
"$@" || {
ERROR "'$*' failed"
exit 0
}
}
BashrcConfig() {
[ -n "$new_user" ] || return
cat <<EOF >> $home/.bashrc
alias l='ls -la --ignore=.?*'
alias ll='ls -la --ignore=..'
alias cp='cp -i'
alias mv='mv -i'
alias rm='rm -i'
alias ln='ln -i'
alias PP='pac -Syu'
alias nano='nano -l'
alias pacdiff=eos-pacdiff
alias poweroff='sync; poweroff'
alias reboot='sync; reboot'
alias update-grub='sudo grub-mkconfig -o /boot/grub/grub.cfg'
alias df='df -hT'
alias md='vscode -n' # Visual Studio Code as a markdown editor
alias grep='grep -n'
alias sou='source ~/.bashrc' # re-read ~/.bashrc
bind '"\e[A":history-search-backward' # history with arrow up key
bind '"\e[B":history-search-forward' # history with arrow down key
bind 'set show-all-if-ambiguous on' # complete with single TAB
bind 'set mark-symlinked-directories on' # complete directory symlinks with slash
export LESS="-RFn"
PS1='\w> '
EOF
chown $new_user:$new_user $home/.bashrc # not really needed if it already exists
}
EmacsConfig() {
[ -n "$new_user" ] || return
[ -x /usr/bin/emacs ] || return
cat <<EOF > $home/.emacs
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(c-guess-guessed-basic-offset 2 t)
'(column-number-mode t)
'(cua-mode t nil (cua-base))
'(gdb-many-windows t)
'(global-display-line-numbers-mode t)
'(indent-tabs-mode nil)
'(inhibit-startup-screen t)
'(make-backup-files nil)
'(next-line-add-newlines nil)
'(package-selected-packages '(realgud))
'(require-final-newline t)
'(scroll-step 1)
'(select-enable-clipboard t)
'(tool-bar-mode nil)
'(tool-bar-position 'right)
'(vc-follow-symlinks t)
'(x-select-enable-clipboard-manager nil))
EOF
chown $new_user:$new_user $home/.emacs
}
GetNewUserName() {
if [ -z "$new_user" ] ; then
if [ -r /tmp/new_username.txt ] ; then
new_user=$(cat /tmp/new_username.txt)
else
ERROR "new username not found. You can use command: $0 'your-username'"
fi
else
echo "new_user already set to '$new_user'"
fi
}
HomeSettings() {
# Add here some user specific stuff!
if [ -n "$new_user" ] && [ -d $home ] ; then
EmacsConfig
BashrcConfig
else
ERROR "$FUNCNAME failed!"
fi
}
InstallPackages() {
local Install=( # packages to install
akm
atril
vscodium-bin
emacs
firefox-developer-edition
gparted
gufw
# kaffeine
libreoffice-fresh
linux-lts
linux-lts-headers
llpp # fast PDF reader for complex PDF files
mpv
ncdu
pahis
# rcs
simple-scan
solaar
terminator
# m-m
pac
)
Check pacman -Syu --noconfirm --needed "${Install[@]}"
}
RemovePackages() {
Remove=( # packages to remove
glances
parole
file-roller
)
Check pacman -Rsn --noconfirm "${Remove[@]}"
}
Setup3rdPartyRepos() {
local reponames=(
m-m
m-aur
m-more2
)
local reponame
local pacmanconf=/etc/pacman.conf
local m_key="91709405DF6A3A1F4B7EF93FA1F1B5187D25904B"
local repo_added=no
local key_added="$(pacman-key --list-keys 2>/dev/null | grep -w $m_key)"
local need_mirrorlist_pkg=no
if [ -z "$key_added" ] ; then
Check pacman-key --keyserver hkps://keyserver.ubuntu.com --recv-keys $m_key
Check pacman-key --lsign-key $m_key
fi
if ! pacman -Q mirrorlist-m >& /dev/null ; then
Check wget -O /etc/pacman.d/mirrorlist-m https://github.com/manuel-192/m-m/raw/master/PKGBUILDs/mirrorlist-m/mirrorlist-m
need_mirrorlist_pkg=yes
fi
for reponame in "${reponames[@]}" ; do
if [ -z "$(grep "^\[$reponame\]$" $pacmanconf )" ] ; then
cat <<EOF >> "$pacmanconf"
[$reponame]
Include = /etc/pacman.d/mirrorlist-m
SigLevel = Required
EOF
repo_added=yes
INFO "Repository [$reponame] was added to $pacmanconf."
else
INFO "[$reponame] is already set up in $pacmanconf."
fi
done
if [ "$repo_added" = "yes" ] ; then
Check pacman -Syu
fi
if [ "$need_mirrorlist_pkg" = "yes" ] ; then
Check pacman --overwrite '/etc/pacman.d/mirrorlist-m' -Syu --noconfirm mirrorlist-m
fi
}
GrubDefaultEntry() {
local entry="EndeavourOS, on linux"
sed -i /etc/default/grub -e "s|^\(GRUB_DEFAULT=\)0$|\1'$entry'|"
update_grub=yes
}
Blacklist() {
local blacklists="$1"
sed -i /etc/default/grub \
-e "s|^\(GRUB_CMDLINE_LINUX_DEFAULT=\"\)|\1module_blacklist=$blacklists |"
update_grub=yes
}
DriverSettings() {
local lspci=$(lspci -vnn)
local graphics=$(echo "$lspci" | grep -Pw 'VGA|Display|3D')
local rakkine=""
if [ -n "$(echo "$graphics" | grep "8086:0046")" ] && [ -n "$(echo "$graphics" | grep "10de:0a2b")" ] ; then
rakkine=l1
elif [ -n "$(echo "$graphics" | grep "8086:5917")" ] && [ -n "$(echo "$graphics" | grep "1002:6660")" ] ; then
rakkine=l2
elif [ -n "$(echo "$graphics" | grep "10de:1d01")" ] ; then
rakkine=p1
elif [ -n "$(echo "$graphics" | grep "15ad:0405")" ] ; then
rakkine=v1
fi
case "$rakkine" in
l1) Blacklist nouveau
GrubDefaultEntry
Check pacman -S --needed --noconfirm xf86-video-intel xorg-xbacklight
;;
l2) Blacklist radeon,amdgpu
GrubDefaultEntry
Check pacman -S --needed --noconfirm xf86-video-intel xorg-xbacklight
;;
p1) Blacklist nouveau,i915
GrubDefaultEntry
;;
v1) GrubDefaultEntry
;;
esac
}
Main() {
local new_user="$1"
GetNewUserName
local home="/home/$new_user"
local update_grub=no
Setup3rdPartyRepos
RemovePackages
InstallPackages
# enable firewall service
sleep 1
systemctl enable ufw
# modify some dotfiles at $HOME
HomeSettings
DriverSettings
if [ "$update_grub" = "yes" ] ; then
grub-mkconfig -o /boot/grub/grub.cfg
fi
}
Main "$@"