Last active
April 13, 2020 15:25
-
-
Save ispanos/ea0460f5b8a3d67b2d00a18bd1864fa0 to your computer and use it in GitHub Desktop.
Some functions I was using on one of my scripts, but no longer use.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# License: GNU GPLv3 | |
status_msg() { printf "%-25s %2s" $(tput setaf 4)"${FUNCNAME[1]}"$(tput sgr0) "- "; } | |
# Prints "done" and any given arguments with a new line. | |
ready() { echo $(tput setaf 2)"done"$@$(tput sgr0); } | |
Install_nvim_plugged_plugins() { | |
# Not tested. Run as user | |
mkdir -p "/home/$name/.config/nvim/autoload" | |
curl -Ls "https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim" \ | |
> "/home/$name/.config/nvim/autoload/plug.vim" | |
(sleep 30 && killall nvim) & | |
nvim -E -c "PlugUpdate|visual|q|q" >/dev/null 2>&1 | |
} | |
safe_ssh() { | |
# Removes password based authentication for ssh | |
sudo sed -i '/#PasswordAuthentication/{s/yes/no/;s/^#//}' /etc/ssh/sshd_config | |
} | |
paccashe_hook() { | |
# Keeps only the latest 3 versions of packages. | |
sudo cat > /etc/pacman.d/hooks/cleanup.hook <<-EOF | |
[Trigger] | |
Type = Package | |
Operation = Remove | |
Operation = Install | |
Operation = Upgrade | |
Target = * | |
[Action] | |
Description = Keeps only the latest 3 versions of packages | |
When = PostTransaction | |
Exec = /usr/bin/paccache -rk3 | |
EOF | |
} | |
numlockTTY() { | |
# Simple script to enable NumLock on ttys. | |
sudo cat > /etc/systemd/system/numLockOnTty.service <<-EOF | |
[Unit] | |
Description=numlockOnTty | |
[Service] | |
ExecStart=/usr/bin/numlockOnTty | |
[Install] | |
WantedBy=multi-user.target | |
EOF | |
sudo cat > /usr/bin/numlockOnTty <<-EOF | |
#!/usr/bin/env bash | |
for tty in /dev/tty{1..6} | |
do | |
/usr/bin/setleds -D +num < "$tty"; | |
done | |
EOF | |
sudo chmod +x /usr/bin/numlockOnTty | |
sudo systemctl enable --now numLockOnTty >/dev/null 2>&1 | |
infinality(){ | |
# Enables infinality fonts. | |
[ ! -r /etc/profile.d/freetype2.sh ] && return | |
sudo sed -i 's/^#exp/exp/' /etc/profile.d/freetype2.sh | |
} | |
networkd_config() { | |
# creates a networkd entry for all ether and wlan devices. | |
net_devs=$( networkctl --no-legend 2>/dev/null | \ | |
grep -P "ether|wlan" | \ | |
awk '{print $2}' | \ | |
sort ) | |
for device in ${net_devs[*]}; do ((i++)) | |
sudo cat > /etc/systemd/network/${device}.network <<-EOF | |
[Match] | |
Name=${device} | |
[Network] | |
DHCP=ipv4 | |
IPForward=yes | |
[DHCP] | |
RouteMetric=$(($i * 10)) | |
EOF | |
done | |
sudo systemctl disable --now dhcpcd >/dev/null 2>&1 | |
sudo systemctl enable --now systemd-networkd >/dev/null 2>&1 | |
printf "search home\\nnameserver 192.168.1.1\\n" | | |
sudo tee /etc/resolv.conf >/dev/null | |
sudo systemctl enable --now systemd-resolved >/dev/null 2>&1 | |
} | |
install_progs() { | |
if [ ! "$1" ]; then | |
1>&2 echo "No arguments passed. No exta programs will be installed." | |
return 1 | |
fi | |
# Use all cpu cores to compile packages | |
sudo sed -i "s/-j2/-j$(nproc)/;s/^#MAKEFLAGS/MAKEFLAGS/" /etc/makepkg.conf | |
# Merges all csv files in one file. Checks for local files first. | |
for file in $@; do | |
if [ -r programs/${file}.csv ]; then | |
cat programs/${lsb_dist}.${file}.csv >> /tmp/progs.csv | |
else | |
curl -Ls "${programs_repo}${lsb_dist}.${file}.csv" >> /tmp/progs.csv | |
fi | |
done | |
# Remove comments and empty lines. | |
sed -i '/^#/d;/^,/d' /tmp/progs.csv | |
# Total number of progs in all lists. | |
total=$(wc -l < /tmp/progs.csv) | |
fail_msg(){ | |
[ $program ] && | |
echo "$(tput setaf 1)$program failed$(tput sgr0)" | \ | |
tee -a /home/${name}/failed | |
} | |
echo "Installing packages from csv file(s): $@" | |
while IFS=, read -r program comment tag; do ((n++)) | |
# Removes quotes from the comments. | |
echo "$comment" | grep -q "^\".*\"$" && | |
comment="$(echo "$comment" | sed "s/\(^\"\|\"$\)//g")" | |
# Pretty output with columns. | |
printf "%07s %-20s %2s %2s" "[$n""/$total]" "$(basename $program)" - "$comment" | |
# the actual installation of packages in csv lists. | |
case "$tag" in | |
"") printf '\n' | |
pacman --noconfirm --needed -S "$program" > /dev/null 2>&1 || fail_msg | |
;; | |
aur | A) printf "(AUR)\n" | |
sudo -u "$name" yay -S --needed --noconfirm "$program" >/dev/null 2>&1 || fail_msg | |
;; | |
git | G) printf "(GIT)\n" | |
local dir=$(mktemp -d) | |
git clone --depth 1 "$program" "$dir" > /dev/null 2>&1 | |
cd "$dir" && make >/dev/null 2>&1 | |
make install >/dev/null 2>&1 || fail_msg | |
;; | |
pip | P) printf "(PIP)\n" | |
# Installs pip if needed. | |
command -v pip || quick_install python-pip | |
yes | pip install "$program" || fail_msg | |
;; | |
flatpak | F) printf "(Flatpak)\n" | |
#### DONT USE THIS | |
flatpak remote-add --if-not-exists \ | |
flathub \ | |
https://flathub.org/repo/flathub.flatpakrepo > /dev/null 2>&1 | |
flatpak install -y "$program" > /dev/null 2>&1 | |
;; | |
esac | |
done < /tmp/progs.csv | |
} | |
data() { # Mounts my HHD. Useless to anyone else | |
# Maybe you could use the mount options for your HDD, | |
# or help me improve mine. | |
sudo mkdir -p /media/Data | |
local duuid mntPoint mntOpt | |
duuid="UUID=fe8b7dcf-3bae-4441-a4f3-a3111fee8ca4" | |
mntPoint="/media/Data" | |
mntOpt="ext4 rw,noatime,nofail,user,auto 0 2" | |
printf "\\n%s \t%s \t%s\t\\n" "$duuid" "$mntPoint" "$mntOpt" | | |
sudo tee -a /etc/fstab >/dev/null | |
} | |
merge_lists() { | |
# Merges all csv files in one file. Checks for local files first. | |
for file in "$@"; do | |
if [ -r "$ID.$file.csv" ]; then | |
cat "$ID.$file.csv" >>/tmp/progs.csv | |
elif [ -r "programs/$ID.$file.csv" ]; then | |
cat "programs/$ID.$file.csv" >>/tmp/progs.csv | |
else | |
curl -Ls "$progs_repo/$ID.$file.csv" >>/tmp/progs.csv | |
fi | |
done | |
# local packages extra_repos nvidiaGPU | |
# packages=$(sed '/^#/d;/^,/d;s/,.*$//' /tmp/progs.csv | tr "\n" " ") | |
# extra_repos=$(sed '/^#/d;/^,/d;s/^.*,//' /tmp/progs.csv) | |
} | |
ALT_merge_lists() { | |
# Merges all csv files in one file. Checks for local files first. | |
for file in "$@"; do | |
if [ -r "$ID.$file.csv" ]; then | |
packages="$packages $(sed '/^#/d;/^,/d;s/,.*$//' $ID.$file.csv)" | |
extra_repos="$extra_repos $(sed '/^#/d;/^,/d;s/^.*,//' $ID.$file.csv)" | |
elif [ -r "programs/$ID.$file.csv" ]; then | |
packages="$packages $(sed '/^#/d;/^,/d;s/,.*$//' programs/$ID.$file.csv)" | |
extra_repos="$extra_repos $(sed '/^#/d;/^,/d;s/^.*,//' programs/$ID.$file.csv)" | |
else | |
packages="$packages $(curl -Ls "$progs_repo/$ID.$file.csv" | sed '/^#/d;/^,/d;s/,.*$//')" | |
extra_repos="$extra_repos $(curl -Ls "$progs_repo/$ID.$file.csv" | sed '/^#/d;/^,/d;s/^.*,//')" | |
fi | |
done | |
} | |
hostname=$(hostnamectl | awk -F": " 'NR==1 {print $2}') | |
agetty_set() { | |
# Doesn't ask for username on the tty for faster logins. | |
# Default user is going to be the user who's running the script. | |
local ExexStart log | |
ExexStart="ExecStart=-\/sbin\/agetty --skip-login --login-options" | |
log="$ExexStart $USER --noclear %I \$TERM" | |
sed "s/^Exec.*/$log/" /usr/lib/systemd/system/[email protected] | | |
sudo tee /etc/systemd/system/[email protected] >/dev/null | |
sudo systemctl daemon-reload | |
sudo systemctl reenable [email protected] | |
grep -q "Anergos" /etc/issue && return | |
# Edits login screen | |
cat <<-EOF | sudo tee -a /etc/issue >/dev/null | |
\e[0;36m | |
Anergos Meta-distribution | |
Website: github.com/ispanos/anergos | |
Hostname: \\n | |
\e[0m | |
EOF | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment