Skip to content

Instantly share code, notes, and snippets.

@swipswaps
Forked from rafaelkallis/fedora_setup.sh
Created April 26, 2021 14:34
Show Gist options
  • Save swipswaps/db7e4e42ded5b8449ee0e81892758016 to your computer and use it in GitHub Desktop.
Save swipswaps/db7e4e42ded5b8449ee0e81892758016 to your computer and use it in GitHub Desktop.
Fedora Scripts
#
# DISABLE SECURE BOOT IN BIOS!
#
# fish
sudo dnf install fish util-linux-user
chsh -s /usr/bin/fish
mkdir ~/.config/fish
touch ~/.config/fish/config.fish
# vim
sudo dnf install vim-enhanced
# git credential helper
sudo dnf install git-credential-libsecret
git config --global user.name "Rafael Kallis"
git config --global user.email "[email protected]"
git config --global user.signingKey "<keyid>"
git config --global commit.gpgSign true
git config --global credential.helper "libsecret"
git config --global core.editor "vim"
#
# python
#
# add to PATH
echo "# pip" >> .config/fish/config.fish
echo "set -x PATH \$PATH \"$HOME/.local/bin\"" >> .config/fish/config.fish
#
# nodejs
#
sudo dnf install nodejs npm
# add to PATH
echo "# npm" >> .config/fish/config.fish
echo "set -x PATH \$PATH \"$HOME/.node_modules/bin\"" >> .config/fish/config.fish
echo "set -x npm_config_prefix \"$HOME/.node_modules\"" >> .config/fish/config.fish
#
# dotnet
#
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
sudo wget -O /etc/yum.repos.d/microsoft-prod.repo https://packages.microsoft.com/config/fedora/33/prod.repo
sudo dnf config-manager --save --setopt="*microsoft-*.priority=1"
sudo dnf install dotnet-sdk-3.1
# add to PATH
echo "# dotnet" >> .config/fish/config.fish
echo "set -x PATH \$PATH \"$HOME/.dotnet/tools\"" >> .config/fish/config.fish
#
# java
#
sudo dnf install java-11-openjdk
# development
sudo dnf install gcc gcc-c++ make cmake python3-devel cargo rust gtk3-devel postgresql
pip install --user mssql-cli podman-compose psutil jupyterlab numpy pandas matplotlib seaborn azure-cli
npm install --global yarn typescript heroku
dotnet tool install --global dotnet-ef
# docker
# https://docs.docker.com/engine/install/fedora/
sudo dnf install dnf-plugins-core
sudo dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo
sudo dnf install docker-ce docker-ce-cli containerd.io docker-compose
sudo systemctl enable docker
sudo usermod -aG docker $USER
# vscode
# (https://code.visualstudio.com/docs/setup/linux#_rhel-fedora-and-centos-based-distributions)
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
sudo sh -c 'echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/vscode.repo'
sudo dnf check-update
sudo dnf install code
# brave browser
# https://brave.com/linux/
sudo rpm --import https://brave-browser-rpm-release.s3.brave.com/brave-core.asc
sudo dnf install dnf-plugins-core
sudo dnf config-manager --add-repo https://brave-browser-rpm-release.s3.brave.com/x86_64/
sudo dnf install brave-browser
# teams
# https://kifarunix.com/install-microsoft-teams-app-on-fedora-32-31-30/
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
sudo sh -c 'echo -e "[teams]\nname=Microsoft Teams\nbaseurl=https://packages.microsoft.com/yumrepos/ms-teams\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/teams.repo'
sudo dnf update
sudo dnf install teams
# pop shell
#cd ~
#git clone https://github.com/pop-os/shell
#cd ~/shell
#sh rebuild.sh
#git clone https://github.com/pop-os/shell-shortcuts
#cd ~/shell-shortcuts
#make
#sudo make install
#cd ~
#
# system
#
# sensors
sudo dnf install lm_sensors
# smart monitoring
# https://fedoraproject.org/wiki/Smartctl
# https://www.smartmontools.org/
sudo dnf install smartmontools
# bluetooth autosuspend
# sudo grubby --update-kernel=ALL --args="btusb.enable_autosuspend=0"
# sudo grubby --update-kernel=ALL --remove-args="btusb.enable_autosuspend"
#
# battery
#
sudo dnf install powertop
sudo powertop --calibrate
sudo systemctl enable powertop
# tlp https://linrunner.de/tlp/installation/fedora.html
#dnf install tlp tlp-rdw
# tlp status
#tlp-stat
# extras if needed!
# dnf install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm
# dnf install https://repo.linrunner.de/fedora/tlp/repos/releases/tlp-release.fc$(rpm -E %fedora).noarch.rpm
# install missing kernel modules as recommended by "tlp-stat -b"
# dnf install kernel-devel akmod-acpi_call akmod-tp_smapi
# fingerprint "6BED 8C16 80E0 E9DC D310 94FB 274D 8DB1 A690 281B"
#!/usr/bin/env python
import sys
from time import time, sleep
from datetime import datetime
import psutil
from psutil._common import bytes2human
import requests
from pathlib import Path
from itertools import cycle
from socket import gethostname, gethostbyname
def cached_ttl(ttl_seconds):
assert ttl_seconds >= 0
memo_t = 0
memo = None
def _decorator(f):
def _wrapper(*args, **kwds):
nonlocal f
nonlocal memo_t
nonlocal memo
if time() >= (memo_t + ttl_seconds):
memo_t = time()
memo = f(*args)
return memo
return _wrapper
return _decorator
@cached_ttl(1)
def temperatures():
return psutil.sensors_temperatures()
@cached_ttl(60)
def crypto_prices():
response = requests.get('https://api.coingecko.com/api/v3/simple/price?ids=ethereum,bitcoin&vs_currencies=usd')
response.raise_for_status()
body = response.json()
btc = int(body['bitcoin']['usd'])
eth = int(body['ethereum']['usd'])
return [f"\N{bitcoin sign} {btc:,}$",f"\N{greek capital letter xi} {eth:,}$"]
def get_cpu():
perc = str(psutil.cpu_percent()).rjust(4)
freq, _, _ = psutil.cpu_freq()
freq /= 1000
temp = int(temperatures()['coretemp'][0].current)
return f"\N{abacus} {freq:.1f}GHz {perc}% {temp}\N{degree sign}C"
def get_ram():
stats = psutil.virtual_memory()
return f"\N{pager} {bytes2human(stats.used)}B {stats.percent}%"
def get_disk():
stats = psutil.disk_usage(Path.home())
temp = int(temperatures()['nvme'][0].current)
return f"\N{dvd} {bytes2human(stats.used)}B {stats.percent}% {temp}\N{degree sign}C"
@cached_ttl(5)
def get_network():
response = requests.get("http://ip-api.com/json?fields=country,countryCode,query")
response.raise_for_status()
body = response.json()
public_ip = body['query']
public_country = body['countryCode']
hostname = gethostname()
local_ip = gethostbyname(hostname)
return [f"\N{earth globe americas} {public_country} {public_ip}", f"\N{personal computer} {hostname} {local_ip}"]
def get_battery():
stats = psutil.sensors_battery()
remaining_minutes = stats.secsleft // 60
remaining = f"{remaining_minutes}m" if remaining_minutes <= 90 else f"{remaining_minutes // 60}h"
status = "\N{high voltage sign}" if stats.power_plugged else "\N{cyclone}"
return f"{status} {int(stats.percent)}% ~{remaining}"
def get_datetime():
now = datetime.now()
symbol = (
'\N{sunrise}' if 7 <= now.hour <= 10
else
"\U00002600\U0000FE0F" if 11 <= now.hour <= 17
else
"\N{cityscape at dusk}" if 18 <= now.hour <= 20
else
"\N{crescent moon}" if 21 <= now.hour <= 22
else
"\N{sleeping symbol}"
)
datetime_text = now.strftime("%H:%M")
return f"{symbol} {datetime_text}"
def compute():
components = [*crypto_prices(), get_cpu(), get_ram(), get_disk(), *get_network(), get_battery(), get_datetime()]
components = [" \N{small blue diamond} " + component for component in components]
return "".join(components) + " "
if __name__ == "__main__":
while True:
data = compute()
sys.stdout.write("" + data + "\n")
sys.stdout.flush()
sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment