Compare commits

..

3 Commits

Author SHA1 Message Date
d457cbacc2 Update gitignore 2020-08-22 05:18:26 +02:00
1fcc6cd926 Add new package-lister module 2020-08-22 05:16:54 +02:00
7c48004aaa Add decorator for needed packages 2020-08-22 05:16:25 +02:00
4 changed files with 105 additions and 81 deletions

2
.gitignore vendored
View File

@ -2,4 +2,4 @@ __pycache__
.vscode .vscode
devenv devenv
your_system_information.txt your_system_information.txt
.DS_Store *.db

43
decorators.py Normal file
View File

@ -0,0 +1,43 @@
from functools import wraps
installed_packages = []
def install_package(pkg):
if pkg not in installed_packages:
installed_packages.append(pkg)
print(f"Installed: {pkg}")
else:
print(f"Already installed: {pkg}")
def needs_packages(packages):
def inner_decorator(function):
@wraps(function)
def execution_wrapper(*args, **kwargs):
[install_package(package) for package in packages]
return function(*args, **kwargs)
return execution_wrapper
return inner_decorator
@needs_packages(['vim', 'calc'])
def add(z1, z2):
return z1 + z2
@needs_packages(['calc', 'sed'])
def sub(z1, z2):
return z1 - z2
@needs_packages(['calc'])
def bla(z1, z2):
return z1 / z2
print(add(1, 2))
print(sub(1, 2))
print(bla(1, 2))

View File

@ -1,80 +0,0 @@
Title,Description,Issue ID,URL,State,Author,Author Username,Assignee,Assignee Username,Confidential,Locked,Due Date,Created At (UTC),Updated At (UTC),Closed At (UTC),Milestone,Weight,Labels,Time Estimate,Time Spent
Add .bashrc,Add my default .bashrc,1,https://gitlab.com/marcel.schwarz/linux-tools/-/issues/1,Closed,Marcel Schwarz,marcel.schwarz,Lucas Noki,lucas.noki,No,No,,2019-11-25 21:16:36,2020-08-01 20:59:58,2020-08-01 20:59:58,Add current setup,,,0,0
Install docker service,"",2,https://gitlab.com/marcel.schwarz/linux-tools/-/issues/2,Closed,Marcel Schwarz,marcel.schwarz,"","",No,No,,2019-12-07 21:42:25,2020-03-21 04:56:42,2020-03-21 04:56:41,Self setup service v1,,new module,0,0
Install PHPMyAdmin,"",3,https://gitlab.com/marcel.schwarz/linux-tools/-/issues/3,Open,Marcel Schwarz,marcel.schwarz,"","",No,No,,2019-12-07 21:42:42,2019-12-13 20:01:35,,Self setup service v1,,new module,0,0
Install Fail2Ban,"",4,https://gitlab.com/marcel.schwarz/linux-tools/-/issues/4,Closed,Marcel Schwarz,marcel.schwarz,"","",No,No,,2019-12-07 21:43:04,2020-08-01 00:42:43,2020-08-01 00:42:43,Self setup service v1,,new module,0,0
Install OpenVPN Server,"Either:
* OpenVPS Access Server
* OpenVPN with Profiles
Maybe use: https://github.com/Nyr/openvpn-install/blob/master/openvpn-install.sh",5,https://gitlab.com/marcel.schwarz/linux-tools/-/issues/5,Open,Marcel Schwarz,marcel.schwarz,"","",No,No,,2019-12-07 21:44:56,2019-12-13 20:02:00,,Self setup service v1,,new module,0,0
Install Database System,"For example:
* MariaDB
* MySQL
* Neo4j",6,https://gitlab.com/marcel.schwarz/linux-tools/-/issues/6,Open,Marcel Schwarz,marcel.schwarz,"","",No,No,,2019-12-07 21:47:01,2019-12-13 20:02:12,,Self setup service v1,,new module,0,0
Generate a report of all done actions as a summary,"",7,https://gitlab.com/marcel.schwarz/linux-tools/-/issues/7,Open,Marcel Schwarz,marcel.schwarz,"","",No,No,,2019-12-07 21:48:34,2019-12-18 23:10:24,,Self setup service v1,,new module,0,0
Set up vim correctly,"",8,https://gitlab.com/marcel.schwarz/linux-tools/-/issues/8,Closed,Marcel Schwarz,marcel.schwarz,Lucas Noki,lucas.noki,No,No,,2019-12-08 19:17:19,2020-02-05 23:08:24,2020-01-12 18:07:04,Self setup service v1,,new module,0,0
Create main.py function to start the script,"",9,https://gitlab.com/marcel.schwarz/linux-tools/-/issues/9,Closed,Marcel Schwarz,marcel.schwarz,"","",No,No,,2019-12-13 22:32:42,2020-04-04 22:45:08,2019-12-14 03:29:17,Self setup service v1,,new module,0,0
Create menu to choose a module to run from main.py,Maybe use [PyInquirer](https://github.com/CITGuru/PyInquirer),10,https://gitlab.com/marcel.schwarz/linux-tools/-/issues/10,Closed,Marcel Schwarz,marcel.schwarz,"","",No,No,,2019-12-15 03:49:41,2020-04-04 22:44:58,2019-12-22 01:39:18,Self setup service v1,,new module,0,0
Set up the swap file for the system with user specified size and default size,"### Acceptance Criteria:
* create swap file (or resize); DONE
* enable swap file; DONE
* deactivate swap file; DONE
* delete swap file; DONE
* location for swap file (default and by user); DONE
* adjust swappiness; Not necessary imo, see here: https://github.com/torvalds/linux/blob/v5.0/Documentation/sysctl/vm.txt#L809
* make ""enable swap file"" persistent; In Progress",11,https://gitlab.com/marcel.schwarz/linux-tools/-/issues/11,Closed,Marcel Schwarz,marcel.schwarz,"","",No,No,,2019-12-22 01:53:24,2020-01-25 01:45:08,2020-01-25 01:45:08,Self setup service v1,,new module,0,0
Install basic command-line tools,"Install:
* bleachbit
* nano
* xrdp
* htop
* bash-completion
* dialog
* powertop
* tree",12,https://gitlab.com/marcel.schwarz/linux-tools/-/issues/12,Closed,Marcel Schwarz,marcel.schwarz,"","",No,No,,2019-12-29 23:05:23,2020-03-20 23:56:19,2020-03-06 00:24:13,Self setup service v1,,new module,0,0
Set up ssh key based authentication,[**Youtube Tutorial**](https://www.youtube.com/watch?v=vpk_1gldOAE),13,https://gitlab.com/marcel.schwarz/linux-tools/-/issues/13,Open,Marcel Schwarz,marcel.schwarz,"","",No,No,,2020-01-06 17:40:35,2020-01-06 17:40:35,,Self setup service v1,,new module,0,0
Setup a Minecraft Server (Vanilla),"",14,https://gitlab.com/marcel.schwarz/linux-tools/-/issues/14,Open,Marcel Schwarz,marcel.schwarz,"","",No,No,,2020-01-09 20:07:17,2020-01-09 20:07:17,,Self setup service v2,,new module,0,0
Investigate usage of new cli (like the gcloud one),"https://cloud.google.com/sdk/gcloud/?hl=de \
https://cloud.google.com/sdk/gcloud/reference/firebase/test/android/run \
https://cloud.google.com/sdk/gcloud/reference/topic/arg-files \",15,https://gitlab.com/marcel.schwarz/linux-tools/-/issues/15,Closed,Marcel Schwarz,marcel.schwarz,"","",No,No,,2020-01-11 03:11:09,2020-01-21 23:29:31,2020-01-21 23:29:30,Self setup service v1,,,0,0
Dev-Ops to create ELF File,PyInstaller Docs: https://pyinstaller.readthedocs.io/en/stable/index.html,16,https://gitlab.com/marcel.schwarz/linux-tools/-/issues/16,Open,Marcel Schwarz,marcel.schwarz,"","",No,No,,2020-01-19 20:42:42,2022-12-22 18:50:12,,,,,0,0
Swap module -> fix /etc/fstab entry problem,"**Problem: entries in /etc/fstab**
To make the swap persistent an entry is added to the /etc/fstab file. Anyway if the swap is resized there will also be another entry added to /etc/fstab. Also when the swap is deleted the entry in /etc/fstab isn´t.
Problems to fix:
- Make sure entry for persistent swap file only exists once!
- Check if entry is already there when resizing and prevent double entries!
- Delete entry when swap gets deleted!",17,https://gitlab.com/marcel.schwarz/linux-tools/-/issues/17,Closed,Lucas Noki,lucas.noki,Lucas Noki,lucas.noki,No,No,,2020-01-27 08:54:33,2020-02-01 02:32:58,2020-02-01 02:31:42,,,bug,0,0
Update Module,"Executes update tasks with the apt package manager
apt update
apt upgrade
apt dist-upgrade
apt autoremove
apt autoclean",18,https://gitlab.com/marcel.schwarz/linux-tools/-/issues/18,Closed,Marcel Schwarz,marcel.schwarz,"","",No,No,,2020-03-05 16:17:49,2020-03-05 19:11:34,2020-03-05 19:11:34,Self setup service v1,,new module,0,0
Bash script to prepare the system for the first use of the python based cli,"",19,https://gitlab.com/marcel.schwarz/linux-tools/-/issues/19,Closed,Marcel Schwarz,marcel.schwarz,"","",No,No,,2020-03-05 19:14:25,2020-03-05 20:41:02,2020-03-05 20:41:02,Self setup service v1,,,0,0
Start up a quick teamspeak server on docker,"",20,https://gitlab.com/marcel.schwarz/linux-tools/-/issues/20,Closed,Marcel Schwarz,marcel.schwarz,"","",No,No,,2020-03-17 01:03:48,2020-03-25 00:39:20,2020-03-21 21:53:32,Self setup service v2,,new module,0,7200
Docker module,"Pull latest:
```
docker images | grep -v REPOSITORY| awk '{print $1}'| xargs -L1 docker pull
```
Pull by Tag:
```
docker images | grep -v REPOSITORY | awk '{printf $1; printf "":""; print $2}' | xargs -L1 docker pull
```
To Update all already pulled images",21,https://gitlab.com/marcel.schwarz/linux-tools/-/issues/21,Open,Marcel Schwarz,marcel.schwarz,"","",No,No,,2020-03-21 04:55:22,2020-04-09 22:29:56,,,,new module,0,0
Add git in basic tools installer,"* git
* git-lfs",22,https://gitlab.com/marcel.schwarz/linux-tools/-/issues/22,Open,Marcel Schwarz,marcel.schwarz,"","",No,No,,2020-06-23 20:34:44,2020-06-23 20:34:44,,,,,0,0
Make project release ready,"",23,https://gitlab.com/marcel.schwarz/linux-tools/-/issues/23,Closed,Marcel Schwarz,marcel.schwarz,Marcel Schwarz,marcel.schwarz,No,No,,2020-08-01 22:53:47,2020-08-05 13:58:40,2020-08-05 13:58:40,,,,0,0
Decorator for needed packages,* To check if a packe needs to be installed a sqlite db is used,24,https://gitlab.com/marcel.schwarz/linux-tools/-/issues/24,Open,Marcel Schwarz,marcel.schwarz,"","",No,No,,2020-08-22 03:13:53,2021-09-11 00:33:05,,,,,0,0
Update bashrc with useful functions,https://linuxize.com/post/bash-functions/,25,https://gitlab.com/marcel.schwarz/linux-tools/-/issues/25,Open,Marcel Schwarz,marcel.schwarz,"","",No,No,,2020-12-26 01:41:32,2020-12-26 01:41:32,,,,,0,0
WSL Module,"WSL2 Linux Module to free up caches and compact memory
See [Microsoft Blog](https://devblogs.microsoft.com/commandline/memory-reclaim-in-the-windows-subsystem-for-linux-2/)
`echo 1 > /proc/sys/vm/drop_caches`
`echo 1 > /proc/sys/vm/compact_memory`
needs to run as root (sudo doesn't work)",26,https://gitlab.com/marcel.schwarz/linux-tools/-/issues/26,Open,Marcel Schwarz,marcel.schwarz,"","",No,No,,2021-04-01 21:24:37,2021-04-01 21:24:37,,,,new module,0,0
1 Title Description Issue ID URL State Author Author Username Assignee Assignee Username Confidential Locked Due Date Created At (UTC) Updated At (UTC) Closed At (UTC) Milestone Weight Labels Time Estimate Time Spent
2 Add .bashrc Add my default .bashrc 1 https://gitlab.com/marcel.schwarz/linux-tools/-/issues/1 Closed Marcel Schwarz marcel.schwarz Lucas Noki lucas.noki No No 2019-11-25 21:16:36 2020-08-01 20:59:58 2020-08-01 20:59:58 Add current setup 0 0
3 Install docker service 2 https://gitlab.com/marcel.schwarz/linux-tools/-/issues/2 Closed Marcel Schwarz marcel.schwarz No No 2019-12-07 21:42:25 2020-03-21 04:56:42 2020-03-21 04:56:41 Self setup service v1 new module 0 0
4 Install PHPMyAdmin 3 https://gitlab.com/marcel.schwarz/linux-tools/-/issues/3 Open Marcel Schwarz marcel.schwarz No No 2019-12-07 21:42:42 2019-12-13 20:01:35 Self setup service v1 new module 0 0
5 Install Fail2Ban 4 https://gitlab.com/marcel.schwarz/linux-tools/-/issues/4 Closed Marcel Schwarz marcel.schwarz No No 2019-12-07 21:43:04 2020-08-01 00:42:43 2020-08-01 00:42:43 Self setup service v1 new module 0 0
6 Install OpenVPN Server Either: * OpenVPS Access Server * OpenVPN with Profiles Maybe use: https://github.com/Nyr/openvpn-install/blob/master/openvpn-install.sh 5 https://gitlab.com/marcel.schwarz/linux-tools/-/issues/5 Open Marcel Schwarz marcel.schwarz No No 2019-12-07 21:44:56 2019-12-13 20:02:00 Self setup service v1 new module 0 0
7 Install Database System For example: * MariaDB * MySQL * Neo4j 6 https://gitlab.com/marcel.schwarz/linux-tools/-/issues/6 Open Marcel Schwarz marcel.schwarz No No 2019-12-07 21:47:01 2019-12-13 20:02:12 Self setup service v1 new module 0 0
8 Generate a report of all done actions as a summary 7 https://gitlab.com/marcel.schwarz/linux-tools/-/issues/7 Open Marcel Schwarz marcel.schwarz No No 2019-12-07 21:48:34 2019-12-18 23:10:24 Self setup service v1 new module 0 0
9 Set up vim correctly 8 https://gitlab.com/marcel.schwarz/linux-tools/-/issues/8 Closed Marcel Schwarz marcel.schwarz Lucas Noki lucas.noki No No 2019-12-08 19:17:19 2020-02-05 23:08:24 2020-01-12 18:07:04 Self setup service v1 new module 0 0
10 Create main.py function to start the script 9 https://gitlab.com/marcel.schwarz/linux-tools/-/issues/9 Closed Marcel Schwarz marcel.schwarz No No 2019-12-13 22:32:42 2020-04-04 22:45:08 2019-12-14 03:29:17 Self setup service v1 new module 0 0
11 Create menu to choose a module to run from main.py Maybe use [PyInquirer](https://github.com/CITGuru/PyInquirer) 10 https://gitlab.com/marcel.schwarz/linux-tools/-/issues/10 Closed Marcel Schwarz marcel.schwarz No No 2019-12-15 03:49:41 2020-04-04 22:44:58 2019-12-22 01:39:18 Self setup service v1 new module 0 0
12 Set up the swap file for the system with user specified size and default size ### Acceptance Criteria: * create swap file (or resize); DONE * enable swap file; DONE * deactivate swap file; DONE * delete swap file; DONE * location for swap file (default and by user); DONE * adjust swappiness; Not necessary imo, see here: https://github.com/torvalds/linux/blob/v5.0/Documentation/sysctl/vm.txt#L809 * make "enable swap file" persistent; In Progress 11 https://gitlab.com/marcel.schwarz/linux-tools/-/issues/11 Closed Marcel Schwarz marcel.schwarz No No 2019-12-22 01:53:24 2020-01-25 01:45:08 2020-01-25 01:45:08 Self setup service v1 new module 0 0
13 Install basic command-line tools Install: * bleachbit * nano * xrdp * htop * bash-completion * dialog * powertop * tree 12 https://gitlab.com/marcel.schwarz/linux-tools/-/issues/12 Closed Marcel Schwarz marcel.schwarz No No 2019-12-29 23:05:23 2020-03-20 23:56:19 2020-03-06 00:24:13 Self setup service v1 new module 0 0
14 Set up ssh key based authentication [**Youtube Tutorial**](https://www.youtube.com/watch?v=vpk_1gldOAE) 13 https://gitlab.com/marcel.schwarz/linux-tools/-/issues/13 Open Marcel Schwarz marcel.schwarz No No 2020-01-06 17:40:35 2020-01-06 17:40:35 Self setup service v1 new module 0 0
15 Setup a Minecraft Server (Vanilla) 14 https://gitlab.com/marcel.schwarz/linux-tools/-/issues/14 Open Marcel Schwarz marcel.schwarz No No 2020-01-09 20:07:17 2020-01-09 20:07:17 Self setup service v2 new module 0 0
16 Investigate usage of new cli (like the gcloud one) https://cloud.google.com/sdk/gcloud/?hl=de \ https://cloud.google.com/sdk/gcloud/reference/firebase/test/android/run \ https://cloud.google.com/sdk/gcloud/reference/topic/arg-files \ 15 https://gitlab.com/marcel.schwarz/linux-tools/-/issues/15 Closed Marcel Schwarz marcel.schwarz No No 2020-01-11 03:11:09 2020-01-21 23:29:31 2020-01-21 23:29:30 Self setup service v1 0 0
17 Dev-Ops to create ELF File PyInstaller Docs: https://pyinstaller.readthedocs.io/en/stable/index.html 16 https://gitlab.com/marcel.schwarz/linux-tools/-/issues/16 Open Marcel Schwarz marcel.schwarz No No 2020-01-19 20:42:42 2022-12-22 18:50:12 0 0
18 Swap module -> fix /etc/fstab entry problem **Problem: entries in /etc/fstab** To make the swap persistent an entry is added to the /etc/fstab file. Anyway if the swap is resized there will also be another entry added to /etc/fstab. Also when the swap is deleted the entry in /etc/fstab isn´t. Problems to fix: - Make sure entry for persistent swap file only exists once! - Check if entry is already there when resizing and prevent double entries! - Delete entry when swap gets deleted! 17 https://gitlab.com/marcel.schwarz/linux-tools/-/issues/17 Closed Lucas Noki lucas.noki Lucas Noki lucas.noki No No 2020-01-27 08:54:33 2020-02-01 02:32:58 2020-02-01 02:31:42 bug 0 0
19 Update Module Executes update tasks with the apt package manager apt update apt upgrade apt dist-upgrade apt autoremove apt autoclean 18 https://gitlab.com/marcel.schwarz/linux-tools/-/issues/18 Closed Marcel Schwarz marcel.schwarz No No 2020-03-05 16:17:49 2020-03-05 19:11:34 2020-03-05 19:11:34 Self setup service v1 new module 0 0
20 Bash script to prepare the system for the first use of the python based cli 19 https://gitlab.com/marcel.schwarz/linux-tools/-/issues/19 Closed Marcel Schwarz marcel.schwarz No No 2020-03-05 19:14:25 2020-03-05 20:41:02 2020-03-05 20:41:02 Self setup service v1 0 0
21 Start up a quick teamspeak server on docker 20 https://gitlab.com/marcel.schwarz/linux-tools/-/issues/20 Closed Marcel Schwarz marcel.schwarz No No 2020-03-17 01:03:48 2020-03-25 00:39:20 2020-03-21 21:53:32 Self setup service v2 new module 0 7200
22 Docker module Pull latest: ``` docker images | grep -v REPOSITORY| awk '{print $1}'| xargs -L1 docker pull ``` Pull by Tag: ``` docker images | grep -v REPOSITORY | awk '{printf $1; printf ":"; print $2}' | xargs -L1 docker pull ``` To Update all already pulled images 21 https://gitlab.com/marcel.schwarz/linux-tools/-/issues/21 Open Marcel Schwarz marcel.schwarz No No 2020-03-21 04:55:22 2020-04-09 22:29:56 new module 0 0
23 Add git in basic tools installer * git * git-lfs 22 https://gitlab.com/marcel.schwarz/linux-tools/-/issues/22 Open Marcel Schwarz marcel.schwarz No No 2020-06-23 20:34:44 2020-06-23 20:34:44 0 0
24 Make project release ready 23 https://gitlab.com/marcel.schwarz/linux-tools/-/issues/23 Closed Marcel Schwarz marcel.schwarz Marcel Schwarz marcel.schwarz No No 2020-08-01 22:53:47 2020-08-05 13:58:40 2020-08-05 13:58:40 0 0
25 Decorator for needed packages * To check if a packe needs to be installed a sqlite db is used 24 https://gitlab.com/marcel.schwarz/linux-tools/-/issues/24 Open Marcel Schwarz marcel.schwarz No No 2020-08-22 03:13:53 2021-09-11 00:33:05 0 0
26 Update bashrc with useful functions https://linuxize.com/post/bash-functions/ 25 https://gitlab.com/marcel.schwarz/linux-tools/-/issues/25 Open Marcel Schwarz marcel.schwarz No No 2020-12-26 01:41:32 2020-12-26 01:41:32 0 0
27 WSL Module WSL2 Linux Module to free up caches and compact memory See [Microsoft Blog](https://devblogs.microsoft.com/commandline/memory-reclaim-in-the-windows-subsystem-for-linux-2/) `echo 1 > /proc/sys/vm/drop_caches` `echo 1 > /proc/sys/vm/compact_memory` needs to run as root (sudo doesn't work) 26 https://gitlab.com/marcel.schwarz/linux-tools/-/issues/26 Open Marcel Schwarz marcel.schwarz No No 2021-04-01 21:24:37 2021-04-01 21:24:37 new module 0 0

View File

@ -0,0 +1,61 @@
import argparse
import sqlite3
import subprocess
# cmd = """dpkg-query -f '\{"package": "${Package}", "version": "${Version}", "arch": "${Architecture}", "source": "${Source}", "desc": "${binary:Synopsis}"\}\\n' -W"""
cmd = """dpkg-query -f '${Package}\\t${Version}\\t${Architecture}\\t${Source}\\t${binary:Synopsis}\\n' -W"""
db = sqlite3.connect("pkg-list.db")
cur = db.cursor()
parser = argparse.ArgumentParser()
parser.add_argument("-s", "--search")
args = parser.parse_args()
def load_list():
global cur
cur.execute("DROP TABLE IF EXISTS Packages")
cur.execute(
"""CREATE TABLE
Packages(
pkg TEXT PRIMARY KEY,
version TEXT NOT NULL,
architecture TEXT NOT NULL,
parent TEXT,
description TEXT NOT NULL
)"""
)
packages = subprocess.check_output(cmd, shell=True).decode("UTF-8")
for line in packages.splitlines():
name, version, arch, source, desc = line.split("\t")
cur.execute(
"INSERT OR REPLACE INTO Packages VALUES (?,?,?,?,?)",
(name, version, arch, source, desc)
)
db.commit()
def list_packages():
global cur
results = cur.execute("SELECT * FROM Packages")
for res in results.fetchall():
print(res)
def is_installed(pkg):
global cur
results = cur.execute("SELECT version FROM Packages WHERE pkg = ?", (pkg,))
return len(results.fetchall()) > 0
def what_does(pkg):
global cur
results = cur.execute("SELECT description FROM Packages WHERE pkg = ?", (pkg,)).fetchone()
return results[0] if results and len(results) > 0 else "Package was not found"
load_list()
# list_packages()
# print(is_installed("sed"))
print(f"{args.search} is installed") if is_installed(args.search) else print(f"{args.search} is not installed")