Skip to content
This repository has been archived by the owner on May 2, 2024. It is now read-only.

Commit

Permalink
update v0.2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
sharpcdf committed Jul 21, 2022
1 parent a06c654 commit 14da483
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 68 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Note: Building requires the Nim Compiler >= 1.6.6 and Zippy, to get Zippy and ot
To build jitter's installer, clone this repository, run `nim installer`. After building, run `./bin/mug install` to install jitter.
To develop jitter, git clone the repository and run `nim dinstaller` or `nim debug` after making changes.

Warning: both the `debug` and `dinstaller` tasks purely show compiler information at compile time, and the debug installer automatically adds jitter to your path.
Note: Both the `debug` and `dinstaller` tasks purely show compiler information at compile time, and otherwise do the same thing as `release` and `installer`

## Structure
Jitter's source code is separated into two directories. The `mug` directory holds the source code for jitter's installer/updater, mug, while the `src` directory holds the source code for jitter itself.
Expand All @@ -31,10 +31,13 @@ Download the Jitter installer from the releases, and then after navigating to th
1. `jtr install gh:VSCodium/vscodium` - installs repository VSCodium/vscodium from github.
2. `jtr install vscodium` - searches for all repositories that have the name `vscodium`, and then installs the chosen one
3. `jtr search vscodium` - searches and lists all repositories that have `vscodium` in their name.
4. `jtr search VSCodium/vscodium (tag|tags|true)` - searches and lists all release tags of repository `VSCodium/vscodium`
4. `jtr search VSCodium/vscodium` - searches and lists all release tags of repository `VSCodium/vscodium`
5. `jtr list` - lists all executables in jitter's bin.
6. `jtr catalog` - lists all downloaded repositories
7. `jtr remove VSCodium/vscodium` - removes VSCodium/vscodium from your system
8. `jtr install VSCodium/vscodium@1.69.0` - installs VSCodium/vscodium release with the tag `1.69.0`
9. `jtr update VSCodium/vscodium` - updates vscodium to the latest version
10. `jtr update (this|jitter|jtr)` - updates jitter to the latest release
11. `jtr update all` - updates all installed packages

Note: repositories are case insensitive, and all AppImages installed are converted to lowercase. `jtr install VSCodium/vscodium` is equivalent to `jtr install vscodium/vscodium`.
2 changes: 1 addition & 1 deletion config.nims
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import os

var mainfile = "jitter.nim"
var maininstallfile = "mug/installer.nim"
var version = "0.1.0"
var version = "0.2.4"
var nimble = getHomeDir() & ".nimble/pkgs"


Expand Down
60 changes: 46 additions & 14 deletions jitter.nim
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
#[
Term reference-
package refers to repositories downloaded onto your system
repository refers to repositories (duh)
owner refers to the owner of the repository
tag refers to the release tag(typically a version number)
Package folder names follow the pattern owner__repo__tag
All executables added to the bin have no filename and are executable or are AppImages
]#

import std/[terminal, os, strutils, httpclient, json]
import src/parse
import src/github as gh
Expand All @@ -7,7 +18,6 @@ from std/osproc import execCmd
#TODO add 'jtr update all' to update all packages
#TODO add config file to manage bin & download directory
var args: seq[string]
var flags: seq[string]
const version {.strdefine.} = "undefined"
var baseDir = getHomeDir() & ".jitter/"
proc printHelp()
Expand All @@ -26,30 +36,41 @@ if (args.len == 1 and args[0] == "help") or args.len == 0:
printHelp()
quit()
#end

#if theres at least a command passed (e.g. jtr install ...)
if args.len >= 1:
echo "hello there, this is a debug build"
#echo "hello there, this is a debug build"
case args[0]:
of "install":
#ditto
try:
if install(args[1], true): success "Binaries successfully installed"
if install(args[1], true):
success "Binaries successfully installed"
else:
fatal "Failed to install repository"
except:
fatal "No repo given. Read 'jtr help' for more info"
of "update":
#if 2nd arg is this or jtr or jitter, update jitter itself. otherwise, update the given package
try:
if args[1] == "this" or args[1] == "jtr" or args[1] == "jitter":
if install("sharpcdf/jitter", true):
success "Jitter installer successfully downloaded"
else:
fatal "Failed to install jitter"
if execCmd("mug upgrade") != 0: fatal "Failed to upgrade jitter. Try manually upgrading by running 'mug upgrade'"
elif args[1] == "all":
for f in walkDir(baseDir & "nerve"):
echo f.path.splitPath().tail
var g = pkgToGitFormat(f.path.splitPath().tail)
echo g
update(g, getTagFromGit(g))
else:
update(args[1], getTagFromGit(args[1]))
except:
fatal "Update failed"
of "remove":
#if it contains a tag, pass it to remove(), otherwise, run remove() interactively
try:
#if it contains a tag, pass it to remove()
if not args[1].contains("@"):
remove(args[1], "")
else:
Expand All @@ -58,30 +79,36 @@ if args.len >= 1:
except:
fatal "Must provide a package name. Read 'jtr help' for more info"
of "search":
#if 2nd arg is tags or tag or true, print avaliable release tags for the given repo. otherwise, search for a repo
try:
if args[2] == "tags" or args[2] == "tag" or args[2] == "true":
if hasRepoFormat(args[1]):
search(args[1], getTagFromGit(args[1]), true)
else:
fatal "Invalid format, must be 'jtr search owner/repo (tags|tag|true)'"
if hasRepoFormat(args[1]):
search(args[1], getTagFromGit(args[1]), true)
else:
search(args[1], getTagFromGit(args[1]), false)
except:
search(args[1], getTagFromGit(args[1]), false)
fatal "Failed to search"
quit()
of "list":
#lists all executables in .jitter/bin
for f in walkDir(baseDir & "bin"):
let file = extractFilename(f.path)
if f.path == getAppDir() & "jtr" and hasExecPerms(f.path): continue
list file
of "version":
#prints the build version
styledEcho(fgCyan, "Jitter version ", fgYellow, version)
styledEcho("For more information visit ", fgGreen, "https://github.com/sharpcdf/jitter")
quit()
of "catalog":
#lists all installed packages(repos)
for d in walkDir(baseDir & "nerve"):
list pkgToGitFormat(d.path.splitPath().tail)
quit()
else:
printHelp()
fatal "Unknown command"

#ditto
proc printHelp() =
echo """Usage:
jtr <command> [args]
Expand All @@ -104,6 +131,7 @@ proc printHelp() =
"""

#* auto source search, github -> gitlab -> sourcehut -> codeberg
#installs repo interactively or directly based on source and then runs the corrosponding download proc, in the main case its gh.download() for github downloads
proc install(src: string, make: bool): bool =
var name = src
var srctype = parseInputSource(name)
Expand All @@ -122,6 +150,7 @@ proc install(src: string, make: bool): bool =
else:
return false

#removes installed packages from the filesystem
proc remove(pkg, ver: string) =
if not pkg.hasRepoFormat():
fatal "Invalid format given. Check 'jtr help' for more info"
Expand All @@ -131,7 +160,7 @@ proc remove(pkg, ver: string) =
var installed = false

for p in walkDir(baseDir & "nerve"):
if p.path.splitPath.tail.contains(name):
if p.path.splitPath.tail.toLowerAscii().contains(name):
installed = true
if not installed:
fatal "package " & name & " is not installed."
Expand Down Expand Up @@ -199,6 +228,8 @@ proc remove(pkg, ver: string) =
info "Removing folder " & dir
removeDir(baseDir & "nerve/" & all)

#TODO add automatic release tags when provided owner/repo instead of using a bool
#searches for either repos or repo tags based on the arg format (read above)
proc search(repo, ver: string, tags: bool) =
var c = newHttpClient()

Expand Down Expand Up @@ -230,8 +261,9 @@ proc search(repo, ver: string, tags: bool) =
for e in j:
list e["tag_name"].getStr()

#lazy update(the only way for now)
proc update(pkg, tag: string) =
remove(pkg, tag)
var p = pkg
gh.download(p, tag, true)
success "Successfully updated " & pkg
if install(p, true): success "Downloaded latest version"
success "Successfully updated " & pkg
42 changes: 20 additions & 22 deletions mug/installer.nim
Original file line number Diff line number Diff line change
@@ -1,52 +1,50 @@
import std/[terminal, os, httpclient, strutils]

import ../src/log
var base = getHomeDir() & ".jitter/"
var args: seq[string]
const jtr = slurp("../bin/jtr")
var changeEnv = false
proc toEnv()
proc addEnv()

when declared(commandLineParams):
args = commandLineParams()
else:
styledEcho(fgRed, "Error: Unable to get arguments")
quit()
when defined(debug):
changeEnv = true
fatal "Unable to get arguments"

if args.len == 1:
if args[0] == "upgrade":
writeFile(base & "bin/jtr", jtr)
elif args[0] == "install":
if dirExists(base):
styledEcho(fgRed, "Jitter is already installed!")
fatal "Jitter is already installed!"
quit()
styledEcho(fgBlue, "Creating base directory in " & base)
info "Creating base directory in " & base
createDir(base)

styledEcho(fgYellow, "Creating bin and nerve directories")
info "Creating bin and nerve directories"
createDir(base & "bin") #*Where the jitter exe and symlinks to the binaries will be held
createDir(base & "nerve") #*where the actualy binaries will be held

styledEcho(fgGreen, "Creating config directory")
info "Creating config directory"
createDir(base & "config") #*config files

styledEcho(fgBlue, "Extracting jitter")
info "Extracting Jitter"
writeFile(base & "bin/jtr", jtr)

styledEcho(fgYellow, "Setting executable permissions")
info "Setting executable permissions"
setFilePermissions(base & "bin/jtr", {fpOthersExec, fpUserExec, fpGroupExec, fpUserRead, fpUserWrite, fpOthersRead, fpOthersWrite})

if changeEnv: toEnv()
styledEcho(fgMagenta, "Done! Now you can add 'export PATH=$PATH:" & base & "bin' to your .bashrc file to add Jitter to your bash path.")
ask "Do you want to add Jitter to your path? [y/N]"
var i = readLine(stdin)
if i == "yes" or i == "y":
addEnv()
elif i == "no" or i == "n" or i == "":
styledEcho(fgMagenta, "Done! Now you can add 'export PATH=$PATH:" & base & "bin' to your .bashrc file to add Jitter to your bash path.")
elif args[0] == "uninstall":
if dirExists(getHomeDir() & ".jitter"):
styledEcho(fgBlue, "Uninstalling Jitter")
info "Uninstalling Jitter"
removeDir(getHomeDir() & ".jitter")
styledEcho(fgGreen, "Done!")
success "Done!"
else:
styledEcho(fgRed, "Error: No jitter path was found.")
quit()
fatal "Error: No jitter path was found."

if args.len == 0 or (args.len == 1 and args[0] == "help"):
echo """Usage
Expand All @@ -58,7 +56,7 @@ if args.len == 0 or (args.len == 1 and args[0] == "help"):
help Displays this help
"""

proc toEnv() {.deprecated: "Should not be used because of the possible risks".} =
proc addEnv() =
styledEcho(fgGreen, "Adding to path..")
var fcheck = readFile(getHomeDir() & ".bashrc")
if not fcheck.contains("export PATH=$PATH:" & base & "bin"):
Expand All @@ -70,7 +68,7 @@ proc toEnv() {.deprecated: "Should not be used because of the possible risks".}
if fileExists("/usr/bin/fish"):
styledEcho(fgGreen, "Fish shell found, appending jitter to path")
fcheck = readFile(getHomeDir() & ".config/fish/config.fish")
if fcheck.contains("set -U fish_user_paths $fish_user_paths " & base & "bin"):
if not fcheck.contains("set -U fish_user_paths $fish_user_paths " & base & "bin"):
var f = open(getHomeDir() & ".config/fish/config.fish", fmAppend)
f.writeLine("set -U fish_user_paths $fish_user_paths " & base & "bin")
else:
Expand Down
Empty file added src/config.nim
Empty file.
37 changes: 22 additions & 15 deletions src/extract.nim
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
#[
Package folder names have the following format:
REPOOWNER__REPONAME__VERSION
]#

import std/[terminal, os, strutils]
from osproc import execCmdEx
import zippy/tarballs as tb
import zippy/ziparchives as za
import log

import parse
var baseDir = getHomeDir() & ".jitter/"
var nerve = baseDir & "nerve/"

#extracts the archive, runs makefiles, and adds executables to the bin
proc extract*(z, name: string, make: bool) =
info "Extracting files"
#extracts the archive according to the extension, or if its an appimage than just makes a directory for it and adds it to the bin
try:
if z.splitFile().ext == ".zip":
case z.splitFile().ext:
of ".zip":
za.extractAll(z, nerve & name)
else:
of ".tgz", ".gz":
tb.extractAll(z, nerve & name)
of ".AppImage":
createDir(nerve & name)
setFilePermissions(z, {fpUserExec, fpGroupExec, fpOthersExec, fpUserRead, fpUserWrite, fpOthersRead})
moveFile(z, nerve & name & "/" & z.extractFilename())
except ZippyError:
#raise
fatal "Failed to extract archive"
Expand All @@ -29,15 +31,20 @@ proc extract*(z, name: string, make: bool) =
if make:
for f in walkDirRec(nerve & name):
if f.extractFilename().toLowerAscii() == "makefile":
info "Running Makefile in directory " & f.splitFile().dir
if execCmdEx("make -C " & f.splitFile().dir).exitCode != 0:
fatal "Error: failed to make " & f
error "Error: failed to make " & f
else:
success "Done"

info "Adding executables to bin"

#Creates symlinks for executables and adds them to the bin
for f in walkDir(nerve & name):
if f.kind == pcDir: continue
var perms = getFilePermissions(f.path)
if (fpGroupExec in perms or fpOthersExec in perms or fpUserExec in perms) and f.path.splitFile().ext == "":
createSymlink(f.path, baseDir & "bin/" & extractFilename(f.path))
success "Created symlink " & extractFilename(f.path)
for f in walkDirRec(nerve & name):
if hasExecPerms(f):
if f.splitFile().ext == "" or f.splitFile().ext == ".AppImage":
if not symlinkExists(baseDir & "bin/" & f.splitFile().name):
createSymlink(f, baseDir & "bin/" & f.splitFile().name)
success "Created symlink " & f.splitFile().name
else:
error "Symlink " & f.splitFile().name & " already exists, skipping"
Loading

0 comments on commit 14da483

Please sign in to comment.