almost done mostly tested

This commit is contained in:
acidburn
2023-04-26 23:43:07 -04:00
parent f57aadde1e
commit 50747ad583
2 changed files with 80 additions and 38 deletions
+64 -34
View File
@@ -1,13 +1,17 @@
#!/bin/python3 #!/bin/python3
# Program Shoud run with sudo -HE
# https://github.com/acidburnmonkey
#
import os import os
import re import re
import subprocess import subprocess
import importlib import importlib
import requests import requests
import logging import logging
import gdown
from rich.console import Console from rich.console import Console
from rich.progress import Progress
from rich.theme import Theme from rich.theme import Theme
@@ -19,6 +23,9 @@ logging.basicConfig(
ap_theme = Theme({'ok':'green', 'error':'red', 'checkt':'bold cyan','promp':'orange1'}) ap_theme = Theme({'ok':'green', 'error':'red', 'checkt':'bold cyan','promp':'orange1'})
console = Console(theme=ap_theme) console = Console(theme=ap_theme)
user = input("Type user name: ")
home = os.path.join('/home',user)
def main(): def main():
setup = '' setup = ''
@@ -71,8 +78,8 @@ def dnf_config():
else: else:
console.print(' dnf.conf already optimized :heavy_check_mark:', style='checkt') console.print(' dnf.conf already optimized :heavy_check_mark:', style='checkt')
subprocess.check_call('sudo dnf install -y https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm', shell=True) subprocess.check_call('sudo dnf install -y https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm',stdout=subprocess.DEVNULL, shell=True)
subprocess.check_call('sudo dnf install -y https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm', shell=True) subprocess.check_call('sudo dnf install -y https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm',stdout=subprocess.DEVNULL, shell=True)
console.print('rpmfusion added to repos :heavy_check_mark:', style='ok') console.print('rpmfusion added to repos :heavy_check_mark:', style='ok')
@@ -95,9 +102,9 @@ def install_programs_dnf():
logging.critical(f"Error at Installing programs: {str(e)}") logging.critical(f"Error at Installing programs: {str(e)}")
## pip ## pip
def install_pip_modules(modules): def install_pip_modules(modules):
subprocess.check_call(['pip', 'install', *modules]) subprocess.check_call(['pip', 'install', *modules])
def pip_modules(modules): def pip_modules(modules):
@@ -111,6 +118,7 @@ def pip_modules(modules):
console.print(f"the following modules are missing: {', '.join(missing_modules)}", style='checkt') console.print(f"the following modules are missing: {', '.join(missing_modules)}", style='checkt')
install_pip_modules(missing_modules) install_pip_modules(missing_modules)
return False return False
else: else:
console.print("all modules are installed. :heavy_check_mark:", style='ok') console.print("all modules are installed. :heavy_check_mark:", style='ok')
return True return True
@@ -120,7 +128,7 @@ def pip_modules(modules):
def sudo_check(): def sudo_check():
user = os.getenv("SUDO_USER") user = os.getenv("SUDO_USER")
if user is None: if user is None:
console.print("This program must run with 'sudo -u USER ./script'", style='error') console.print("This program must run as sudo -HE ./script ", style='error')
exit() exit()
else: else:
console.print('ok :heavy_check_mark:', style='ok') console.print('ok :heavy_check_mark:', style='ok')
@@ -129,38 +137,36 @@ def sudo_check():
def zsh_fonts(): def zsh_fonts():
console.rule("Installing Zsh fonts", style='checkt') console.rule("Installing Zsh fonts", style='checkt')
with Progress() as progress: try:
task = progress.add_task("[cyan]Installing Zhs etc...", total=4) console.print("installing oh my zsh ", style='ok')
while not progress.finished:
console.print("installing oh my zsh ", style='ok') #installs oh my zsh
#installs oh my zsh ohmy_url = "https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh"
url = "https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh" zsh_installer = requests.get(ohmy_url)
response = requests.get(url) open('install.sh', 'wb').write(zsh_installer.content)
script = response.text subprocess.run('chmod +x install.sh ', stdout=subprocess.DEVNULL, shell=True, check=True)
subprocess.run(script, shell=True, check=True) subprocess.run(f'sudo -u {user} ./install.sh', shell=True, check=True)
progress.update(task, advance=1)
console.print("installing oh my zsh auto sugestions ", style='ok') console.print("installing oh my zsh auto sugestions ", style='ok')
# zsh auto sugestions # zsh auto sugestions
subprocess.run('git clone https://github.com/zsh-users/zsh-autosuggestions ${zsh_custom:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions', shell=True) subprocess.run('git clone https://github.com/zsh-users/zsh-autosuggestions ${zsh_custom:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions', shell=True)
progress.update(task, advance=1)
console.print("installing powerlevel10k ", style='ok') console.print("installing powerlevel10k ", style='ok')
#powerlevel 10k #powerlevel 10k
subprocess.run('git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${zsh_custom:-$home/.oh-my-zsh/custom}/themes/powerlevel10k', shell=True) subprocess.run('git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${zsh_custom:-$home/.oh-my-zsh/custom}/themes/powerlevel10k', shell=True)
progress.update(task, advance=1)
console.print("installing flathub", style='ok') except Exception as e:
# flathub logging.warning(f"Could not set up Zsh: {str(e)}")
subprocess.run('flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo', shell=True)
progress.update(task, advance=1)
console.print("installing flathub", style='ok')
# flathub
subprocess.run('flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo', shell=True, stdout=subprocess.DEVNULL)
# copy and override dotfiles # copy and override dotfiles
def copy_dotfiles(setup): def copy_dotfiles(setup):
console.rule("Copying Dotfiles", style='checkt') console.rule("Copying Dotfiles", style='checkt')
home = os.path.expanduser("~")
# list of relevant configs # list of relevant configs
lis = list(next(os.walk('.'))[1]) lis = list(next(os.walk('.'))[1])
@@ -193,16 +199,15 @@ def copy_dotfiles(setup):
lis.remove('i3') lis.remove('i3')
if ('polybar' in lis): if ('polybar' in lis):
lis.remove('polybar') lis.remove('polybar')
lis.append('desktop/i3', 'desktop/polybar') lis.append('desktop/i3')
lis.append('desktop/polybar')
# copying files recusrsively # copying files recusrsively
for dir in lis: for dir in lis:
print(subprocess.run(f'cp -r {dir} {destination}', shell=True)) print(subprocess.run(f'cp -r {dir} {destination}', shell=True))
def executable_scripts(): def executable_scripts():
console.rule('Making scripts executable', style=checkt) console.rule('Making scripts executable', style='checkt')
home = os.path.expanduser("~")
for root ,_,files in os.walk(os.path.join(home,'.config')): for root ,_,files in os.walk(os.path.join(home,'.config')):
for element in files: for element in files:
@@ -211,10 +216,35 @@ def executable_scripts():
subprocess.run(f"chmod +x {os.path.join(root,element)}", shell=True) subprocess.run(f"chmod +x {os.path.join(root,element)}", shell=True)
except Exception as e: except Exception as e:
logging.critical(f"Error at executable_scripts: {str(e)}") logging.critical(f"Error at executable_scripts: {str(e)}")
console.print("Job done :heavy_check_mark:", style='ok')
def msic_configs(): def msic_configs():
pass console.rule('Setting up final configs', style='checkt')
current_dir = os.getcwd()
try :
os.mkdir('misic')
os.mkdir(os.path.join(home,'.fonts'))
except FileExistsError:
pass
os.chdir(os.path.join(current_dir,'misic'))
#### Fonts
# https://drive.google.com/drive/folders/1BciF4x3_K3T8p1Y17lHn_xWXnSAZpvDE
fonts_url = 'https://drive.google.com/uc?id=1-3g_CjiJHKhRrJNjjZeAYu9KIGIAAAhC'
output ='fonts-c.zip'
gdown.download(fonts_url,output, quiet=False)
subprocess.run(f"unzip {output} -d {os.path.join(home,'.fonts')}",stdout=subprocess.DEVNULL ,shell=True)
subprocess.run("fc-cache -f",stdout=subprocess.DEVNULL ,shell=True)
#### i3 autotiling
autotiling_url = 'https://raw.githubusercontent.com/nwg-piotr/autotiling/master/autotiling/main.py'
tiler = requests.get(autotiling_url, allow_redirects=True)
open('autotiling', 'wb').write(tiler.content)
subprocess.run('chmod +x autotiling', shell=True, stdout=subprocess.DEVNULL)
subprocess.run('cp autotiling /bin', shell=True, stdout=subprocess.DEVNULL)
if __name__ == '__main__': if __name__ == '__main__':
copy_dotfiles('d') main()
+15 -3
View File
@@ -1,17 +1,29 @@
import os import os
import gdown import gdown
import subprocess import subprocess
import requests
current_dir = os.getcwd() current_dir = os.getcwd()
try : try :
os.mkdir('misic') os.mkdir('misic')
os.mkdir(os.path.join(home,'.fonts'))
except FileExistsError: except FileExistsError:
pass pass
os.chdir(os.path.join(current_dir,'misic')) os.chdir(os.path.join(current_dir,'misic'))
#### Fonts
# https://drive.google.com/drive/folders/1BciF4x3_K3T8p1Y17lHn_xWXnSAZpvDE # https://drive.google.com/drive/folders/1BciF4x3_K3T8p1Y17lHn_xWXnSAZpvDE
url = 'https://drive.google.com/uc?id=1-3g_CjiJHKhRrJNjjZeAYu9KIGIAAAhC' fonts_url = 'https://drive.google.com/uc?id=1-3g_CjiJHKhRrJNjjZeAYu9KIGIAAAhC'
output ='fonts-c.zip' output ='fonts-c.zip'
# gdown.download(url,output, quiet=False) gdown.download(fonts_url,output, quiet=False)
subprocess.run(f"unzip {output} {os.path.join(home,'.fonts')}",stdout=subprocess.DEVNULL ,shell=True)
subprocess.run("fc-cache -f",stdout=subprocess.DEVNULL ,shell=True)
#### i3 autotiling
autotiling_url = 'https://raw.githubusercontent.com/nwg-piotr/autotiling/master/autotiling/main.py'
tiler = requests.get(autotiling_url, allow_redirects=True)
open('autotiling', 'wb').write(tiler.content)
subprocess.run('chmod +x autotiling', shell=True, stdout=subprocess.DEVNULL)
subprocess.run('cp autotiling /bin', shell=True, stdout=subprocess.DEVNULL)
subprocess.run(f'unzip {output} ',stdout=subprocess.DEVNULL ,shell=True)