Skip to content

Commit 9fffb59

Browse files
committed
Minor utils improvements and fixes 🐌
1 parent 171f7a4 commit 9fffb59

File tree

8 files changed

+151
-11
lines changed

8 files changed

+151
-11
lines changed

common/customizations/ubuntu.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Disable guest user and remote login
2-
if command -v lightdm; then
2+
if command -v lightdm &>/dev/null; then
33
sudo mkdir -p "/etc/lightdm/lightdm.conf.d"
44
sudo sh -c 'printf "[SeatDefaults]\nallow-guest=false\n" > /etc/lightdm/lightdm.conf.d/50-no-guest.conf'
55
sudo sh -c 'printf "[SeatDefaults]\ngreeter-show-remote-login=false\n" >/etc/lightdm/lightdm.conf.d/50-no-remote-login.conf'

motd/60-ssl.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ else
2525
statusWarning="!"
2626
fi
2727

28-
if ! command -v openssl &>/dev/null; then
28+
if ! command -v "openssl" &>/dev/null; then
2929
echo -e "Please install ${fg_white}${bold}openssl${normal} to check the expiration dates of SSL certificates."
3030
else
3131
currentTime=$(date +%s)

utils/arch/package-actions.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/bin/bash
22

33
__install_packages() {
4-
if command -v yay; then
4+
if command -v "yay" &>/dev/null; then
55
yay -S $@ # &> /dev/null
66
else
7-
pacman -S $@ # &> /dev/null
7+
sudo pacman -S $@ # &> /dev/null
88
fi
99
}
1010

utils/common/aliases-picker.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pick_aliases() {
1212
local aliases_to_be_sourced=""
1313

1414
exec 3>&1;
15-
local selected_aliases=$(dialog --keep-tite --title 'MOTD' \
15+
local selected_aliases=$(dialog --keep-tite --title 'Aliases' \
1616
--checklist 'Pick which sets of aliases should be enabled:' 20 60 16\
1717
${aliases_files[@]} \
1818
2>&1 1>&3 \

utils/common/functions.sh

+4-3
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ clear_last_line() {
4949
create_backup_directory() {
5050
local backup_directory="$(dirname "${BASH_SOURCE[0]}")/../backups/"
5151
if [ ! -d "${backup_directory}" ]; then
52-
mkdir -p "${backup_directory}" && return 0
52+
mkdir -p "${backup_directory}"
53+
return $?
5354
fi
54-
return 1 # Already exists or error creating
55+
return 99 # Already exists
5556
}
5657

5758
# I was born in MS-DOS.
@@ -120,7 +121,7 @@ stow_and_verify() {
120121
stow_and_verify $@ || ([ -v new_path ] && popd &>/dev/null; return 1)
121122
fi
122123
fi
123-
[ -v new_path ] && popd &>/dev/null
124+
[ -v new_path ] && popd &>/dev/null
124125
return 0
125126
}
126127

utils/common/os.sh

+15-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
guess_platform() {
44
if [ -z "${DETECTED_OS}" ]; then
5-
if type -p lsb_release >/dev/null 2>&1; then
5+
if [ -f "/etc/arch-release" ]; then
6+
export DETECTED_OS="arch"
7+
elif type -p lsb_release >/dev/null 2>&1; then
68
case "$(lsb_release -si)" in
79
"archlinux"|"Arch Linux"|"arch"|"Arch"|"archarm"|"ManjaroLinux")
10+
# deprecate? (in favor of the check above)
811
export DETECTED_OS="arch"
912
;;
10-
"Debian"|"Ubuntu")
13+
"Debian"|"Ubuntu"|"Raspbian")
1114
export DETECTED_OS="debian"
1215
;;
1316
esac
@@ -23,13 +26,22 @@ guess_platform() {
2326
return
2427
}
2528

29+
guess_is_laptop() {
30+
#Linux: sudo dmidecode --string chassis-type
31+
#Mac: sysctl hw.model
32+
return 0
33+
}
34+
2635
# Returns a compatible window manager name or empty
2736
guess_wm() {
2837
local wm=''
2938
local possible_wm=''
3039

3140
# Uses wmctrl, falls back to XDG_CURRENT_DESKTOP
32-
possible_wm="$((wmctrl -m | grep "Name: " || echo "Name: ${XDG_CURRENT_DESKTOP}") | cut -d ' ' -f 2- | tr '[:upper:]' '[:lower:]')"
41+
if command -v "wmctrl" &>/dev/null; then
42+
possible_wm="$(wmctrl -m | grep "Name: ")"
43+
fi
44+
possible_wm="$(cut -d ' ' -f 2- <<<"${possible_wm:-Name: $XDG_CURRENT_DESKTOP}" | tr '[:upper:]' '[:lower:]'))"
3345

3446
if [[ "${possible_wm}" =~ "gnome" ]]; then
3547
wm="gnome"

utils/common/systemd.sh

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/bin/bash
2+
3+
pushd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null || exit 1
4+
5+
TIMERS_DIR="../../timers"
6+
7+
source 'questions.sh'
8+
9+
10+
echo "systemd tweaks 🔧"
11+
printf "‾‾‾‾‾‾‾‾‾‾‾‾‾‾\n\n"
12+
13+
echo "This script is for advanced users, check the source and pay close attention to warnings and errors."
14+
printf "Things may break, tears may be shed.\n\n"
15+
16+
17+
###############################################################################
18+
# NetworkManager-wait-online.service
19+
###############################################################################
20+
# This service may slow down boot and it's usually not needed.
21+
# By masking the service, it can be started if other requires it.
22+
23+
ask_yes_no "Mask NetworkManager-wait-online.service?" $DEFAULT_NO
24+
if answer_was_yes; then
25+
sudo systemctl stop NetworkManager-wait-online.service
26+
sudo systemctl disable NetworkManager-wait-online.service
27+
sudo systemctl mask NetworkManager-wait-online.service
28+
echo "Done."
29+
fi
30+
31+
32+
###############################################################################
33+
# Journal tweaks
34+
###############################################################################
35+
# The journal may grow through time making the system feel slow
36+
37+
ask_yes_no "Limit journal size? (50M)" $DEFAULT_NO
38+
if answer_was_yes; then
39+
sudo mkdir /etc/systemd/journald.conf.d
40+
sudo tee /etc/systemd/journald.conf.d/00-journal-size.conf > /dev/null <<EOT
41+
[Journal]
42+
SystemMaxUse=50M
43+
EOT
44+
45+
echo "Done."
46+
fi
47+
48+
49+
###############################################################################
50+
# ntpd.service
51+
###############################################################################
52+
# FIXME: this is wrong
53+
# This service may slow down boot; if there is a reliable hw clock, it should
54+
# be sufficiently accurate to get things started and sync later on.
55+
#
56+
# It may cause problems with programs that expect a monotonic clock.
57+
# Do not delay this service on a RasPi or on laptops without clock battery.
58+
59+
if command -v "ntpd" &>/dev/null; then
60+
ask_yes_no "Delay ntpd.service start?" $DEFAULT_NO
61+
if answer_was_yes; then
62+
sudo cp "${TIMERS_DIR}/system/delayed-ntpd.target" "/etc/systemd/system/"
63+
sudo cp "${TIMERS_DIR}/system/delayed-ntpd.timer" "/etc/systemd/system/"
64+
sudo systemctl daemon-reload
65+
66+
sudo timedatectl set-ntp 0
67+
68+
sudo systemctl stop ntpd.service
69+
sudo systemctl disable ntpd.service
70+
sudo systemctl disable ntpdate.service
71+
72+
sudo systemctl enable delayed-ntpd.timer
73+
74+
echo "Done."
75+
fi
76+
fi
77+
78+
79+
###############################################################################
80+
# fstab format check
81+
###############################################################################
82+
# If fstab has the old "nobootwait", mounts may be locking the boot sequence.
83+
84+
FSTAB_NOBOOTWAIT=$(grep "nobootwait" /etc/fstab)
85+
if [ -n "$FSTAB_NOBOOTWAIT" ]; then
86+
echo "⚠️ Check your /etc/fstab config! 'nobootwait' is useless."
87+
echo "More info: https://wiki.archlinux.org/title/fstab#Automount_with_systemd"
88+
fi
89+
unset FSTAB_NOBOOTWAIT
90+
91+
92+
# Finish
93+
unset TIMERS_DIR
94+
popd &>/dev/null || exit

utils/common/xrandr-wizard.sh

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
all_except() {
4+
5+
}
6+
7+
xrandr_wizard() {
8+
local asd=""
9+
local displays=()
10+
local primary_display=""
11+
12+
displays=($(xrandr -q|grep " connected"|awk 'BEGIN{ORS=""}{print $1 " "}'))
13+
local display_count="${#displays[@]}"
14+
15+
if [ $display_count -lt 1 ]; then
16+
log ERROR 'No display connected!'
17+
elif [ $display_count -eq 1 ]; then
18+
log DEBUG 'Only one display detected'
19+
primary_display="${displays[0]}"
20+
else
21+
exec 3>&1;
22+
primary_display=$(dialog --keep-tite --title "Primary display" \
23+
--radiolist "Pick which display to set as primary" 16 40 10\
24+
${displays[@]} \
25+
2>&1 1>&3 \
26+
)
27+
exec 3>&-
28+
fi
29+
# pushd "$(dirname "${BASH_SOURCE[0]}")/../../art/prompt/templates/" &> /dev/null
30+
# popd &>/dev/null
31+
}
32+
33+
xrandr_wizard

0 commit comments

Comments
 (0)