Conflicts:
	scripts/tunnel
This commit is contained in:
Geoffrey Frogeye 2016-11-20 14:41:33 +01:00
commit 2803838314
10 changed files with 349 additions and 397 deletions

5
bashrc
View file

@ -19,12 +19,11 @@ fi
export USER=$(whoami) export USER=$(whoami)
export HOSTNAME=$(cat /etc/hostname) export HOSTNAME=$(cat /etc/hostname)
HOST=${HOSTNAME//geoffrey-/} HOST=${HOSTNAME%%.*}
PS1="\[\e]2;\u@${HOST} \w\a\]\[\e[0;37m\][\[\e[0;${col}m\]\u\[\e[0;37m\]@\[\e[0;34m\]${HOST} \[\e[0;36m\]\W\[\e[0;37m\]]\$\[\e[1;97m\] " PS1="\[\e]2;\u@${HOST} \w\a\]\[\e[0;37m\][\[\e[0;${col}m\]\u\[\e[0;37m\]@\[\e[0;34m\]${HOST} \[\e[0;36m\]\W\[\e[0;37m\]]\$\[\e[0m\] "
PS2="> " PS2="> "
PS3="+ " PS3="+ "
PS4="+ " PS4="+ "
trap 'echo -ne "\e[0m"' DEBUG
# Vars # Vars

View file

@ -96,7 +96,7 @@
# #
# If this option is set to mouse or keyboard, the monitor option # If this option is set to mouse or keyboard, the monitor option
# will be ignored. # will be ignored.
follow = mouse follow = none
# Should a notification popped up from history be sticky or timeout # Should a notification popped up from history be sticky or timeout
# as if it would normally do. # as if it would normally do.
@ -162,19 +162,19 @@
# Xev might be helpful to find names for keys. # Xev might be helpful to find names for keys.
# Close notification. # Close notification.
close = mod1+space close = mod4+n
# Close all notifications. # Close all notifications.
# close_all = ctrl+shift+space # close_all = ctrl+shift+space
close_all = ctrl+mod1+space close_all = ctrl+mod4+n
# Redisplay last message(s). # Redisplay last message(s).
# On the US keyboard layout "grave" is normally above TAB and left # On the US keyboard layout "grave" is normally above TAB and left
# of "1". # of "1".
history = ctrl+mod4+h history = shift+mod4+n
# Context menu. # Context menu.
context = ctrl+alt+c context = mod1+mod4+n
[urgency_low] [urgency_low]
# IMPORTANT: colors have to be defined in quotation marks. # IMPORTANT: colors have to be defined in quotation marks.

26
config/htop/htoprc Normal file
View file

@ -0,0 +1,26 @@
# Beware! This file is rewritten by htop when settings are changed in the interface.
# The parser is also very primitive, and not human-friendly.
fields=0 48 17 18 38 39 40 2 46 47 49 1
sort_key=46
sort_direction=1
hide_threads=0
hide_kernel_threads=0
hide_userland_threads=0
shadow_other_users=0
show_thread_names=0
show_program_path=1
highlight_base_name=0
highlight_megabytes=0
highlight_threads=1
tree_view=0
header_margin=0
detailed_cpu_time=0
cpu_count_from_zero=0
update_process_names=0
account_guest_in_cpu_meter=0
color_scheme=0
delay=15
left_meters=AllCPUs Memory Swap
left_meter_modes=1 1 1
right_meters=Tasks LoadAverage Uptime
right_meter_modes=2 2 2

View file

@ -29,8 +29,8 @@ font pango:Sans 8
floating_modifier $mod floating_modifier $mod
# kill focused window # kill focused window
#bindsym $mod+F4 kill bindsym $mod+z kill
bindsym Mod1+F4 kill #bindsym Mod1+F4 kill
bindsym button2 kill bindsym button2 kill
# start dmenu (a program launcher) # start dmenu (a program launcher)
@ -81,11 +81,11 @@ bindsym $mod+j focus down
bindsym $mod+k focus up bindsym $mod+k focus up
bindsym $mod+l focus right bindsym $mod+l focus right
# alternatively, you can use the cursor keys: ## alternatively, you can use the cursor keys:
bindsym $mod+Left focus left #bindsym $mod+Left focus left
bindsym $mod+Down focus down #bindsym $mod+Down focus down
bindsym $mod+Up focus up #bindsym $mod+Up focus up
bindsym $mod+Right focus right #bindsym $mod+Right focus right
# move focused window # move focused window
bindsym $mod+Shift+h move left bindsym $mod+Shift+h move left
@ -93,11 +93,11 @@ bindsym $mod+Shift+j move down
bindsym $mod+Shift+k move up bindsym $mod+Shift+k move up
bindsym $mod+Shift+l move right bindsym $mod+Shift+l move right
# alternatively, you can use the cursor keys: ## alternatively, you can use the cursor keys:
bindsym $mod+Shift+Left move left #bindsym $mod+Shift+Left move left
bindsym $mod+Shift+Down move down #bindsym $mod+Shift+Down move down
bindsym $mod+Shift+Up move up #bindsym $mod+Shift+Up move up
bindsym $mod+Shift+Right move right #bindsym $mod+Shift+Right move right
# workspace back and forth (with/without active container) # workspace back and forth (with/without active container)
workspace_auto_back_and_forth yes workspace_auto_back_and_forth yes
@ -167,16 +167,28 @@ bindsym $mod+9 workspace $WS9
bindsym $mod+0 workspace $WS10 bindsym $mod+0 workspace $WS10
#navigate workspaces next / previous #navigate workspaces next / previous
bindsym $mod+Ctrl+Left workspace prev_on_output bindsym $mod+Ctrl+h workspace prev_on_output
bindsym $mod+Ctrl+Right workspace next_on_output bindsym $mod+Ctrl+l workspace next_on_output
bindsym $mod+Ctrl+Down workspace prev bindsym $mod+Ctrl+j workspace prev
bindsym $mod+Ctrl+Up workspace next bindsym $mod+Ctrl+k workspace next
##navigate workspaces next / previous (arrow keys)
#bindsym $mod+Ctrl+Left workspace prev_on_output
#bindsym $mod+Ctrl+Right workspace next_on_output
#bindsym $mod+Ctrl+Down workspace prev
#bindsym $mod+Ctrl+Up workspace next
# Move to workspace next / previous with focused container # Move to workspace next / previous with focused container
bindsym $mod+Ctrl+Shift+Left move container to workspace prev_on_output; workspace prev_on_output bindsym $mod+Ctrl+Shift+h move container to workspace prev_on_output; workspace prev_on_output
bindsym $mod+Ctrl+Shift+Right move container to workspace next_on_output; workspace next_on_output bindsym $mod+Ctrl+Shift+l move container to workspace next_on_output; workspace next_on_output
bindsym $mod+Ctrl+Shift+Down move container to workspace prev; workspace prev bindsym $mod+Ctrl+Shift+j move container to workspace prev; workspace prev
bindsym $mod+Ctrl+Shift+Up move container to workspace next; workspace next bindsym $mod+Ctrl+Shift+k move container to workspace next; workspace next
## Move to workspace next / previous with focused container (arrow keys)
#bindsym $mod+Ctrl+Shift+Left move container to workspace prev_on_output; workspace prev_on_output
#bindsym $mod+Ctrl+Shift+Right move container to workspace next_on_output; workspace next_on_output
#bindsym $mod+Ctrl+Shift+Down move container to workspace prev; workspace prev
#bindsym $mod+Ctrl+Shift+Up move container to workspace next; workspace next
# move focused container to workspace # move focused container to workspace
bindsym $mod+ctrl+1 move container to workspace $ws1 bindsym $mod+ctrl+1 move container to workspace $ws1
@ -202,11 +214,17 @@ bindsym $mod+shift+8 move container to workspace $ws8; workspace $ws8
bindsym $mod+shift+9 move container to workspace $ws9; workspace $ws9 bindsym $mod+shift+9 move container to workspace $ws9; workspace $ws9
bindsym $mod+shift+0 move container to workspace $ws10; workspace $ws10 bindsym $mod+shift+0 move container to workspace $ws10; workspace $ws10
# move workspaces to screen ## move workspaces to screen
bindsym $mod+ctrl+shift+r move workspace to output right #bindsym $mod+ctrl+shift+r move workspace to output right
bindsym $mod+ctrl+shift+l move workspace to output left #bindsym $mod+ctrl+shift+l move workspace to output left
bindsym $mod+Ctrl+Shift+u move workspace to output above #bindsym $mod+Ctrl+Shift+u move workspace to output above
bindsym $mod+Ctrl+Shift+d move workspace to output below #bindsym $mod+Ctrl+Shift+d move workspace to output below
# move workspaces to screen (arrow keys)
bindsym $mod+ctrl+shift+Right move workspace to output right
bindsym $mod+ctrl+shift+Left move workspace to output left
bindsym $mod+Ctrl+Shift+Up move workspace to output above
bindsym $mod+Ctrl+Shift+Down move workspace to output below
# Open applications on specific workspaces # Open applications on specific workspaces
assign [class="Thunderbird"] $WS7 assign [class="Thunderbird"] $WS7
@ -263,16 +281,16 @@ mode "Resize" {
# Pressing right will grow the windows width. # Pressing right will grow the windows width.
# Pressing up will shrink the windows height. # Pressing up will shrink the windows height.
# Pressing down will grow the windows height. # Pressing down will grow the windows height.
bindsym j resize shrink width 10 px or 10 ppt bindsym h resize shrink width 10 px or 10 ppt
bindsym k resize grow height 10 px or 10 ppt bindsym j resize grow height 10 px or 10 ppt
bindsym i resize shrink height 10 px or 10 ppt bindsym k resize shrink height 10 px or 10 ppt
bindsym l resize grow width 10 px or 10 ppt bindsym l resize grow width 10 px or 10 ppt
# same bindings, but for the arrow keys ## same bindings, but for the arrow keys
bindsym Left resize shrink width 10 px or 10 ppt #bindsym Left resize shrink width 10 px or 10 ppt
bindsym Down resize grow height 10 px or 10 ppt #bindsym Down resize grow height 10 px or 10 ppt
bindsym Up resize shrink height 10 px or 10 ppt #bindsym Up resize shrink height 10 px or 10 ppt
bindsym Right resize grow width 10 px or 10 ppt #bindsym Right resize grow width 10 px or 10 ppt
# back to normal: Enter or Escape # back to normal: Enter or Escape
bindsym Return mode "default" bindsym Return mode "default"

9
screenrc Normal file
View file

@ -0,0 +1,9 @@
term xterm-256color
hardstatus off
hardstatus alwayslastline
hardstatus alwayslastline '%{= G}[ %{G}%H %{g}][%= %{= w}%?%-Lw%?%{= R}%n*%f %t%?%{= R}(%u)%?%{= w}%+Lw%?%= %{= g}][ %{y}Load: %l %{g}][%{B}%Y-%m-%d %{W}%c:%s %{g}]'
startup_message off
termcapinfo xterm* ti@:te@
vbell off
altscreen on
windowlist string "%4n %h%=%f"

30
scripts/debloc-custom.sh Executable file
View file

@ -0,0 +1,30 @@
#!/usr/bin/env bash
# Installs all programs on the system
function debloc-custom-cli {
# Utils
debloc-install moreutils screen ncdu htop sl proxytunnel pass
# Text editor
debloc-install vim exuberant-ctags
# Dev
debloc-install build-essential cmake clang
}
function debloc-custom {
debloc-custom-cli
# Desktop manager
debloc-install i3 dmenu dunst unclutter xautolock feh numlockx scrot
# qutebrowser
debloc-install python3-lxml python-tox python3-pyqt5 python3-pyqt5.qtwebkit python3-sip python3-jinja2 python3-pygments python3-yaml
TMP_DIR=$(mktemp -d)
$(cd $TMP_DIR; wget --quiet https://qutebrowser.org/python3-pypeg2_2.15.2-1_all.deb)
$(cd $TMP_DIR; wget --quiet https://github.com/The-Compiler/qutebrowser/releases/download/v0.8.4/qutebrowser_0.8.4-1_all.deb)
debloc-deb $TMP_DIR/*.deb
rm -rf $TMP_DIR
}

224
scripts/debloc.sh Executable file
View file

@ -0,0 +1,224 @@
#!/usr/bin/env bash
ARCH=$(dpkg --print-architecture)
DEBLOC_DB=$HOME/.config/debloc/$ARCH
DEBLOC_ROOT=$HOME/.debloc/$ARCH
# TODO Configurable
DEBIAN_MIRROR=http://debian.polytech-lille.fr/debian
mkdir -p $DEBLOC_DB &> /dev/null
mkdir -p $DEBLOC_ROOT &> /dev/null
export PATH="$DEBLOC_ROOT/usr/bin:$DEBLOC_ROOT/usr/games/:$DEBLOC_ROOT/usr/lib/git-core:$PATH"
export LD_LIBRARY_PATH="$DEBLOC_ROOT/lib:$LD_LIBRARY_PATH"
export PYTHONPATH="$DEBLOC_ROOT/usr/lib/python3:$PYTHONPATH"
export QT_QPA_PLATFORM_PLUGIN_PATH="$DEBLOC_ROOT/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms"
# Tell if a package exists
function _debloc-exists { # package
LANG=C apt-cache show $1 &> /dev/null
if [ $? == 0 ]; then
return 1
else
return 0
fi
}
# Return the real package associated with a virtual package
# If not a virtual package, return the input
function _debloc-filterVirtual { # package
pkg=$1
LANG=C apt-cache policy $1 | grep "Candidate" | grep "(none)" > /dev/null
if [ $? == 0 ]; then
# TODO This is not really accurate
LANG=C apt-cache showpkg $pkg | tail -1 | cut -d ' ' -f 1
else
echo $pkg
fi
return 0
}
# Tell if a package is installed via debloc
function _debloc-locallyInstalled { # package
if [ -e $DEBLOC_DB/$1 ]; then
return 1
else
return 0
fi
}
# Tell if a package is installed system-wide
function _debloc-globallyInstalled { # package
LANG=C apt-cache policy $1 | grep "Installed" | grep "(none)" > /dev/null
return $?
}
# Get informations about a package
function _debloc-packageShow { # package
LANG=C apt-cache show $1 | while read line; do
if [ "$line" == '' ]; then
break
fi
echo "$line"
done
return 0
}
# Get the path of a package
function _debloc-packagePath { # package
_debloc-packageShow $1 | grep "^Filename:" | head -1 | cut -d ':' -f 2 | sed -e 's/^[[:space:]]*//'
return 0
}
# Get the md5sum of a package
function _debloc-packageMd5sum { # package
_debloc-packageShow $1 | grep "^MD5sum:" | cut -d ':' -f 2 | sed -e 's/^[[:space:]]*//'
return 0
}
# Update symbolics links in $DEBLOC_ROOT/lib
function _debloc-ldconfig {
mkdir -p $DEBLOC_ROOT/lib &> /dev/null
rm -f $DEBLOC_ROOT/lib/* &> /dev/null
if [ -e $DEBLOC_ROOT/usr/lib ]; then
find $DEBLOC_ROOT/usr/lib -type f -name "*.so*" | while read lib; do
ln --symbolic --force "$lib" "$DEBLOC_ROOT/lib/$(basename $lib)"
done
find $DEBLOC_ROOT/usr/lib -type l -name "*.so*" | while read link; do
yes | cp --force --no-dereference --preserve=links "$link" "$DEBLOC_ROOT/lib/" &> /dev/null
done
fi
}
# Install debian archive
function _debloc-installDeb { # path
TMP_DIR=$(mktemp -d) &> /dev/null
$(cd $TMP_DIR; ar x "$1")
TAR_FILE=$(find $TMP_DIR -type f -name "data.tar.*" | head -1)
if [ -e "$TAR_FILE" ]; then
# Output for DB saving
tar tf $TAR_FILE
tar xf $TAR_FILE -C $DEBLOC_ROOT
# _debloc-ldconfig
mkdir -p $DEBLOC_ROOT/lib &> /dev/null
tar tf $TAR_FILE | grep '^./usr/lib/' | grep '\.so' | while read file; do
lib=$(readlink -f $DEBLOC_ROOT/$file)
if [ -f $lib ]; then
ln --symbolic --force "$lib" "$DEBLOC_ROOT/lib/$(basename $file)"
fi
if [ -h $lib ]; then
yes | cp --force --no-dereference --preserve=links "$(basename $link)" "$DEBLOC_ROOT/lib/" &> /dev/null
fi
done
fi
rm -rf $TMP_DIR &> /dev/null
return 0
}
# Install package
function _debloc-install { # package
pkg=$1
echo "→ Downloading"
url=${DEBIAN_MIRROR}/$(_debloc-packagePath $pkg)
DEB_FILE=$(mktemp) &> /dev/null
wget "$url" --quiet -O $DEB_FILE
if [ $? != 0 ]; then
echo "→ Failed!"
return 4
fi
echo "→ Verifying sums"
theo=$(_debloc-packageMd5sum $pkg)
real=$(md5sum $DEB_FILE | cut -d ' ' -f 1)
if [ "$theo" != "$real" ]; then
rm -f $DEB_FILE &> /dev/null
echo "→ Failed!"
return 5
fi
echo "→ Installing"
_debloc-installDeb $DEB_FILE > $DEBLOC_DB/$pkg
echo "→ Done!"
rm -f $DEB_FILE &> /dev/null
return 0
}
# Get the dependencies of a package
function _debloc-packageDeps { # package
LANG=C apt-cache show $1 | grep '^Depends:' | sed 's/Depends: //' | sed 's/, /\n/g' | cut -d ' ' -f 1
return 0
}
# Install package with dependencies
function _debloc-installDeps { # package
pkg=$1
echo "Installing $pkg"
_debloc-packageDeps $pkg | while read dep; do
dep=$(_debloc-filterVirtual $dep)
_debloc-locallyInstalled $dep
if [ $? == 1 ]; then
echo "- Dependency $dep is already installed with Debloc"
continue
fi
_debloc-globallyInstalled $dep
if [ $? == 1 ]; then
echo "- Dependency $dep is already installed on the system"
continue
fi
_debloc-installDeps $dep | while read line; do echo "- $line"; done
done
_debloc-install $pkg
return 0
}
# Install package with dependencies (user version with verifications)
function debloc-install { # package
for pkg in $*; do
pkg=$(_debloc-filterVirtual $pkg)
_debloc-exists $pkg
if [ $? == 0 ]; then
echo "Unknown package $pkg"
continue
fi
_debloc-locallyInstalled $pkg
if [ $? == 1 ]; then
echo "Package $pkg is already installed with Debloc"
continue
fi
_debloc-globallyInstalled $pkg
if [ $? == 1 ]; then
echo "Package $pkg is already installed on the system"
continue
fi
_debloc-installDeps $pkg
done
return 0
}
# Install debian archive (user version with verifications)
function debloc-deb { # path
for path in $*; do
if [ ! -f "$path" ]; then
echo "$path is not a file"
return 6
fi
echo "Installing $(basename $path)"
_debloc-installDeb "$(readlink -f $path)" > $DEBLOC_DB/$(basename $path)
done
return 0
}
# Remove every package installed with Debloc
function debloc-flush {
rm -rf $DEBLOC_ROOT/* &> /dev/null
rm -f $DEBLOC_DB/* &> /dev/null
}

3
scripts/index.sh Normal file → Executable file
View file

@ -1,3 +1,4 @@
source ~/.scripts/proxy.sh source ~/.scripts/proxy.sh
source ~/.scripts/locinst.sh source ~/.scripts/debloc.sh
source ~/.scripts/debloc-custom.sh
alias beep=~/.scripts/beep.sh alias beep=~/.scripts/beep.sh

View file

@ -1,152 +0,0 @@
#!/usr/bin/env python3
import json
import urllib.request
import subprocess
import os
import sys
import re
LOCINST_DIR=os.environ['HOME']+'/.locinst'
LOCINST_DB=os.environ['HOME']+'/.config/locinst'
LOCINST_TMP='/tmp/locinst'
DEBIAN_MIRROR = 'http://debian.polytech-lille.fr/debian/'
def globallyInstalled(name):
try:
a = subprocess.check_output(['apt-cache', 'policy', name]).decode('utf8').strip().lower()
return 'installé\xa0: (aucun)' not in [b.strip() for b in a.split('\n')]
except FileNotFoundError:
return False
def locallyInstalled(name):
return False
def debian_install(name):
def findPackage(name):
raw = urllib.request.urlopen('http://sources.debian.net/api/search/' + name + '/')
data = json.loads(raw.read().decode('utf8'))
results = data['results']
if results['exact']:
return True
else:
print("Package " + name + " does not exist" + (", however you might want to try one of the following: " + ", ".join([pkg['name'] for pkg in results['other']]) if results['other'] else "") + ".")
return False
def findVersion(name):
raw = urllib.request.urlopen('http://sources.debian.net/api/src/' + name + '/')
data = json.loads(raw.read().decode('utf8'))
def findByCodename(codename):
goodVersions = [version['version'] for version in data['versions'] if codename in version['suites']]
return goodVersions[0] if len(goodVersions) else False
try:
codename = subprocess.check_output(['lsb_release', '--codename', '--short']).decode('utf8').strip().lower()
choice = findByCodename(codename)
if choice:
return choice
except FileNotFoundError:
pass
return findByCodename('jessie')
def parseInfos(control):
paragraph = {}
key = ''
for line in control.strip().split('\n'):
if re.match('\s', line[0]):
try:
paragraph[key] += '\n' + line.strip()
except KeyError:
pass
elif re.match('^[\w-]+\:', line):
key = line.split(':')[0].lower()
paragraph[key] = line[len(key)+1:].strip()
return paragraph
def getArch():
arch = subprocess.check_output(['uname', '--machine']).decode('utf8').strip().lower()
if arch == 'x86_64':
arch = 'amd64'
return arch
def download(name, version):
arch = getArch()
filename = name + '_' + version + '_' + arch
print("Downloading " + filename + "...")
url = DEBIAN_MIRROR + 'pool/main/' + (name[0] if name[0:3] != 'lib' else name[0:4]) + '/' + name + '/' + filename + '.deb'
debfile = LOCINST_TMP + '/' + filename + '.deb'
urllib.request.urlretrieve(url, debfile)
extractdir = LOCINST_TMP + '/' + filename
try:
os.mkdir(extractdir)
except FileExistsError:
pass
subprocess.check_call(['ar', 'x', debfile], cwd=extractdir)
subprocess.check_call(['rm', '-rf', debfile], stdout=subprocess.DEVNULL)
controltar = [a for a in os.listdir(extractdir) if a.split('.')[:2] == ['control', 'tar']][0]
subprocess.check_call(['tar', 'xf', extractdir + '/' + controltar], cwd=extractdir)
with open(extractdir + '/control') as controlfile:
control = controlfile.read()
finaldir = LOCINST_TMP + '/' + name
try:
os.mkdir(finaldir)
except FileExistsError:
pass
datatar = [a for a in os.listdir(extractdir) if a.split('.')[:2] == ['data', 'tar']][0]
subprocess.check_call(['tar', 'xf', extractdir + '/' + datatar], cwd=finaldir)
subprocess.check_call(['rm', '-rf', extractdir])
return {
'final': finaldir,
'control': control
}
if not findPackage(name):
return 4
if globallyInstalled(name):
return 5
print("Installing " + name + "...")
version = findVersion(name)
if not version:
return 6
d = download(name, version)
finaldir, control = d['final'], d['control']
infos = parseInfos(control)
if 'depends' in infos:
for dep in infos['depends'].split(', '):
dep = dep.strip().split(' ')[0]
if not globallyInstalled(dep):
# print("Installing " + dep + " as a dependency")
# debian_install(dep)
# TODO For compatibility until locinst.sh is rewritten
try:
subprocess.check_call([os.environ['HOME'] + '/.scripts/locinst.sh', 'debian', dep])
except subprocess.CalledProcessError:
pass
if 'recommends' in infos:
for rec in infos['recommends'].split(','):
print(name + " suggests you to install: " + rec.strip())
return 0
# TODO For compatibility until locinst.sh is rewritten
exit(debian_install(sys.argv[1]))

View file

@ -1,203 +0,0 @@
#!/bin/bash
# Local package installer
# Config
export LOCINST_DIR="$HOME/.locinst/"
#export LOCINST_DB="$XDG_CONFIG_HOME/locinst/"
export LOCINST_DB="$HOME/.config/locinst/"
# Constants
LOCINST_TMP=/tmp/locinst
# Path set
export PATH="$LOCINST_DIR/bin:$LOCINST_DIR/usr/bin:$LOCINST_DIR/usr/games/:$PATH"
export LD_LIBRARY_PATH="$LOCINST_DIR/lib:$LOCINST_DIR/usr/lib:$LD_LIBRARY_PATH"
# Dir set
if [ ! -d "$LOCINST_DIR" ]; then
mkdir -p "$LOCINST_DIR"
# TODO Add symbolic links and stuff
fi
if [ ! -d "$LOCINST_TMP" ]; then
mkdir -p "$LOCINST_TMP"
fi
if [ ! -d "$LOCINST_DB" ]; then
mkdir -p "$LOCINST_DB"
fi
# Misc functions
function step { # str
echo "--> $1"
}
function error { # str
echo "ERR $1"
}
# Providers
# Args package_destination, package[, extra_info]
# 0: No error, must have put the uncompressed package in $package_destination
# 1: Generic error
# 4: Package not found on repo
# 5: Package already installed on system
function locinst_arch {
function getPageLink { # package, arch, repo
echo "https://www.archlinux.org/packages/$3/$2/$1/"
}
function getDlLink { # package, arch, repo
echo "$(getPageLink $1 $2 $3)download/"
}
function findPackage { # package
function testLink { # link
wget -q --max-redirect 0 "$1" -O /dev/null
return $?
}
function testPackage { # package, arch, repo
link="$(getPageLink $1 $2 $3)"
testLink "$link"
return $?
}
for repo in community core extra
do
for arch in any $(uname -m)
do
testPackage $1 $arch $repo
if [ $? -eq 0 ]; then
echo "$arch:$repo"
return 0
fi
done
done
return 1
}
dest="$1"
package=$2
step "Finding $package"
data=$(findPackage $package)
if [ $? -ne 0 ]; then
return 4
fi
arch=$(cut -d ":" -f 1 <<< "$data")
repo=$(cut -d ":" -f 2 <<< "$data")
step "Downloading $repo/$package-$arch"
link=$(getDlLink $package $arch $repo)
destcmp="$LOCINST_TMP/$package.tar.xz"
wget $link -O $destcmp
step "Extracting package"
tar xf "$destcmp" -C "$dest"
# TODO Parse .PKGINFO for dependency
# TODO Check if already on system
rm -f $dest/.MTREE $dest/.PKGINFO
rm "$destcmp"
return 0
}
function locinst_pypi {
dest=$1
shift
tar=$LOCINST_TMP/$1.tar.gz
char=`echo $1 | cut -c1-1`
wget "https://pypi.python.org/packages/source/$char/$1/$1-$2.tar.gz" -O $tar --no-check-certificate
preinst=$LOCINST_TMP/$1-$2/
tar xf $tar -C $LOCINST_TMP
mkdir -p $dest/lib/python
export PYTHONPATH="$dest/lib/python:$PYTHONPATH"
(cd $preinst; python3 setup.py install --home=$dest)
rm -rf $tar $preinst
}
# Master function
function locinst { # action package [other_info]*
function remove { # package
package=$1
index=$LOCINST_DB/$package
# TODO Filter common things, also delete folders
(cd $LOCINST_DIR; cat $index | while read file; do rm -f "$file"; done)
rm -f $index
}
action=$1
package=$2
shift; shift
dest=$LOCINST_TMP/$package
if [ ! -d "$dest" ]; then
mkdir -p "$dest"
fi
case $action in
"remove")
step "Removing $package"
remove $package
return $?
;;
"arch")
locinst_arch $dest $package $*
code=$?
;;
"pypi")
locinst_pypi $dest $package $*
code=$?
;;
"debian")
$HOME/.scripts/locinst.py $package $*
code=$?
;;
*)
#error "I don't know what to do. And don't beg for help with the commands."
return 1
;;
esac
# From now on something was installed
case $code in
0)
index=$LOCINST_DB/$package
if [ -e $index ]; then
step "Removing old instance of $package"
remove $package
fi
step "Installing $package"
(cd $dest; find . -mindepth 2 >> $index)
cp -r $dest/* $LOCINST_DIR/
rm -rf $dest
return 0
;;
4)
error "Package not found!"
;;
5)
error "Package already installed on system!"
;;
6)
error "Could not satisfy version requirements!"
;;
*)
error "Ugh... Something bad happened"
esac
# From now on an error has happened
return $code
}
if [ -n $1 ]; then
locinst $@
fi