Compare commits

...

2 Commits

Author SHA1 Message Date
Quentin Duchemin 345606b800 Automatic network modules in polybar
When initializing the system (or later launching `~/.config/bootstrap/init_netctl <env>` and `~/.init_config.sh <env>`, each interface is converted in a module and then referenced in the bottom_center variable of the bottom bar.
2024-05-01 12:14:49 +02:00
Quentin Duchemin b1e3ea44f8 Switch from NM to netctl
I did that in the good old days, and I switched to NM because I didn't know then the wifi-menu interface. But, for a sneaky bug I don't understand, all my wireless interfaces became "Unavailable" on all my computers. No matter if I uninstall, reset anything related to NM. So, back to netctl with a nice script to automate connections
2024-05-01 10:29:37 +02:00
8 changed files with 89 additions and 60 deletions

View File

@ -15,6 +15,8 @@ catppuccin-gtk-theme-macchiato
chafa chafa
chromium chromium
cups cups
dhcpcd
dialog
docker docker
dosfstools dosfstools
dkms dkms
@ -33,6 +35,7 @@ hplip
htop htop
i3-wm i3-wm
i3lock-color i3lock-color
ifplugd
imagemagick imagemagick
jq jq
kwayland5 kwayland5
@ -49,10 +52,8 @@ mlocate
nmap nmap
nemo nemo
neofetch neofetch
netctl
neovim neovim
network-manager-applet
networkmanager
nm-connection-editor
noto-fonts-emoji noto-fonts-emoji
numlockx numlockx
obsidian obsidian
@ -99,6 +100,7 @@ vim
vlc vlc
vscodium-bin vscodium-bin
wget wget
wpa_supplicant
xautolock xautolock
xclip xclip
xdg-user-dirs xdg-user-dirs

View File

@ -0,0 +1,56 @@
#!/usr/bin/env bash
# ${1} : environment (see README.md)
module_names=''
echo -e "* Auto-create wired profil, autoconnect service for netctl and polybar module..."
for i in `ip -br l | awk '$1 !~ "lo|vir|br|wl" { print $1}'`; do
echo -e "~ ${i}..."
module_name="network-${i}"
module_names+=" ${module_name}"
cat <<- EOF | sudo tee /etc/netctl/${i} >/dev/null
Interface=${i}
Connection=ethernet
IP=dhcp
EOF
cat <<- EOF | tee ~/.config/polybar/config.d/${i}.${1} >/dev/null
[module/${module_name}]
type = internal/network
interface = ${i}
ping-interval = 3
label-connected = \${env:BAR_WIRED_CONNECTED}
label-disconnected =
label-disconnected-foreground = \${colors.text}
; Consider an 'UNKNOWN' interface state as up.
; Some devices like USB network adapters have
; an unknown state, even when they're running
; Default: false
unknown-as-up = true
EOF
sudo systemctl enable --now netctl-ifplugd@${i}
# In case some old config stays....
sudo systemctl restart netctl-ifplugd@${i}
done
echo -e "* Autoconnect to wireless profiles..."
for i in `ip -br l | awk '$1 ~ "wl" { print $1}'`; do
module_name="network-${i}"
module_names+=" ${module_name}"
echo -e "~ ${i}..."
cat <<- EOF | tee ~/.config/polybar/config.d/${i}.${1} >/dev/null
[module/${module_name}]
type = internal/network
interface = ${i}
ping-interval = 3
label-connected = \${env:BAR_WIFI_CONNECTED}
label-disconnected =
label-disconnected-foreground = \${colors.text}
EOF
sudo systemctl enable --now netctl-auto@${i}
done
echo -e "* Create an override polybar file to add all discovered networks..."
cat << EOF | tee ~/.config/polybar/config.d/bottom_center.${1} >/dev/null
[variables]
bottom_center = updates-arch-combined ${module_names}
EOF
# https://man.archlinux.org/man/netctl.special.7
echo -e "* Ensure connections are back when PC is resumed..."
sudo systemctl enable netctl-sleep

View File

@ -14,8 +14,8 @@ export MOCHA_ROSEWATER="#f2cdcd"
export MOCHA_MAUVE="#ca9ee6" export MOCHA_MAUVE="#ca9ee6"
export MOCHA_TEAL="#81c8be" export MOCHA_TEAL="#81c8be"
export BAR_WINDOW="%{F$MOCHA_TEXT}%title%" export BAR_WINDOW="%{F$MOCHA_TEXT}%title%"
export BAR_WIFI_CONNECTED="%{F$MOCHA_TEXT}%essid% %{F$MOCHA_YELLOW}%{F$MOCHA_TEXT} %local_ip% %{F$MOCHA_YELLOW}%{F$MOCHA_TEXT} %downspeed% %{F$MOCHA_YELLOW}%{F$MOCHA_TEXT} %upspeed%" export BAR_WIFI_CONNECTED="%{F$MOCHA_TEXT}%essid% %{F$MOCHA_YELLOW}%{F$MOCHA_TEXT} %local_ip% %{F$MOCHA_YELLOW}%{F$MOCHA_TEXT} %downspeed% %{F$MOCHA_YELLOW}%{F$MOCHA_TEXT} %upspeed%"
export BAR_WIRED_CONNECTED="%{F$MOCHA_TEXT}%ifname% %{F$MOCHA_YELLOW}%{F$MOCHA_TEXT} %local_ip% %{F$MOCHA_YELLOW}%{F$MOCHA_TEXT} %downspeed% %{F$MOCHA_YELLOW}%{F$MOCHA_TEXT} %upspeed%" export BAR_WIRED_CONNECTED="%{F$MOCHA_TEXT}%ifname% %{F$MOCHA_YELLOW}%{F$MOCHA_TEXT} %local_ip% %{F$MOCHA_YELLOW}%{F$MOCHA_TEXT} %downspeed% %{F$MOCHA_YELLOW}%{F$MOCHA_TEXT} %upspeed%"
export BAR_CPU="%{F$MOCHA_MAUVE} " export BAR_CPU="%{F$MOCHA_MAUVE} "
export BAR_TEMP_OK="%{F$MOCHA_MAUVE} %{F-} %temperature-c%" export BAR_TEMP_OK="%{F$MOCHA_MAUVE} %{F-} %temperature-c%"
export BAR_TEMP_WARN="%{F$MOCHA_PEACH} %{F-} %temperature-c%" export BAR_TEMP_WARN="%{F$MOCHA_PEACH} %{F-} %temperature-c%"

View File

@ -6,7 +6,6 @@ top_center = player-mpris
;top_center = xwindow ;top_center = xwindow
top_right = system-usb-udev date top_right = system-usb-udev date
bottom_left = i3 bottom_left = i3
bottom_center = updates-arch-combined wired-network
bottom_right = temperature cpu memory filesystem-custom bottom_right = temperature cpu memory filesystem-custom
[module/memory] [module/memory]

View File

@ -6,7 +6,6 @@ top_center = player-mpris
;top_center = xwindow ;top_center = xwindow
top_right = system-usb-udev backlight pulseaudio date top_right = system-usb-udev backlight pulseaudio date
bottom_left = i3 bottom_left = i3
bottom_center = updates-arch-combined wireless-network
bottom_right = temperature cpu memory filesystem-custom bottom_right = temperature cpu memory filesystem-custom
[module/memory] [module/memory]

View File

@ -76,26 +76,6 @@ type = internal/xwindow
label = ${env:BAR_WINDOW} label = ${env:BAR_WINDOW}
label-maxlen=100 label-maxlen=100
[module/wireless-network]
type = internal/network
interface-type = wireless
interval = 1
label-connected = ${env:BAR_WIFI_CONNECTED}
label-disconnected = Wireless disconnected
label-disconnected-foreground = ${colors.text}
; Poorly documented and hackish way to have more space between some modules
label-connected-margin = 10
label-disconnected-margin = 10
[module/wired-network]
type = internal/network
interface = enp8s0
interface-type = wired
interval = 1
label-connected = ${env:BAR_WIRED_CONNECTED}
label-disconnected = Ethernet disconnected
label-disconnected-foreground = ${colors.text}
[module/i3] [module/i3]
type = internal/i3 type = internal/i3
format = <label-state> <label-mode> format = <label-state> <label-mode>

View File

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
# Wait for connection
source $(dirname $0)/../.env source $(dirname $0)/../.env
connect=$(ping -q -w 1 -c 1 `ip r | grep default | cut -d ' ' -f 3` &> /dev/null) connect=$(ping -q -w 1 -c 1 8.8.8.8 &> /dev/null)
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
updates_arch=$(/usr/bin/checkupdates | wc -l) updates_arch=$(/usr/bin/checkupdates | wc -l)
# a restricts to AUR packages # a restricts to AUR packages

View File

@ -50,27 +50,24 @@ function check_copy() {
# with an optional `$1/config.d/$2` file. This is useful for having # with an optional `$1/config.d/$2` file. This is useful for having
# a common base for multiple computer, and per-computer stuff. # a common base for multiple computer, and per-computer stuff.
# $1 : path of the folder # $1 : path of the folder
# $2 : optional current environment # $2 : current environment
# $3 : if defined, prepend $2 instead of appending # $3 : if defined, prepend $2 instead of appending
function merge_config() { function merge_config() {
echo -e "\n=== Generate ${m} config file ===" echo -e "\n=== Generate ${m} config file ==="
rm -f ${CONFIG}/${m}/${FINAL_CONFIG} final_path=${CONFIG}/${m}/${FINAL_CONFIG}.${2}
rm -f ${final_path}
# Copy common config # Copy common config
cp ${CONFIG}/${m}/${BASE_CONFIG} ${CONFIG}/${m}/${FINAL_CONFIG} cp ${CONFIG}/${m}/${BASE_CONFIG} ${final_path}
echo "${CONFIG}/${m}/${FINAL_CONFIG} created" echo "${final_path} created"
# If there is an override folder, merge given env # If there is an override folder, merge given env
if [ ! -z ${2} ] && [ -d ${CONFIG}/${m}/${MERGE_CONFIG_FOLDER} ]; then if [ ! -z ${2} ] && [ -d ${CONFIG}/${m}/${MERGE_CONFIG_FOLDER} ]; then
for f in `find ${CONFIG}/${m}/config.d -type f -path "*${2}"`; do for f in `find ${CONFIG}/${m}/config.d -type f -path "*${2}"`; do
final_path=${CONFIG}/${m}/${FINAL_CONFIG}
if [ -z $3 ]; then if [ -z $3 ]; then
echo "Found ${f}, append to regular config file" echo "Found ${f}, append to regular config file"
cat "${f}" >> ${final_path} echo -e "\n$(cat ${f})\n" >> ${final_path}
else else
echo "Found ${f}, prepend to regular config file" echo "Found ${f}, prepend to regular config file"
cat ${f} > /tmp/config echo -e "\n$(cat ${f})\n$(cat ${final_path})\n" > ${final_path}
echo -e '\n' >> /tmp/config
cat ${final_path} >> /tmp/config
mv /tmp/config ${final_path}
fi fi
done done
fi fi
@ -94,15 +91,13 @@ function init_system() {
# https://man.archlinux.org/man/rofi-dmenu.5 # https://man.archlinux.org/man/rofi-dmenu.5
echo -e "* Symlink dmenu → rofi..." echo -e "* Symlink dmenu → rofi..."
sudo ln -sf /usr/bin/rofi /usr/bin/dmenu sudo ln -sf /usr/bin/rofi /usr/bin/dmenu
echo -e "* Enabling required systemd units..." echo -e "* Enabling common systemd units..."
sudo systemctl enable --now NetworkManager
sudo systemctl enable --now systemd-timesyncd sudo systemctl enable --now systemd-timesyncd
sudo systemctl enable --now cups sudo systemctl enable --now cups
sudo systemctl enable --now bluetooth sudo systemctl enable --now bluetooth
sudo systemctl enable --now bluetooth-autoconnect sudo systemctl enable --now bluetooth-autoconnect
sudo systemctl enable --now updatedb.timer sudo systemctl enable --now updatedb.timer
# iwd will be used as a backend for NetworkManager ~/.config/init_netctl.sh
sudo systemctl disable wpa_supplicant
echo -e "* Ensure hardware clock is up to date..." echo -e "* Ensure hardware clock is up to date..."
sudo hwclock --systohc sudo hwclock --systohc
# So that "Open in Terminal" works inc Nemo # So that "Open in Terminal" works inc Nemo
@ -158,6 +153,7 @@ CONFIG=${XDG_CONFIG_HOME:-$HOME/.config}
ENV=${1} ENV=${1}
# First thing to do, before symlinks
for m in ${MERGE_DIRS}; do for m in ${MERGE_DIRS}; do
if [ -f "${CONFIG}/${m}/${MERGE_CONFIG_FOLDER}/above" ]; then if [ -f "${CONFIG}/${m}/${MERGE_CONFIG_FOLDER}/above" ]; then
merge_config $m ${ENV} true merge_config $m ${ENV} true
@ -166,6 +162,19 @@ for m in ${MERGE_DIRS}; do
fi fi
done done
echo -e "\n=== Create symlink to *.${ENV} regular files ==="
# Take all specific files and create a symlink pointing to it without the extension
# This file will be used by applications
for f in `find ${CONFIG} -type f -name "*.${ENV}"`; do
echo "${f%.*}${f}"
ln -sf ${f} ${f%.*}
done
# Take care of config files at home level, outside ${CONFIG} (e.g. Xresources)
for f in `find ${HOME} -maxdepth 1 -mindepth 1 -type f -name "*.${ENV}"`; do
echo "${f%.*}${f}"
ln -sf ${f} ${f%.*}
done
echo -e "\n=== Copy changed configuration which resides in outer directory ===" echo -e "\n=== Copy changed configuration which resides in outer directory ==="
# Destination files are regular files # Destination files are regular files
for f in `find ${CONFIG} -type f -name ${DEST_FILENAME}`; do for f in `find ${CONFIG} -type f -name ${DEST_FILENAME}`; do
@ -184,8 +193,7 @@ for f in `find ${CONFIG} -type f -name ${DEST_FILENAME}`; do
filename=${config_file##*/} filename=${config_file##*/}
# Now copy to destination # Now copy to destination
real_dest=${DEST}/${subfolder} real_dest=${DEST}/${subfolder}
echo $real_dest sudo mkdir -p ${real_dest}
sudo mkdir -p ${real_dest}
absolute_source=`realpath "${DIR}/${config_file}"` absolute_source=`realpath "${DIR}/${config_file}"`
check_copy "${absolute_source}" "sudo cp ${absolute_source} ${real_dest}" "sudo rm ${real_dest}/${filename}" check_copy "${absolute_source}" "sudo cp ${absolute_source} ${real_dest}" "sudo rm ${real_dest}/${filename}"
done done
@ -195,21 +203,6 @@ if [ ! -z "$INIT" ]; then
init_system init_system
fi fi
if [ ! -z ${ENV} ]; then
echo -e "\n=== Create symlink to *.${ENV} regular files ==="
# Take all specific files and create a symlink pointing to it without the extension
# This file will be used by applications
for f in `find ${CONFIG} -type f -name "*.${ENV}"`; do
echo "${f%.*}${f}"
ln -sf ${f} ${f%.*}
done
# Take care of config files at home level, outside ${CONFIG} (e.g. Xresources)
for f in `find ${HOME} -maxdepth 1 -mindepth 1 -type f -name "*.${ENV}"`; do
echo "${f%.*}${f}"
ln -sf ${f} ${f%.*}
done
fi
if [ ! -z "${WM_RESTART}" ]; then if [ ! -z "${WM_RESTART}" ]; then
echo -e "\n=== Restart graphical environment ===" echo -e "\n=== Restart graphical environment ==="
# Reload i3 configuration # Reload i3 configuration