WIP: Migrate dpkg package #36
@ -1,16 +0,0 @@
|
|||||||
FROM ghcr.io/sirherobrine23/mydockerimage:latest
|
|
||||||
|
|
||||||
# Add non root user and Install oh my zsh
|
|
||||||
ARG USERNAME="devcontainer"
|
|
||||||
ARG USER_UID="1000"
|
|
||||||
ARG USER_GID=$USER_UID
|
|
||||||
RUN groupadd --gid $USER_GID $USERNAME && adduser --disabled-password --gecos "" --shell /usr/bin/zsh --uid $USER_UID --gid $USER_GID $USERNAME && usermod -aG sudo $USERNAME && echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/$USERNAME && chmod 0440 /etc/sudoers.d/$USERNAME && usermod -aG docker $USERNAME
|
|
||||||
USER $USERNAME
|
|
||||||
WORKDIR /home/$USERNAME
|
|
||||||
# Set default entrypoint
|
|
||||||
ENTRYPOINT [ "/usr/local/bin/start.sh" ]
|
|
||||||
RUN yes | sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" && \
|
|
||||||
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting && \
|
|
||||||
git clone https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions && \
|
|
||||||
sed -e 's|ZSH_THEME=".*"|ZSH_THEME="strug"|g' -i ~/.zshrc && \
|
|
||||||
sed -e 's|plugins=(.*)|plugins=(git docker kubectl zsh-syntax-highlighting zsh-autosuggestions)|g' -i ~/.zshrc
|
|
@ -1,60 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "Typescript base",
|
|
||||||
"updateRemoteUserUID": false,
|
|
||||||
"containerUser": "develop",
|
|
||||||
"remoteUser": "develop",
|
|
||||||
"overrideCommand": false,
|
|
||||||
"postCreateCommand": "npm ci",
|
|
||||||
"build": {
|
|
||||||
"dockerfile": "Dockerfile",
|
|
||||||
"args": {
|
|
||||||
"USERNAME": "develop",
|
|
||||||
"USER_UID": "1000"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"runArgs": [
|
|
||||||
"--init",
|
|
||||||
"--privileged"
|
|
||||||
],
|
|
||||||
"mounts": [
|
|
||||||
"target=/var/lib/docker,source=typescript_base,type=volume",
|
|
||||||
"target=/lib/modules/,source=/lib/modules/,type=bind,readonly"
|
|
||||||
],
|
|
||||||
"settings": {
|
|
||||||
"editor.tabSize": 2,
|
|
||||||
"editor.minimap.enabled": false,
|
|
||||||
"files.eol": "\n",
|
|
||||||
"files.trimFinalNewlines": true,
|
|
||||||
"files.trimTrailingWhitespace": true,
|
|
||||||
"googleTranslateExt.replaceText": true,
|
|
||||||
"material-icon-theme.showWelcomeMessage": false,
|
|
||||||
"gitlens.showWelcomeOnInstall": false,
|
|
||||||
"googleTranslateExt.languages": [
|
|
||||||
"en"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"extensions": [
|
|
||||||
"redhat.vscode-yaml",
|
|
||||||
"hookyqr.beautify",
|
|
||||||
"aaron-bond.better-comments",
|
|
||||||
"wmaurer.change-case",
|
|
||||||
"oouo-diogo-perdigao.docthis",
|
|
||||||
"dbaeumer.vscode-eslint",
|
|
||||||
"me-dutour-mathieu.vscode-github-actions",
|
|
||||||
"benshabatnoam.google-translate-ext",
|
|
||||||
"oderwat.indent-rainbow",
|
|
||||||
"tgreen7.vs-code-node-require",
|
|
||||||
"eg2.vscode-npm-script",
|
|
||||||
"christian-kohler.npm-intellisense",
|
|
||||||
"ionutvmi.path-autocomplete",
|
|
||||||
"christian-kohler.path-intellisense",
|
|
||||||
"esbenp.prettier-vscode",
|
|
||||||
"visualstudioexptteam.vscodeintellicode",
|
|
||||||
"vscode-icons-team.vscode-icons",
|
|
||||||
"eamodio.gitlens",
|
|
||||||
"ms-azuretools.vscode-docker",
|
|
||||||
"chrmarti.regex",
|
|
||||||
"formulahendry.code-runner",
|
|
||||||
"euskadi31.json-pretty-printer"
|
|
||||||
]
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
/*.y*ml
|
|
||||||
/example
|
|
||||||
/*[Dd]ocker*
|
|
||||||
node_modules/
|
|
||||||
.devcontainer/
|
|
||||||
.vscode/
|
|
||||||
.github/
|
|
||||||
*.d.ts
|
|
||||||
*.js
|
|
5
.github/dependabot.yml
vendored
5
.github/dependabot.yml
vendored
@ -1,10 +1,5 @@
|
|||||||
version: 2
|
version: 2
|
||||||
updates:
|
updates:
|
||||||
- package-ecosystem: github-actions
|
|
||||||
directory: /
|
|
||||||
schedule:
|
|
||||||
interval: daily
|
|
||||||
|
|
||||||
- package-ecosystem: npm
|
- package-ecosystem: npm
|
||||||
directory: /
|
directory: /
|
||||||
schedule:
|
schedule:
|
||||||
|
70
.github/workflows/publish.yaml
vendored
70
.github/workflows/publish.yaml
vendored
@ -1,70 +0,0 @@
|
|||||||
name: Publish package
|
|
||||||
on:
|
|
||||||
release:
|
|
||||||
types:
|
|
||||||
- prereleased
|
|
||||||
- released
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
publishpackage:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
name: Publish
|
|
||||||
permissions:
|
|
||||||
packages: write
|
|
||||||
contents: write
|
|
||||||
env:
|
|
||||||
PACKAGE_VERSION: ${{ github.ref }}
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
name: Code checkout
|
|
||||||
with:
|
|
||||||
persist-credentials: true
|
|
||||||
ref: main
|
|
||||||
fetch-depth: 2
|
|
||||||
submodules: true
|
|
||||||
|
|
||||||
- name: Setup QEMU to Docker
|
|
||||||
uses: docker/setup-qemu-action@v2
|
|
||||||
|
|
||||||
- name: Setup Buildx
|
|
||||||
uses: docker/setup-buildx-action@v2
|
|
||||||
|
|
||||||
- name: Login into registry Github Packages
|
|
||||||
uses: docker/login-action@v2
|
|
||||||
with:
|
|
||||||
registry: ghcr.io
|
|
||||||
username: ${{ github.actor }}
|
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
# Install basic tools
|
|
||||||
- uses: actions/setup-node@v3
|
|
||||||
name: Setup node.js
|
|
||||||
with:
|
|
||||||
node-version: 18.x
|
|
||||||
registry-url: https://registry.npmjs.org/
|
|
||||||
|
|
||||||
- name: Edit version and install depencies
|
|
||||||
run: |
|
|
||||||
sudo npm i -g semver
|
|
||||||
VERSION="$(semver -c ${{ github.ref_name }})"
|
|
||||||
echo "PACKAGE_VERSION=$VERSION" >> $GITHUB_ENV
|
|
||||||
jq --arg ver $VERSION '.version = $ver' package.json > package2.json
|
|
||||||
mv -fv package2.json package.json
|
|
||||||
|
|
||||||
# Install depencides and build
|
|
||||||
npm install --no-save
|
|
||||||
|
|
||||||
# Publish npm
|
|
||||||
- run: npm publish --access public --tag ${{ github.event.release.prerelease && 'next' || 'latest' }}
|
|
||||||
env:
|
|
||||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
||||||
|
|
||||||
- name: Build image
|
|
||||||
uses: docker/build-push-action@v4
|
|
||||||
with:
|
|
||||||
platforms: "linux/amd64,linux/arm64"
|
|
||||||
context: ./
|
|
||||||
push: true
|
|
||||||
tags: |
|
|
||||||
ghcr.io/sirherobrine23/apt-stream:latest
|
|
||||||
ghcr.io/sirherobrine23/apt-stream:v${{ env.PACKAGE_VERSION }}
|
|
23
.gitignore
vendored
23
.gitignore
vendored
@ -1,21 +1,8 @@
|
|||||||
storage/
|
# Node
|
||||||
/apt*.yml
|
|
||||||
/apt*.yaml
|
|
||||||
/apt*.json
|
|
||||||
.repoTest/
|
|
||||||
thunder-tests
|
|
||||||
*.deb
|
|
||||||
*.key
|
|
||||||
*.pem
|
|
||||||
*.gpg
|
|
||||||
/client_secret*.json
|
|
||||||
|
|
||||||
# Ingore node folders
|
|
||||||
node_modules/
|
|
||||||
/*-lock*
|
/*-lock*
|
||||||
*.tgz
|
node_modules/
|
||||||
|
|
||||||
# Typescript
|
# Typescript
|
||||||
tsconfig.tsbuildinfo
|
src/*/src/**/*.d.ts
|
||||||
*.d.ts
|
src/*/src/**/*.js
|
||||||
*.js
|
*.tsbuildinfo
|
8
.hintrc
8
.hintrc
@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": [
|
|
||||||
"development"
|
|
||||||
],
|
|
||||||
"hints": {
|
|
||||||
"typescript-config/strict": "off"
|
|
||||||
}
|
|
||||||
}
|
|
35
.npmignore
35
.npmignore
@ -1,35 +0,0 @@
|
|||||||
# vscode
|
|
||||||
.devcontainer/
|
|
||||||
.vscode/
|
|
||||||
.hintrc
|
|
||||||
|
|
||||||
# Typescript
|
|
||||||
src/*.ts
|
|
||||||
tsconfig.*
|
|
||||||
|
|
||||||
# node and npm
|
|
||||||
node_modules/
|
|
||||||
/*.tgz
|
|
||||||
|
|
||||||
# Github and Git
|
|
||||||
.github/
|
|
||||||
.git*
|
|
||||||
|
|
||||||
# Docker
|
|
||||||
.dockerignore
|
|
||||||
*docker-compose.yaml
|
|
||||||
*docker-compose.yml
|
|
||||||
*Dockerfile*
|
|
||||||
*dockerfile*
|
|
||||||
|
|
||||||
# Project
|
|
||||||
/apt*.yml
|
|
||||||
/apt*.yaml
|
|
||||||
/apt*.json
|
|
||||||
/example
|
|
||||||
.repoTest/
|
|
||||||
thunder-tests
|
|
||||||
*.deb
|
|
||||||
*.key
|
|
||||||
*.pem
|
|
||||||
*.gpg
|
|
22
.vscode/launch.json
vendored
22
.vscode/launch.json
vendored
@ -1,22 +0,0 @@
|
|||||||
{
|
|
||||||
// Use IntelliSense to learn about possible attributes.
|
|
||||||
// Hover to view descriptions of existing attributes.
|
|
||||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
||||||
"version": "0.2.0",
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "Lauch API",
|
|
||||||
"type": "node",
|
|
||||||
"request": "launch",
|
|
||||||
"internalConsoleOptions": "openOnSessionStart",
|
|
||||||
"skipFiles": ["<node_internals>/**", "node_modules/**"],
|
|
||||||
"cwd": "${workspaceRoot}",
|
|
||||||
"runtimeExecutable": "node",
|
|
||||||
"args": ["src/index.js", "server", "--cluster=0"],
|
|
||||||
"preLaunchTask": {
|
|
||||||
"type": "npm",
|
|
||||||
"script": "build"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
28
.vscode/settings.json
vendored
Normal file
28
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
"files.eol": "\n",
|
||||||
|
"files.encoding": "utf8",
|
||||||
|
"files.defaultLanguage": "javascript",
|
||||||
|
"files.trimFinalNewlines": true,
|
||||||
|
"files.trimTrailingWhitespace": true,
|
||||||
|
"editor.tabSize": 2,
|
||||||
|
"editor.insertSpaces": true,
|
||||||
|
"editor.minimap.enabled": false,
|
||||||
|
"editor.detectIndentation": false,
|
||||||
|
"editor.codeActionsOnSave": {
|
||||||
|
"source.organizeImports": true
|
||||||
|
},
|
||||||
|
"files.exclude": {
|
||||||
|
"**/node_modules/": true,
|
||||||
|
"**/*.d.ts": true,
|
||||||
|
"**/*.js": true
|
||||||
|
},
|
||||||
|
"terminal.integrated.env.windows": {
|
||||||
|
"PATH": "${workspaceFolder}/node_modules/.bin;${env:PATH}"
|
||||||
|
},
|
||||||
|
"terminal.integrated.env.linux": {
|
||||||
|
"PATH": "${workspaceFolder}/node_modules/.bin:${env:PATH}"
|
||||||
|
},
|
||||||
|
"terminal.integrated.env.osx": {
|
||||||
|
"PATH": "${workspaceFolder}/node_modules/.bin:${env:PATH}"
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +0,0 @@
|
|||||||
FROM node
|
|
||||||
RUN apt update && DEBIAN_FRONTEND=noninteractive apt install -y python3 python3-pip && rm -rf /var/lib/apt/*
|
|
||||||
WORKDIR /app
|
|
||||||
COPY package*.json ./
|
|
||||||
RUN npm install
|
|
||||||
COPY . .
|
|
||||||
RUN npm run prepack
|
|
||||||
RUN npm link
|
|
||||||
ENTRYPOINT [ "apt-stream", "server", "--data", "/data" ]
|
|
339
LICENSE
339
LICENSE
@ -1,339 +0,0 @@
|
|||||||
GNU GENERAL PUBLIC LICENSE
|
|
||||||
Version 2, June 1991
|
|
||||||
|
|
||||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
|
||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
|
||||||
of this license document, but changing it is not allowed.
|
|
||||||
|
|
||||||
Preamble
|
|
||||||
|
|
||||||
The licenses for most software are designed to take away your
|
|
||||||
freedom to share and change it. By contrast, the GNU General Public
|
|
||||||
License is intended to guarantee your freedom to share and change free
|
|
||||||
software--to make sure the software is free for all its users. This
|
|
||||||
General Public License applies to most of the Free Software
|
|
||||||
Foundation's software and to any other program whose authors commit to
|
|
||||||
using it. (Some other Free Software Foundation software is covered by
|
|
||||||
the GNU Lesser General Public License instead.) You can apply it to
|
|
||||||
your programs, too.
|
|
||||||
|
|
||||||
When we speak of free software, we are referring to freedom, not
|
|
||||||
price. Our General Public Licenses are designed to make sure that you
|
|
||||||
have the freedom to distribute copies of free software (and charge for
|
|
||||||
this service if you wish), that you receive source code or can get it
|
|
||||||
if you want it, that you can change the software or use pieces of it
|
|
||||||
in new free programs; and that you know you can do these things.
|
|
||||||
|
|
||||||
To protect your rights, we need to make restrictions that forbid
|
|
||||||
anyone to deny you these rights or to ask you to surrender the rights.
|
|
||||||
These restrictions translate to certain responsibilities for you if you
|
|
||||||
distribute copies of the software, or if you modify it.
|
|
||||||
|
|
||||||
For example, if you distribute copies of such a program, whether
|
|
||||||
gratis or for a fee, you must give the recipients all the rights that
|
|
||||||
you have. You must make sure that they, too, receive or can get the
|
|
||||||
source code. And you must show them these terms so they know their
|
|
||||||
rights.
|
|
||||||
|
|
||||||
We protect your rights with two steps: (1) copyright the software, and
|
|
||||||
(2) offer you this license which gives you legal permission to copy,
|
|
||||||
distribute and/or modify the software.
|
|
||||||
|
|
||||||
Also, for each author's protection and ours, we want to make certain
|
|
||||||
that everyone understands that there is no warranty for this free
|
|
||||||
software. If the software is modified by someone else and passed on, we
|
|
||||||
want its recipients to know that what they have is not the original, so
|
|
||||||
that any problems introduced by others will not reflect on the original
|
|
||||||
authors' reputations.
|
|
||||||
|
|
||||||
Finally, any free program is threatened constantly by software
|
|
||||||
patents. We wish to avoid the danger that redistributors of a free
|
|
||||||
program will individually obtain patent licenses, in effect making the
|
|
||||||
program proprietary. To prevent this, we have made it clear that any
|
|
||||||
patent must be licensed for everyone's free use or not licensed at all.
|
|
||||||
|
|
||||||
The precise terms and conditions for copying, distribution and
|
|
||||||
modification follow.
|
|
||||||
|
|
||||||
GNU GENERAL PUBLIC LICENSE
|
|
||||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
|
||||||
|
|
||||||
0. This License applies to any program or other work which contains
|
|
||||||
a notice placed by the copyright holder saying it may be distributed
|
|
||||||
under the terms of this General Public License. The "Program", below,
|
|
||||||
refers to any such program or work, and a "work based on the Program"
|
|
||||||
means either the Program or any derivative work under copyright law:
|
|
||||||
that is to say, a work containing the Program or a portion of it,
|
|
||||||
either verbatim or with modifications and/or translated into another
|
|
||||||
language. (Hereinafter, translation is included without limitation in
|
|
||||||
the term "modification".) Each licensee is addressed as "you".
|
|
||||||
|
|
||||||
Activities other than copying, distribution and modification are not
|
|
||||||
covered by this License; they are outside its scope. The act of
|
|
||||||
running the Program is not restricted, and the output from the Program
|
|
||||||
is covered only if its contents constitute a work based on the
|
|
||||||
Program (independent of having been made by running the Program).
|
|
||||||
Whether that is true depends on what the Program does.
|
|
||||||
|
|
||||||
1. You may copy and distribute verbatim copies of the Program's
|
|
||||||
source code as you receive it, in any medium, provided that you
|
|
||||||
conspicuously and appropriately publish on each copy an appropriate
|
|
||||||
copyright notice and disclaimer of warranty; keep intact all the
|
|
||||||
notices that refer to this License and to the absence of any warranty;
|
|
||||||
and give any other recipients of the Program a copy of this License
|
|
||||||
along with the Program.
|
|
||||||
|
|
||||||
You may charge a fee for the physical act of transferring a copy, and
|
|
||||||
you may at your option offer warranty protection in exchange for a fee.
|
|
||||||
|
|
||||||
2. You may modify your copy or copies of the Program or any portion
|
|
||||||
of it, thus forming a work based on the Program, and copy and
|
|
||||||
distribute such modifications or work under the terms of Section 1
|
|
||||||
above, provided that you also meet all of these conditions:
|
|
||||||
|
|
||||||
a) You must cause the modified files to carry prominent notices
|
|
||||||
stating that you changed the files and the date of any change.
|
|
||||||
|
|
||||||
b) You must cause any work that you distribute or publish, that in
|
|
||||||
whole or in part contains or is derived from the Program or any
|
|
||||||
part thereof, to be licensed as a whole at no charge to all third
|
|
||||||
parties under the terms of this License.
|
|
||||||
|
|
||||||
c) If the modified program normally reads commands interactively
|
|
||||||
when run, you must cause it, when started running for such
|
|
||||||
interactive use in the most ordinary way, to print or display an
|
|
||||||
announcement including an appropriate copyright notice and a
|
|
||||||
notice that there is no warranty (or else, saying that you provide
|
|
||||||
a warranty) and that users may redistribute the program under
|
|
||||||
these conditions, and telling the user how to view a copy of this
|
|
||||||
License. (Exception: if the Program itself is interactive but
|
|
||||||
does not normally print such an announcement, your work based on
|
|
||||||
the Program is not required to print an announcement.)
|
|
||||||
|
|
||||||
These requirements apply to the modified work as a whole. If
|
|
||||||
identifiable sections of that work are not derived from the Program,
|
|
||||||
and can be reasonably considered independent and separate works in
|
|
||||||
themselves, then this License, and its terms, do not apply to those
|
|
||||||
sections when you distribute them as separate works. But when you
|
|
||||||
distribute the same sections as part of a whole which is a work based
|
|
||||||
on the Program, the distribution of the whole must be on the terms of
|
|
||||||
this License, whose permissions for other licensees extend to the
|
|
||||||
entire whole, and thus to each and every part regardless of who wrote it.
|
|
||||||
|
|
||||||
Thus, it is not the intent of this section to claim rights or contest
|
|
||||||
your rights to work written entirely by you; rather, the intent is to
|
|
||||||
exercise the right to control the distribution of derivative or
|
|
||||||
collective works based on the Program.
|
|
||||||
|
|
||||||
In addition, mere aggregation of another work not based on the Program
|
|
||||||
with the Program (or with a work based on the Program) on a volume of
|
|
||||||
a storage or distribution medium does not bring the other work under
|
|
||||||
the scope of this License.
|
|
||||||
|
|
||||||
3. You may copy and distribute the Program (or a work based on it,
|
|
||||||
under Section 2) in object code or executable form under the terms of
|
|
||||||
Sections 1 and 2 above provided that you also do one of the following:
|
|
||||||
|
|
||||||
a) Accompany it with the complete corresponding machine-readable
|
|
||||||
source code, which must be distributed under the terms of Sections
|
|
||||||
1 and 2 above on a medium customarily used for software interchange; or,
|
|
||||||
|
|
||||||
b) Accompany it with a written offer, valid for at least three
|
|
||||||
years, to give any third party, for a charge no more than your
|
|
||||||
cost of physically performing source distribution, a complete
|
|
||||||
machine-readable copy of the corresponding source code, to be
|
|
||||||
distributed under the terms of Sections 1 and 2 above on a medium
|
|
||||||
customarily used for software interchange; or,
|
|
||||||
|
|
||||||
c) Accompany it with the information you received as to the offer
|
|
||||||
to distribute corresponding source code. (This alternative is
|
|
||||||
allowed only for noncommercial distribution and only if you
|
|
||||||
received the program in object code or executable form with such
|
|
||||||
an offer, in accord with Subsection b above.)
|
|
||||||
|
|
||||||
The source code for a work means the preferred form of the work for
|
|
||||||
making modifications to it. For an executable work, complete source
|
|
||||||
code means all the source code for all modules it contains, plus any
|
|
||||||
associated interface definition files, plus the scripts used to
|
|
||||||
control compilation and installation of the executable. However, as a
|
|
||||||
special exception, the source code distributed need not include
|
|
||||||
anything that is normally distributed (in either source or binary
|
|
||||||
form) with the major components (compiler, kernel, and so on) of the
|
|
||||||
operating system on which the executable runs, unless that component
|
|
||||||
itself accompanies the executable.
|
|
||||||
|
|
||||||
If distribution of executable or object code is made by offering
|
|
||||||
access to copy from a designated place, then offering equivalent
|
|
||||||
access to copy the source code from the same place counts as
|
|
||||||
distribution of the source code, even though third parties are not
|
|
||||||
compelled to copy the source along with the object code.
|
|
||||||
|
|
||||||
4. You may not copy, modify, sublicense, or distribute the Program
|
|
||||||
except as expressly provided under this License. Any attempt
|
|
||||||
otherwise to copy, modify, sublicense or distribute the Program is
|
|
||||||
void, and will automatically terminate your rights under this License.
|
|
||||||
However, parties who have received copies, or rights, from you under
|
|
||||||
this License will not have their licenses terminated so long as such
|
|
||||||
parties remain in full compliance.
|
|
||||||
|
|
||||||
5. You are not required to accept this License, since you have not
|
|
||||||
signed it. However, nothing else grants you permission to modify or
|
|
||||||
distribute the Program or its derivative works. These actions are
|
|
||||||
prohibited by law if you do not accept this License. Therefore, by
|
|
||||||
modifying or distributing the Program (or any work based on the
|
|
||||||
Program), you indicate your acceptance of this License to do so, and
|
|
||||||
all its terms and conditions for copying, distributing or modifying
|
|
||||||
the Program or works based on it.
|
|
||||||
|
|
||||||
6. Each time you redistribute the Program (or any work based on the
|
|
||||||
Program), the recipient automatically receives a license from the
|
|
||||||
original licensor to copy, distribute or modify the Program subject to
|
|
||||||
these terms and conditions. You may not impose any further
|
|
||||||
restrictions on the recipients' exercise of the rights granted herein.
|
|
||||||
You are not responsible for enforcing compliance by third parties to
|
|
||||||
this License.
|
|
||||||
|
|
||||||
7. If, as a consequence of a court judgment or allegation of patent
|
|
||||||
infringement or for any other reason (not limited to patent issues),
|
|
||||||
conditions are imposed on you (whether by court order, agreement or
|
|
||||||
otherwise) that contradict the conditions of this License, they do not
|
|
||||||
excuse you from the conditions of this License. If you cannot
|
|
||||||
distribute so as to satisfy simultaneously your obligations under this
|
|
||||||
License and any other pertinent obligations, then as a consequence you
|
|
||||||
may not distribute the Program at all. For example, if a patent
|
|
||||||
license would not permit royalty-free redistribution of the Program by
|
|
||||||
all those who receive copies directly or indirectly through you, then
|
|
||||||
the only way you could satisfy both it and this License would be to
|
|
||||||
refrain entirely from distribution of the Program.
|
|
||||||
|
|
||||||
If any portion of this section is held invalid or unenforceable under
|
|
||||||
any particular circumstance, the balance of the section is intended to
|
|
||||||
apply and the section as a whole is intended to apply in other
|
|
||||||
circumstances.
|
|
||||||
|
|
||||||
It is not the purpose of this section to induce you to infringe any
|
|
||||||
patents or other property right claims or to contest validity of any
|
|
||||||
such claims; this section has the sole purpose of protecting the
|
|
||||||
integrity of the free software distribution system, which is
|
|
||||||
implemented by public license practices. Many people have made
|
|
||||||
generous contributions to the wide range of software distributed
|
|
||||||
through that system in reliance on consistent application of that
|
|
||||||
system; it is up to the author/donor to decide if he or she is willing
|
|
||||||
to distribute software through any other system and a licensee cannot
|
|
||||||
impose that choice.
|
|
||||||
|
|
||||||
This section is intended to make thoroughly clear what is believed to
|
|
||||||
be a consequence of the rest of this License.
|
|
||||||
|
|
||||||
8. If the distribution and/or use of the Program is restricted in
|
|
||||||
certain countries either by patents or by copyrighted interfaces, the
|
|
||||||
original copyright holder who places the Program under this License
|
|
||||||
may add an explicit geographical distribution limitation excluding
|
|
||||||
those countries, so that distribution is permitted only in or among
|
|
||||||
countries not thus excluded. In such case, this License incorporates
|
|
||||||
the limitation as if written in the body of this License.
|
|
||||||
|
|
||||||
9. The Free Software Foundation may publish revised and/or new versions
|
|
||||||
of the General Public License from time to time. Such new versions will
|
|
||||||
be similar in spirit to the present version, but may differ in detail to
|
|
||||||
address new problems or concerns.
|
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the Program
|
|
||||||
specifies a version number of this License which applies to it and "any
|
|
||||||
later version", you have the option of following the terms and conditions
|
|
||||||
either of that version or of any later version published by the Free
|
|
||||||
Software Foundation. If the Program does not specify a version number of
|
|
||||||
this License, you may choose any version ever published by the Free Software
|
|
||||||
Foundation.
|
|
||||||
|
|
||||||
10. If you wish to incorporate parts of the Program into other free
|
|
||||||
programs whose distribution conditions are different, write to the author
|
|
||||||
to ask for permission. For software which is copyrighted by the Free
|
|
||||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
|
||||||
make exceptions for this. Our decision will be guided by the two goals
|
|
||||||
of preserving the free status of all derivatives of our free software and
|
|
||||||
of promoting the sharing and reuse of software generally.
|
|
||||||
|
|
||||||
NO WARRANTY
|
|
||||||
|
|
||||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
|
||||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
|
||||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
|
||||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
|
||||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
|
||||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
|
||||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
|
||||||
REPAIR OR CORRECTION.
|
|
||||||
|
|
||||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
|
||||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
|
||||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
|
||||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
|
||||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
|
||||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
|
||||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
|
||||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
|
||||||
POSSIBILITY OF SUCH DAMAGES.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
How to Apply These Terms to Your New Programs
|
|
||||||
|
|
||||||
If you develop a new program, and you want it to be of the greatest
|
|
||||||
possible use to the public, the best way to achieve this is to make it
|
|
||||||
free software which everyone can redistribute and change under these terms.
|
|
||||||
|
|
||||||
To do so, attach the following notices to the program. It is safest
|
|
||||||
to attach them to the start of each source file to most effectively
|
|
||||||
convey the exclusion of warranty; and each file should have at least
|
|
||||||
the "copyright" line and a pointer to where the full notice is found.
|
|
||||||
|
|
||||||
<one line to give the program's name and a brief idea of what it does.>
|
|
||||||
Copyright (C) <year> <name of author>
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License along
|
|
||||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
|
||||||
|
|
||||||
If the program is interactive, make it output a short notice like this
|
|
||||||
when it starts in an interactive mode:
|
|
||||||
|
|
||||||
Gnomovision version 69, Copyright (C) year name of author
|
|
||||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
|
||||||
This is free software, and you are welcome to redistribute it
|
|
||||||
under certain conditions; type `show c' for details.
|
|
||||||
|
|
||||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
|
||||||
parts of the General Public License. Of course, the commands you use may
|
|
||||||
be called something other than `show w' and `show c'; they could even be
|
|
||||||
mouse-clicks or menu items--whatever suits your program.
|
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or your
|
|
||||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
|
||||||
necessary. Here is a sample; alter the names:
|
|
||||||
|
|
||||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
|
||||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
|
||||||
|
|
||||||
<signature of Ty Coon>, 1 April 1989
|
|
||||||
Ty Coon, President of Vice
|
|
||||||
|
|
||||||
This General Public License does not permit incorporating your program into
|
|
||||||
proprietary programs. If your program is a subroutine library, you may
|
|
||||||
consider it more useful to permit linking proprietary applications with the
|
|
||||||
library. If this is what you want to do, use the GNU Lesser General
|
|
||||||
Public License instead of this License.
|
|
22
README.md
22
README.md
@ -1,22 +0,0 @@
|
|||||||
# apt-stream
|
|
||||||
|
|
||||||
Create your apt repository with nodejs without having to save files or even take care of storage.
|
|
||||||
|
|
||||||
## Storages
|
|
||||||
|
|
||||||
You can host an apt fast repository with the following storages:
|
|
||||||
|
|
||||||
- Docker and OCI images (find `.deb` files in diff's)
|
|
||||||
- Github Releases and Tree
|
|
||||||
- Google Driver
|
|
||||||
- Oracle Cloud Bucket, another driver soon
|
|
||||||
|
|
||||||
## Setup
|
|
||||||
|
|
||||||
The configuration will be very simple, the first time you run the server or even just run `apt-stream` it will look for the file in the current folder if not the one informed by the cli by the `--config/-c <path>` argument .
|
|
||||||
|
|
||||||
you can also create the file manually after running `apt-stream` it will make a pretty of the settings, and if there is something wrong it will ignore it or it will crash the whole program.
|
|
||||||
|
|
||||||
### For large repository packages
|
|
||||||
|
|
||||||
if you register more than 1500 packages for a single repository, I recommend disabling `gzip` and `xz` to create `Release`, as it is very slow to generate `Packages.gz` and `Packages.xz` files.
|
|
@ -1,39 +0,0 @@
|
|||||||
version: "3.9"
|
|
||||||
name: apt_stream
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
# Config
|
|
||||||
config:
|
|
||||||
|
|
||||||
services:
|
|
||||||
# Mongo server
|
|
||||||
mongo_server:
|
|
||||||
image: mongo
|
|
||||||
container_name: mongo_server_apt_stream
|
|
||||||
restart: always
|
|
||||||
|
|
||||||
# Apt server
|
|
||||||
apt_stream:
|
|
||||||
build: "./"
|
|
||||||
container_name: apt_stream
|
|
||||||
# Restart if the container fails
|
|
||||||
restart: on-failure
|
|
||||||
|
|
||||||
# Wait for mongo server to be ready
|
|
||||||
depends_on:
|
|
||||||
- mongo_server
|
|
||||||
|
|
||||||
# Mount volumes
|
|
||||||
volumes:
|
|
||||||
- config:/data
|
|
||||||
|
|
||||||
# Set extra config to "apt-stream server"
|
|
||||||
command:
|
|
||||||
- "--db"
|
|
||||||
- "mongo_server"
|
|
||||||
- "--port"
|
|
||||||
- "3000"
|
|
||||||
|
|
||||||
# Expose port
|
|
||||||
ports:
|
|
||||||
- "3000:3000/tcp"
|
|
@ -1,5 +0,0 @@
|
|||||||
Package: example
|
|
||||||
Architecture: amd64
|
|
||||||
Version: 1.0.0
|
|
||||||
Maintainer: Matheus S Queiroga
|
|
||||||
Description: Example package
|
|
@ -1,3 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
set -ex
|
|
||||||
echo "Compress works"
|
|
71
package.json
71
package.json
@ -1,70 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "apt-stream",
|
"name": "mono_dpkg",
|
||||||
"version": "2.1.0",
|
"private": true,
|
||||||
"description": "Create repository without save file in disk",
|
"workspaces": [
|
||||||
"private": false,
|
"src/dpkg",
|
||||||
"type": "module",
|
"src/apt"
|
||||||
"license": "GPL-2.0",
|
|
||||||
"author": "Matheus Sampaio Queiroga <srherobrine20@gmail.com>",
|
|
||||||
"homepage": "https://github.com/Sirherobrine23/apt-stream#readme",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git+https://github.com/Sirherobrine23/apt-stream.git"
|
|
||||||
},
|
|
||||||
"keywords": [
|
|
||||||
"apt",
|
|
||||||
"pack",
|
|
||||||
"upload",
|
|
||||||
"cloud",
|
|
||||||
"stream",
|
|
||||||
"server",
|
|
||||||
"debian",
|
|
||||||
"ubuntu",
|
|
||||||
"cli",
|
|
||||||
"interactive"
|
|
||||||
],
|
],
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/Sirherobrine23/apt-stream/issues",
|
|
||||||
"email": "srherobrine20+apt-stream@gmail.com"
|
|
||||||
},
|
|
||||||
"sponsor": {
|
|
||||||
"url": "https://github.com/sponsors/Sirherobrine23"
|
|
||||||
},
|
|
||||||
"publishConfig": {
|
|
||||||
"access": "public"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=16.0.0"
|
|
||||||
},
|
|
||||||
"bin": {
|
|
||||||
"apt-stream": "./src/index.js"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"prepack": "tsc --build --clean && tsc --build",
|
|
||||||
"postpack": "tsc --build --clean"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/express": "^4.17.17",
|
"@types/node": "^20.10.0",
|
||||||
"@types/inquirer": "^9.0.3",
|
|
||||||
"@types/node": "^20.3.2",
|
|
||||||
"@types/yargs": "^17.0.24",
|
|
||||||
"ts-node": "^10.9.1",
|
"ts-node": "^10.9.1",
|
||||||
"typescript": "^5.1.6"
|
"typescript": "^5.3.2"
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@sirherobrine23/cloud": "^3.6.12",
|
|
||||||
"@sirherobrine23/decompress": "^3.6.12",
|
|
||||||
"@sirherobrine23/docker-registry": "^3.6.12",
|
|
||||||
"@sirherobrine23/dpkg": "^3.6.12",
|
|
||||||
"@sirherobrine23/extends": "^3.6.12",
|
|
||||||
"@sirherobrine23/http": "^3.6.12",
|
|
||||||
"express": "^4.18.2",
|
|
||||||
"express-rate-limit": "^6.7.0",
|
|
||||||
"inquirer": "^9.2.7",
|
|
||||||
"inquirer-file-tree-selection-prompt": "^2.0.5",
|
|
||||||
"mongodb": "^5.6.0",
|
|
||||||
"openpgp": "^5.9.0",
|
|
||||||
"yaml": "^2.3.1",
|
|
||||||
"yargs": "^17.7.2"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
11
railway.json
11
railway.json
@ -1,11 +0,0 @@
|
|||||||
{
|
|
||||||
"$schema": "https://railway.app/railway.schema.json",
|
|
||||||
"build": {
|
|
||||||
"builder": "DOCKERFILE",
|
|
||||||
"dockerfilePath": "Dockerfile"
|
|
||||||
},
|
|
||||||
"deploy": {
|
|
||||||
"startCommand": "bash -c \"apt-stream server -c env:config -z -t 0 --port ${PORT} --db ${MONGO_URL}\"",
|
|
||||||
"restartPolicyType": "ALWAYS"
|
|
||||||
}
|
|
||||||
}
|
|
22
src/apt/README.md
Normal file
22
src/apt/README.md
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
# apt-stream
|
||||||
|
|
||||||
|
Create your apt repository with nodejs without having to save files or even take care of storage.
|
||||||
|
|
||||||
|
## Storages
|
||||||
|
|
||||||
|
You can host an apt fast repository with the following storages:
|
||||||
|
|
||||||
|
- Docker and OCI images (find `.deb` files in diff's)
|
||||||
|
- Github Releases and Tree
|
||||||
|
- Google Driver
|
||||||
|
- Oracle Cloud Bucket, another driver soon
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
The configuration will be very simple, the first time you run the server or even just run `apt-stream` it will look for the file in the current folder if not the one informed by the cli by the `--config/-c <path>` argument .
|
||||||
|
|
||||||
|
you can also create the file manually after running `apt-stream` it will make a pretty of the settings, and if there is something wrong it will ignore it or it will crash the whole program.
|
||||||
|
|
||||||
|
### For large repository packages
|
||||||
|
|
||||||
|
if you register more than 1500 packages for a single repository, I recommend disabling `gzip` and `xz` to create `Release`, as it is very slow to generate `Packages.gz` and `Packages.xz` files.
|
46
src/apt/package.json
Normal file
46
src/apt/package.json
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
{
|
||||||
|
"name": "apt-stream",
|
||||||
|
"version": "2.1.0",
|
||||||
|
"description": "Create repository without save file in disk",
|
||||||
|
"private": false,
|
||||||
|
"type": "module",
|
||||||
|
"license": "GPL-2.0",
|
||||||
|
"author": "Matheus Sampaio Queiroga <srherobrine20@gmail.com>",
|
||||||
|
"homepage": "https://git.sirherobrine23.org/Sirherobrine23/node-apt#readme",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://git.sirherobrine23.org/Sirherobrine23/node-apt.git",
|
||||||
|
"directory": "src/apt"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"apt",
|
||||||
|
"pack",
|
||||||
|
"upload",
|
||||||
|
"cloud",
|
||||||
|
"stream",
|
||||||
|
"server",
|
||||||
|
"debian",
|
||||||
|
"ubuntu",
|
||||||
|
"cli",
|
||||||
|
"interactive"
|
||||||
|
],
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://git.sirherobrine23.org/Sirherobrine23/node-apt/issues"
|
||||||
|
},
|
||||||
|
"sponsor": {
|
||||||
|
"url": "https://github.com/sponsors/Sirherobrine23"
|
||||||
|
},
|
||||||
|
"publishConfig": {
|
||||||
|
"access": "public"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=16.0.0"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"apt-stream": "./src/index.js"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"prepack": "tsc --build --clean && tsc --build",
|
||||||
|
"postpack": "tsc --build --clean"
|
||||||
|
}
|
||||||
|
}
|
0
src/apt/src/index.ts
Normal file
0
src/apt/src/index.ts
Normal file
3
src/apt/tsconfig.json
Normal file
3
src/apt/tsconfig.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"extends": "../../tsconfig.json"
|
||||||
|
}
|
398
src/config.ts
398
src/config.ts
@ -1,398 +0,0 @@
|
|||||||
import { googleDriver, oracleBucket } from "@sirherobrine23/cloud";
|
|
||||||
import dockerRegistry from "@sirherobrine23/docker-registry";
|
|
||||||
import { apt, dpkg } from "@sirherobrine23/dpkg";
|
|
||||||
import { extendsCrypto } from "@sirherobrine23/extends";
|
|
||||||
import { Github } from "@sirherobrine23/http";
|
|
||||||
import { Collection, Db, MongoClient } from "mongodb";
|
|
||||||
import crypto from "node:crypto";
|
|
||||||
import oldFs, { createReadStream } from "node:fs";
|
|
||||||
import { tmpdir } from "node:os";
|
|
||||||
import path from "node:path";
|
|
||||||
import { finished } from "node:stream/promises";
|
|
||||||
import openpgp from "openpgp";
|
|
||||||
import yaml from "yaml";
|
|
||||||
|
|
||||||
export type repositorySouce = {
|
|
||||||
/**
|
|
||||||
* Dist component
|
|
||||||
* @default main
|
|
||||||
*/
|
|
||||||
componentName?: string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The source is available for file upload.
|
|
||||||
*/
|
|
||||||
enableUpload?: boolean;
|
|
||||||
} & ({
|
|
||||||
type: "http",
|
|
||||||
url: string | URL,
|
|
||||||
enableUpload?: false;
|
|
||||||
header?: { [key: string]: string },
|
|
||||||
query?: { [key: string]: string }
|
|
||||||
} | {
|
|
||||||
type: "mirror",
|
|
||||||
enableUpload?: false;
|
|
||||||
config: apt.sourceList;
|
|
||||||
} | {
|
|
||||||
type: "github",
|
|
||||||
/**
|
|
||||||
* Repository owner
|
|
||||||
* @example `Sirherobrine23`
|
|
||||||
*/
|
|
||||||
owner: string,
|
|
||||||
/**
|
|
||||||
* Repository name
|
|
||||||
* @example `apt-stream`
|
|
||||||
*/
|
|
||||||
repository: string,
|
|
||||||
/**
|
|
||||||
* Auth token, not required if public repository
|
|
||||||
*/
|
|
||||||
token?: string,
|
|
||||||
} & ({
|
|
||||||
subType: "release",
|
|
||||||
tag?: string[],
|
|
||||||
} | {
|
|
||||||
subType: "branch",
|
|
||||||
enableUpload?: false;
|
|
||||||
branch: string[],
|
|
||||||
}) | {
|
|
||||||
type: "googleDriver",
|
|
||||||
|
|
||||||
/**
|
|
||||||
* oAuth Client Secret
|
|
||||||
*/
|
|
||||||
clientSecret: string,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* oAuth Client ID
|
|
||||||
*/
|
|
||||||
clientId: string,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Client oAuth
|
|
||||||
*/
|
|
||||||
clientToken: googleDriver.googleCredential,
|
|
||||||
|
|
||||||
/** Folder id to add files upload */
|
|
||||||
uploadFolderID?: string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Files or Folders ID's
|
|
||||||
*/
|
|
||||||
gIDs?: string[],
|
|
||||||
} | {
|
|
||||||
type: "oracleBucket",
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Oracle bucket authentication
|
|
||||||
*/
|
|
||||||
authConfig: oracleBucket.oracleOptions,
|
|
||||||
|
|
||||||
/** Folder to upload files if enabled */
|
|
||||||
uploadFolderPath?: string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Files or Folders path
|
|
||||||
*/
|
|
||||||
path?: string[],
|
|
||||||
} | {
|
|
||||||
type: "docker",
|
|
||||||
auth?: dockerRegistry.userAuth,
|
|
||||||
image: string,
|
|
||||||
tags?: string[]
|
|
||||||
});
|
|
||||||
|
|
||||||
export type SourceJson = {
|
|
||||||
Description?: string;
|
|
||||||
Codename?: string;
|
|
||||||
Suite?: string;
|
|
||||||
Origin?: string;
|
|
||||||
Label?: string;
|
|
||||||
repositorys?: {
|
|
||||||
[src: string]: repositorySouce
|
|
||||||
}
|
|
||||||
};
|
|
||||||
export class Source extends Map<string, repositorySouce> {
|
|
||||||
constructor(src: SourceJson = {}) {
|
|
||||||
super();
|
|
||||||
if (!src) return;
|
|
||||||
const {
|
|
||||||
Codename,
|
|
||||||
Description,
|
|
||||||
Label,
|
|
||||||
Origin,
|
|
||||||
Suite,
|
|
||||||
repositorys = {}
|
|
||||||
} = src;
|
|
||||||
|
|
||||||
this.Description = Description;
|
|
||||||
this.Codename = Codename;
|
|
||||||
this.Suite = Suite;
|
|
||||||
this.Origin = Origin;
|
|
||||||
this.Label = Label;
|
|
||||||
Object.keys(repositorys).forEach(key => this.set(key, repositorys[key]));
|
|
||||||
}
|
|
||||||
|
|
||||||
Description?: string;
|
|
||||||
Codename?: string;
|
|
||||||
Suite?: string;
|
|
||||||
Origin?: string;
|
|
||||||
Label?: string;
|
|
||||||
|
|
||||||
toJSON() {
|
|
||||||
return Array.from(this.keys()).reduce<SourceJson>((acc, key) => {
|
|
||||||
acc.repositorys[key] = this.get(key);
|
|
||||||
return acc;
|
|
||||||
}, {
|
|
||||||
Description: this.Description,
|
|
||||||
Codename: this.Codename,
|
|
||||||
Suite: this.Suite,
|
|
||||||
Label: this.Label,
|
|
||||||
Origin: this.Origin,
|
|
||||||
repositorys: {}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
toArray(): (repositorySouce & { id: string })[] {
|
|
||||||
return Array.from(this.keys()).map(id => ({ id, ...(this.get(id)) }));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add new source origin to Repository and check if valid config, else throw Error.
|
|
||||||
*
|
|
||||||
* @param srcID - optional ID to source
|
|
||||||
* @param value - Repository source to Repository
|
|
||||||
*/
|
|
||||||
set(srcID: string | undefined, value: repositorySouce) {
|
|
||||||
if (!value) throw new Error("Require value");
|
|
||||||
else if (!(typeof value === "object" && !Array.isArray(value))) throw new Error("Require Object");
|
|
||||||
else if (typeof value === "string" && this.has(srcID)) throw new Error("Source ID are add");
|
|
||||||
value.componentName ||= "main";
|
|
||||||
value.enableUpload ??= false;
|
|
||||||
srcID ||= value.type + "_" + ([crypto.randomBytes(6).toString("hex"), crypto.randomBytes(crypto.randomInt(4, 16)).toString("hex"), crypto.randomUUID()]).join("-");
|
|
||||||
|
|
||||||
if (value.type === "http") {
|
|
||||||
if (!value.url) throw new Error("Require debian package file");
|
|
||||||
else if (!(value.url instanceof URL || typeof value.url === "string" && value.url.startsWith("http"))) throw new Error("Invalid URL");
|
|
||||||
value.enableUpload = false;
|
|
||||||
|
|
||||||
// Test string to is valid URL
|
|
||||||
let protocol: string;
|
|
||||||
if (typeof value.url === "string") protocol = (new URL(value.url)).protocol;
|
|
||||||
else protocol = value.url.protocol;
|
|
||||||
if (!(protocol === "http:" || protocol === "https:")) throw new Error("Invalid URL, require HTTP protocol");
|
|
||||||
|
|
||||||
value.header ||= {};
|
|
||||||
value.query ||= {};
|
|
||||||
} else if (value.type === "github") {
|
|
||||||
if (!(value.owner && value.repository)) throw new Error("Require valid repository and owner");
|
|
||||||
else if (!(typeof value.owner === "string" && value.owner.length > 1)) throw new Error("Require valid owner username");
|
|
||||||
else if (!(typeof value.repository === "string" && value.repository.length > 1)) throw new Error("Require valid repository name");
|
|
||||||
value.token ||= Github.githubToken;
|
|
||||||
|
|
||||||
if (value.subType === "release") {
|
|
||||||
value.tag ||= [];
|
|
||||||
} else if (value.subType === "branch") {
|
|
||||||
value.enableUpload = false;
|
|
||||||
value.branch ||= [];
|
|
||||||
if (!value.branch.length) throw new Error("Require at one Branch");
|
|
||||||
} else throw new Error("Invalid Github subtype");
|
|
||||||
} else if (value.type === "googleDriver") {
|
|
||||||
if (!(value.clientId && value.clientSecret && value.clientToken)) throw new Error("Require Client ID, Secret and Token auth");
|
|
||||||
else if (!(typeof value.clientId === "string" && value.clientId.length > 5)) throw new Error("Require valid clientID");
|
|
||||||
else if (!(typeof value.clientSecret === "string" && value.clientSecret.length > 5)) throw new Error("Require valid clientSecret");
|
|
||||||
else if (!(typeof value.clientToken === "object" && typeof value.clientToken.access_token === "string")) throw new Error("Require valid token");
|
|
||||||
value.gIDs ||= [];
|
|
||||||
} else if (value.type === "oracleBucket") {
|
|
||||||
if (!value.authConfig.region) throw new Error("Require Bucket region");
|
|
||||||
if (value.authConfig.auth) {
|
|
||||||
if (Array.isArray(value.authConfig.auth)) {
|
|
||||||
if (!(value.authConfig.auth.length)) throw new Error("Require auth to Oracle Cloud");
|
|
||||||
const backup = value.authConfig.auth.slice(0, 2);
|
|
||||||
if (!(oldFs.existsSync(path.resolve(process.cwd(), backup.at(0))))) throw new Error("Invalid Oracle auth path, Path not exists");
|
|
||||||
backup[0] = path.resolve(process.cwd(), backup.at(0));
|
|
||||||
if (typeof backup.at(1) === "string") {
|
|
||||||
if (!(backup[1] = backup[1].trim())) delete backup[1];
|
|
||||||
} else delete backup[1];
|
|
||||||
value.authConfig.auth = backup.filter(Boolean);
|
|
||||||
} else {
|
|
||||||
const { tenancy, user, fingerprint, privateKey, passphase } = value.authConfig.auth;
|
|
||||||
if (!(tenancy && user && fingerprint && privateKey)) throw new Error("Invalid auth to Oracle Cloud");
|
|
||||||
if (!passphase) delete value.authConfig.auth.passphase;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
value.path ||= [];
|
|
||||||
} else if (value.type === "mirror") {
|
|
||||||
value.enableUpload = false;
|
|
||||||
if (!value.config) throw new Error("Require Mirror sources");
|
|
||||||
else if (!((value.config = value.config.filter(at => at.type === "packages" && at.distname?.trim?.() && at.src?.trim?.())).length)) throw new Error("To mirror the repository you only need a source");
|
|
||||||
} else if (value.type === "docker") {
|
|
||||||
if (!value.image) throw new Error("Require docker image");
|
|
||||||
if (value.auth) if (!(value.auth.username && value.auth.password)) throw new Error("Required valid auth to Docker image");
|
|
||||||
value.tags ||= [];
|
|
||||||
} else throw new Error("Invalid source type");
|
|
||||||
super.set(srcID, value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
async uploadFile(srcID: string, filePath: string) {
|
|
||||||
if (!(this.has(srcID))) throw new Error("ID not exists");
|
|
||||||
const info = this.get(srcID);
|
|
||||||
if (!(info.enableUpload)) throw new Error("Cannot upload package");
|
|
||||||
const { controlFile } = await dpkg.parsePackage(createReadStream(filePath));
|
|
||||||
const debInfo = await extendsCrypto.createHashAsync(createReadStream(filePath)), fileName = `${controlFile.Package}_${controlFile.Architecture}_${controlFile.Version}.deb`;
|
|
||||||
|
|
||||||
if (info.type === "github") await finished(createReadStream(filePath).pipe((await (await Github.repositoryManeger(info.owner, info.repository, { token: info.token })).release.manegerRelease(controlFile.Version)).uploadAsset(fileName, debInfo.byteLength)), { error: true });
|
|
||||||
else if (info.type === "oracleBucket") await finished(createReadStream(filePath).pipe((await oracleBucket.oracleBucket(info.authConfig)).uploadFile(path.posix.join(info.uploadFolderPath || "/", fileName))));
|
|
||||||
else if (info.type === "googleDriver") {
|
|
||||||
const gdrive = await googleDriver.GoogleDriver({oauth: await googleDriver.createAuth({ clientID: info.clientId, clientSecret: info.clientSecret, token: info.clientToken, authUrlCallback: () => { throw new Error("Auth disabled"); }, tokenCallback: () => { }, redirectURL: null })});
|
|
||||||
await finished(gdrive.uploadFile(fileName, info.uploadFolderID));
|
|
||||||
} else if (info.type === "docker") {
|
|
||||||
const oci = new dockerRegistry.v2(info.image, info.auth);
|
|
||||||
const img = await oci.createImage(dockerRegistry.debianArchToDockerPlatform(controlFile.Architecture));
|
|
||||||
await finished(createReadStream(filePath).pipe(img.createBlob("gzip").addEntry({ name: fileName, size: debInfo.byteLength })));
|
|
||||||
info.tags.push((await img.finalize()).digest);
|
|
||||||
super.set(srcID, info);
|
|
||||||
} else throw new Error("Not implemented upload");
|
|
||||||
|
|
||||||
return { controlFile, debInfo };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export type ConfigJSON = {
|
|
||||||
mongoURL?: string;
|
|
||||||
gpg?: {
|
|
||||||
gpgPassphrase?: string;
|
|
||||||
privateKey: string;
|
|
||||||
publicKey: string;
|
|
||||||
};
|
|
||||||
repositorys: { [repoName: string]: SourceJson };
|
|
||||||
};
|
|
||||||
|
|
||||||
export async function generateGPG({ passphrase, email, name }: { passphrase?: string, email?: string, name?: string } = {}) {
|
|
||||||
const { privateKey, publicKey } = await openpgp.generateKey({
|
|
||||||
rsaBits: 4094,
|
|
||||||
type: "rsa",
|
|
||||||
format: "armored",
|
|
||||||
passphrase,
|
|
||||||
userIDs: [
|
|
||||||
{
|
|
||||||
comment: "Generated in Apt-Stream",
|
|
||||||
email, name
|
|
||||||
}
|
|
||||||
]
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
privateKey,
|
|
||||||
publicKey,
|
|
||||||
passphrase
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export class Config extends Map<string, Source> {
|
|
||||||
/** Mongo Server URL to connect */
|
|
||||||
public mongoConnection: URL = new URL("mongodb://127.0.0.1/aptStream");
|
|
||||||
public tmpFolder = tmpdir();
|
|
||||||
|
|
||||||
public gpgPassphrase?: string;
|
|
||||||
public privateGPG?: string;
|
|
||||||
public publicGPG?: string;
|
|
||||||
|
|
||||||
constructor(src?: ConfigJSON | string) {
|
|
||||||
super();
|
|
||||||
if (!src) return;
|
|
||||||
|
|
||||||
if (typeof src === "string") {
|
|
||||||
const srcc: string = src;
|
|
||||||
try {
|
|
||||||
src = yaml.parse(srcc);
|
|
||||||
} catch {
|
|
||||||
src = JSON.parse(srcc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const {
|
|
||||||
mongoURL,
|
|
||||||
gpg,
|
|
||||||
repositorys = {},
|
|
||||||
} = src as ConfigJSON;
|
|
||||||
if (mongoURL) this.mongoConnection = new URL(mongoURL);
|
|
||||||
if (gpg) {
|
|
||||||
this.gpgPassphrase = gpg.gpgPassphrase;
|
|
||||||
this.privateGPG = gpg.privateKey;
|
|
||||||
this.publicGPG = gpg.publicKey;
|
|
||||||
}
|
|
||||||
Object.keys(repositorys).forEach(key => this.set(key, new Source(repositorys[key])));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get YAML config to easy edit
|
|
||||||
* @returns - yaml Config
|
|
||||||
*/
|
|
||||||
toString() { return yaml.stringify(this.toJSON()); }
|
|
||||||
|
|
||||||
toJSON() {
|
|
||||||
return Object.keys(this.keys()).reduce<ConfigJSON>((acc, key) => {
|
|
||||||
acc.repositorys[key] = this.get(key).toJSON();
|
|
||||||
return acc;
|
|
||||||
}, {
|
|
||||||
mongoURL: this.mongoConnection.toString(),
|
|
||||||
...(!(this.privateGPG && this.publicGPG) ? {} : {
|
|
||||||
gpg: {
|
|
||||||
gpgPassphrase: this.gpgPassphrase,
|
|
||||||
privateKey: this.privateGPG,
|
|
||||||
publicKey: this.publicGPG,
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
repositorys: {},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async getPulicKey(fileType: "dearmor" | "armor" = "armor") {
|
|
||||||
// same to gpg --dearmor
|
|
||||||
if (fileType === "dearmor") return Buffer.from((await openpgp.unarmor(this.publicGPG)).data as any);
|
|
||||||
return (await openpgp.readKey({ armoredKey: this.publicGPG })).armor();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type packageCollection = {
|
|
||||||
repositorys: {repository: string, origim: string}[];
|
|
||||||
restoreFile: any;
|
|
||||||
control: dpkg.debianControl;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type uploadInfo = {
|
|
||||||
ID: string;
|
|
||||||
token: string;
|
|
||||||
validAt: number;
|
|
||||||
filePath: string;
|
|
||||||
repository: string;
|
|
||||||
destID: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export class Connection {
|
|
||||||
constructor(public repoConfig: Config, public client: MongoClient) {
|
|
||||||
this.database = client.db(repoConfig.mongoConnection.pathname.slice(1) || "aptStream");
|
|
||||||
this.packageCollection = this.database.collection<packageCollection>("packages");
|
|
||||||
this.uploadCollection = this.database.collection<uploadInfo>("uploads");
|
|
||||||
}
|
|
||||||
|
|
||||||
public database: Db;
|
|
||||||
public packageCollection: Collection<packageCollection>;
|
|
||||||
public uploadCollection: Collection<uploadInfo>;
|
|
||||||
|
|
||||||
public getConnections() {
|
|
||||||
const connection = this.client["topology"];
|
|
||||||
return {
|
|
||||||
current: Number(connection.client.s.activeSessions?.size),
|
|
||||||
max: Number(connection.s.options.maxConnecting),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function Connect(repoConfig: Config) {
|
|
||||||
const client = await (new MongoClient(repoConfig.mongoConnection.toString())).connect();
|
|
||||||
return new Connection(repoConfig, client);
|
|
||||||
}
|
|
52
src/dpkg/README.md
Normal file
52
src/dpkg/README.md
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
# Nodejs Debian maneger
|
||||||
|
|
||||||
|
this package supports some features that can be useful like extracting the Package files or even creating a Nodejs direct
|
||||||
|
|
||||||
|
## Supported features
|
||||||
|
|
||||||
|
### Dpkg
|
||||||
|
|
||||||
|
- Create package.
|
||||||
|
- Extract package file (`ar` file).
|
||||||
|
- Extract and descompress `data.tar`.
|
||||||
|
|
||||||
|
### Apt
|
||||||
|
|
||||||
|
- Get packages from repository `Packages` file.
|
||||||
|
- Parse repository `source.list`.
|
||||||
|
- Parse `Release` and `InRelease` file.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
É possivel criar pacotes direto de pacote:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { createWriteStream } from "node:fs";
|
||||||
|
import { fileURLToPath } from "node:url";
|
||||||
|
import { finished } from "node:stream/promises";
|
||||||
|
import path from "node:path";
|
||||||
|
import dpkg from "@sirherobrine23/debian";
|
||||||
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
|
const deb = dpkg.createPackage({
|
||||||
|
dataFolder: path.join(__dirname, "debian_pack"),
|
||||||
|
control: {
|
||||||
|
Package: "test",
|
||||||
|
Architecture: "all",
|
||||||
|
Version: "1.1.1",
|
||||||
|
Description: `Example to create fist line\n\nand Second`,
|
||||||
|
Maintainer: {
|
||||||
|
Name: "Matheus Sampaio Queiroga",
|
||||||
|
Email: "srherobrine20@gmail.com"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
compress: {
|
||||||
|
data: "gzip",
|
||||||
|
control: "gzip",
|
||||||
|
},
|
||||||
|
scripts: {
|
||||||
|
preinst: "#!/bin/bash\nset -ex\necho OK"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
await finished(deb.pipe(createWriteStream(path.join(__dirname, "example.deb"))));
|
||||||
|
```
|
49
src/dpkg/package.json
Normal file
49
src/dpkg/package.json
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
{
|
||||||
|
"name": "@sirherobrine23/dpkg",
|
||||||
|
"version": "3.7.0",
|
||||||
|
"description": "Create and Parse debian packages files directly from Nodejs",
|
||||||
|
"type": "module",
|
||||||
|
"main": "src/index.js",
|
||||||
|
"types": "src/index.d.ts",
|
||||||
|
"author": "Matheus Sampaio Queiroga <srherobrine20@gmail.com>",
|
||||||
|
"license": "GPL-2.0",
|
||||||
|
"homepage": "https://git.sirherobrine23.org/Sirherobrine23/node-apt",
|
||||||
|
"keywords": [
|
||||||
|
"apt",
|
||||||
|
"dpkg",
|
||||||
|
"debian",
|
||||||
|
"multi-platform",
|
||||||
|
"windows",
|
||||||
|
"linux",
|
||||||
|
"macOS"
|
||||||
|
],
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://git.sirherobrine23.org/Sirherobrine23/node-apt.git",
|
||||||
|
"directory": "src/dpkg"
|
||||||
|
},
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://git.sirherobrine23.org/Sirherobrine23/node-apt/issues"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"prepack": "tsc --build --clean && tsc --build",
|
||||||
|
"postpack": "tsc --build --clean"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@sirherobrine23/ar": "3.7.0",
|
||||||
|
"@sirherobrine23/decompress": "3.7.0",
|
||||||
|
"@sirherobrine23/extends": "3.7.0",
|
||||||
|
"@sirherobrine23/http": "3.7.0",
|
||||||
|
"openpgp": "^5.11.0",
|
||||||
|
"tar-stream": "^3.1.6"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/tar-stream": "^3.1.3"
|
||||||
|
},
|
||||||
|
"workspaces": [
|
||||||
|
"../ar",
|
||||||
|
"../decompress",
|
||||||
|
"../extends",
|
||||||
|
"../http"
|
||||||
|
]
|
||||||
|
}
|
0
src/dpkg/src/apt.ts
Normal file
0
src/dpkg/src/apt.ts
Normal file
299
src/dpkg/src/dpkg.ts
Normal file
299
src/dpkg/src/dpkg.ts
Normal file
@ -0,0 +1,299 @@
|
|||||||
|
import path from "node:path";
|
||||||
|
import fs from "node:fs";
|
||||||
|
import stream from "node:stream";
|
||||||
|
import stream_promise from "node:stream/promises";
|
||||||
|
import * as nodeAr from "@sirherobrine23/ar";
|
||||||
|
import { Compressors } from "@sirherobrine23/decompress";
|
||||||
|
|
||||||
|
/** Debian packages, get from `dpkg-architecture --list -L | grep 'musl-linux-' | sed 's|musl-linux-||g' | xargs`, version 1.21.1, Ubuntu */
|
||||||
|
export type debianArch = "all"|"armhf"|"armel"|"mipsn32"|"mipsn32el"|"mipsn32r6"|"mipsn32r6el"|"mips64"|"mips64el"|"mips64r6"|"mips64r6el"|"powerpcspe"|"x32"|"arm64ilp32"|"i386"|"ia64"|"alpha"|"amd64"|"arc"|"armeb"|"arm"|"arm64"|"avr32"|"hppa"|"m32r"|"m68k"|"mips"|"mipsel"|"mipsr6"|"mipsr6el"|"nios2"|"or1k"|"powerpc"|"powerpcel"|"ppc64"|"ppc64el"|"riscv64"|"s390"|"s390x"|"sh3"|"sh3eb"|"sh4"|"sh4eb"|"sparc"|"sparc64"|"tilegx";
|
||||||
|
export const archs: Readonly<debianArch[]> = Object.freeze(["all", "armhf", "armel", "mipsn32", "mipsn32el", "mipsn32r6", "mipsn32r6el", "mips64", "mips64el", "mips64r6", "mips64r6el", "powerpcspe", "x32", "arm64ilp32", "i386", "ia64", "alpha", "amd64", "arc", "armeb", "arm", "arm64", "avr32", "hppa", "m32r", "m68k", "mips", "mipsel", "mipsr6", "mipsr6el", "nios2", "or1k", "powerpc", "powerpcel", "ppc64", "ppc64el", "riscv64", "s390", "s390x", "sh3", "sh3eb", "sh4", "sh4eb", "sparc", "sparc64", "tilegx"]);
|
||||||
|
|
||||||
|
function keys<T>(arg0: T): (keyof T)[] { return Object.keys(arg0) as any[]; }
|
||||||
|
|
||||||
|
type Dependencie = [string]|
|
||||||
|
[string, string]|
|
||||||
|
[string, "|"|"<<"|"<="|"="|">="|">>", string];
|
||||||
|
|
||||||
|
/** Debian binary control */
|
||||||
|
export interface DebianControl {
|
||||||
|
/** Package name */
|
||||||
|
Package: string;
|
||||||
|
/**
|
||||||
|
* The version number of a package. The format is: `[epoch:]upstream_version[-debian_revision]`.
|
||||||
|
*
|
||||||
|
* The three components here are:
|
||||||
|
*
|
||||||
|
* - **epoch**
|
||||||
|
*
|
||||||
|
* This is a single (generally small) unsigned integer. It may be omitted, in which case zero is assumed.
|
||||||
|
*
|
||||||
|
* Epochs can help when the upstream version numbering scheme changes, but they must be used with care. You should not change the epoch, even in experimental, without getting consensus on debian-devel first.
|
||||||
|
*
|
||||||
|
* - **upstream_version**
|
||||||
|
*
|
||||||
|
* This is the main part of the version number. It is usually the version number of the original (“upstream”) package from which the .deb file has been made, if this is applicable. Usually this will be in the same format as that specified by the upstream author(s); however, it may need to be reformatted to fit into the package management system’s format and comparison scheme.
|
||||||
|
*
|
||||||
|
* The comparison behavior of the package management system with respect to the upstream_version is described below. The upstream_version portion of the version number is mandatory.
|
||||||
|
*
|
||||||
|
* The upstream_version must contain only alphanumerics 6 and the characters . + - ~ (full stop, plus, hyphen, tilde) and should start with a digit. If there is no debian_revision then hyphens are not allowed.
|
||||||
|
*
|
||||||
|
* - **debian_revision**
|
||||||
|
*
|
||||||
|
* This part of the version number specifies the version of the Debian package based on the upstream version. It must contain only alphanumerics and the characters + . ~ (plus, full stop, tilde) and is compared in the same way as the upstream_version is.
|
||||||
|
*
|
||||||
|
* It is conventional to restart the debian_revision at 1 each time the upstream_version is increased.
|
||||||
|
*
|
||||||
|
* The package management system will break the version number apart at the last hyphen in the string (if there is one) to determine the upstream_version and debian_revision. The absence of a debian_revision is equivalent to a debian_revision of 0.
|
||||||
|
*
|
||||||
|
* Presence of the debian_revision part indicates this package is a non-native package (see Source packages). Absence indicates the package is a native package.
|
||||||
|
*
|
||||||
|
* When comparing two version numbers, first the epoch of each are compared, then the upstream_version if epoch is equal, and then debian_revision if upstream_version is also equal. epoch is compared numerically. The upstream_version and debian_revision parts are compared by the package management system using the following algorithm:
|
||||||
|
*
|
||||||
|
* The strings are compared from left to right.
|
||||||
|
*
|
||||||
|
* First the initial part of each string consisting entirely of non-digit characters is determined. These two parts (one of which may be empty) are compared lexically. If a difference is found it is returned. The lexical comparison is a comparison of ASCII values modified so that all the letters sort earlier than all the non-letters and so that a tilde sorts before anything, even the end of a part. For example, the following parts are in sorted order from earliest to latest: ~~, ~~a, ~, the empty part, a. 7
|
||||||
|
*
|
||||||
|
* Then the initial part of the remainder of each string which consists entirely of digit characters is determined. The numerical values of these two parts are compared, and any difference found is returned as the result of the comparison. For these purposes an empty string (which can only occur at the end of one or both version strings being compared) counts as zero.
|
||||||
|
*
|
||||||
|
* These two steps (comparing and removing initial non-digit strings and initial digit strings) are repeated until a difference is found or both strings are exhausted.
|
||||||
|
*/
|
||||||
|
Version: string;
|
||||||
|
/**
|
||||||
|
* The package maintainer’s name and email address. The name must come first, then the email address inside angle brackets `<>` (in RFC822 format).
|
||||||
|
*
|
||||||
|
* If the maintainer’s name contains a full stop then the whole field will not work directly as an email address due to a misfeature in the syntax specified in RFC822; a program using this field as an address must check for this and correct the problem if necessary (for example by putting the name in round brackets and moving it to the end, and bringing the email address forward).
|
||||||
|
*/
|
||||||
|
Maintainer: string;
|
||||||
|
/**
|
||||||
|
* A description of the binary package, consisting of two parts, the synopsis or the short description, and the long description. It is a multiline field with the following format:
|
||||||
|
*
|
||||||
|
* ```txt
|
||||||
|
* single line synopsis
|
||||||
|
* extended description over several lines
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
Description: string;
|
||||||
|
/** This field identifies the source package name. */
|
||||||
|
Source?: string;
|
||||||
|
Section?: string;
|
||||||
|
Priority?: string;
|
||||||
|
Architecture: debianArch;
|
||||||
|
Essential?: boolean;
|
||||||
|
"Installed-Size"?: number|bigint;
|
||||||
|
Homepage?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Some binary packages incorporate parts of other packages when built but do not have to depend on those packages. Examples include linking with static libraries or incorporating source code from another package during the build. In this case, the source packages of those other packages are part of the complete source (the binary package is not reproducible without them).
|
||||||
|
*
|
||||||
|
* When the license of either the incorporated parts or the incorporating binary package requires that the full source code of the incorporating binary package be made available, the Built-Using field must list the corresponding source package for any affected binary package incorporated during the build, 6 including an “exactly equal” (“=”) version relation on the version that was used to build that version of the incorporating binary package. 7
|
||||||
|
*
|
||||||
|
* This causes the Debian archive to retain the versions of the source packages that were actually incorporated. In particular, if the versions of the incorporated parts are updated but the incorporating binary package is not rebuilt, the older versions of the incorporated parts will remain in the archive in order to satisfy the license.
|
||||||
|
*/
|
||||||
|
"Built-Using"?: string[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This declares an absolute dependency. A package will not be configured unless all of the packages listed in its Depends field have been correctly configured (unless there is a circular dependency as described above).
|
||||||
|
*
|
||||||
|
* The Depends field should be used if the depended-on package is required for the depending package to provide a significant amount of functionality.
|
||||||
|
*
|
||||||
|
* The Depends field should also be used if the postinst or prerm scripts require the depended-on package to be unpacked or configured in order to run. In the case of postinst configure, the depended-on packages will be unpacked and configured first. (If both packages are involved in a dependency loop, this might not work as expected; see the explanation a few paragraphs back.) In the case of prerm or other postinst actions, the package dependencies will normally be at least unpacked, but they may be only “Half-Installed” if a previous upgrade of the dependency failed.
|
||||||
|
*
|
||||||
|
* Finally, the Depends field should be used if the depended-on package is needed by the postrm script to fully clean up after the package removal. There is no guarantee that package dependencies will be available when postrm is run, but the depended-on package is more likely to be available if the package declares a dependency (particularly in the case of postrm remove). The postrm script must gracefully skip actions that require a dependency if that dependency isn’t available.
|
||||||
|
*/
|
||||||
|
Depends?: Dependencie[];
|
||||||
|
/**
|
||||||
|
* This field is like Depends, except that it also forces dpkg to complete installation of the packages named before even starting the installation of the package which declares the pre-dependency, as follows:
|
||||||
|
*
|
||||||
|
* When a package declaring a pre-dependency is about to be unpacked the pre-dependency can be satisfied if the depended-on package is either fully configured, or even if the depended-on package(s) are only in the “Unpacked” or the “Half-Configured” state, provided that they have been configured correctly at some point in the past (and not removed or partially removed since). In this case, both the previously-configured and currently “Unpacked” or “Half-Configured” versions must satisfy any version clause in the Pre-Depends field.
|
||||||
|
*
|
||||||
|
* When the package declaring a pre-dependency is about to be configured, the pre-dependency will be treated as a normal Depends. It will be considered satisfied only if the depended-on package has been correctly configured. However, unlike with Depends, Pre-Depends does not permit circular dependencies to be broken. If a circular dependency is encountered while attempting to honor Pre-Depends, the installation will be aborted.
|
||||||
|
*
|
||||||
|
* Pre-Depends are also required if the preinst script depends on the named package. It is best to avoid this situation if possible.
|
||||||
|
*
|
||||||
|
* Pre-Depends should be used sparingly, preferably only by packages whose premature upgrade or installation would hamper the ability of the system to continue with any upgrade that might be in progress.
|
||||||
|
*
|
||||||
|
* You should not specify a Pre-Depends entry for a package before this has been discussed on the debian-devel mailing list and a consensus about doing that has been reached. See Dependencies.
|
||||||
|
*/
|
||||||
|
"Pre-Depends"?: Dependencie[];
|
||||||
|
/**
|
||||||
|
* This declares a strong, but not absolute, dependency.
|
||||||
|
*
|
||||||
|
* The Recommends field should list packages that would be found together with this one in all but unusual installations.
|
||||||
|
*/
|
||||||
|
Recommends?: Dependencie[];
|
||||||
|
/** This is used to declare that one package may be more useful with one or more others. Using this field tells the packaging system and the user that the listed packages are related to this one and can perhaps enhance its usefulness, but that installing this one without them is perfectly reasonable. */
|
||||||
|
Suggests?: Dependencie[];
|
||||||
|
/** This field is similar to Suggests but works in the opposite direction. It is used to declare that a package can enhance the functionality of another package. */
|
||||||
|
Enhances?: Dependencie[];
|
||||||
|
/** Breaks is described in Packages which break other packages - Breaks */
|
||||||
|
Breaks?: Dependencie[];
|
||||||
|
/** Conflicts is described in Conflicting binary packages - Conflicts. The rest are described below. */
|
||||||
|
Conflicts?: Dependencie[];
|
||||||
|
|
||||||
|
"Original-Maintainer"?: string;
|
||||||
|
Bugs?: string;
|
||||||
|
Task?: string;
|
||||||
|
Tags?: string[];
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Packages file control */
|
||||||
|
export interface DebianControlPackages extends DebianControl {
|
||||||
|
Filename: string;
|
||||||
|
Size: number|bigint;
|
||||||
|
MD5sum: string;
|
||||||
|
|
||||||
|
Origin?: string;
|
||||||
|
SHA1?: string;
|
||||||
|
SHA256?: string;
|
||||||
|
SHA512?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create control file
|
||||||
|
* @param config - Package config
|
||||||
|
*/
|
||||||
|
export function createControl(config: DebianControl|DebianControlPackages): string {
|
||||||
|
if (!config.Package || typeof config.Package !== "string") throw new TypeError("Set package name!");
|
||||||
|
else if (config.Package.trim().toLowerCase() !== config.Package || !((/^[a-z0-9][a-z0-9\.\+\-]+$/).test(config.Package))) throw new TypeError("Set valid package name!");
|
||||||
|
else if (!(archs.includes(config.Architecture))) throw new TypeError("Invalid arch");
|
||||||
|
else if (!config.Description || typeof config.Description !== "string" || config.Description.length <= 1) throw new TypeError("Set package Description");
|
||||||
|
const isDep = (arg: any): arg is "Depends" => ([ "Depends", "Pre-Depends", "Recommends", "Suggests", "Enhances", "Breaks", "Conflicts" ]).includes(arg);
|
||||||
|
const configBuff: string[] = [];
|
||||||
|
keys(config).forEach(keyName => {
|
||||||
|
if (([undefined, null, ""]).includes(config[keyName] as any)) return;
|
||||||
|
let line = String().concat(keyName, ": ");
|
||||||
|
const data = config[keyName];
|
||||||
|
if (keyName === "Description") {
|
||||||
|
let [ syno, ...extend ] = config[keyName].trim().split("\n");
|
||||||
|
extend = extend.join("\n").trim().split("\n");
|
||||||
|
line = line.concat(syno.trim(), "\n", extend.map(s => {
|
||||||
|
if ((["", "."]).includes((s = s.trimEnd()))) return " .";
|
||||||
|
return String().concat(" ", s);
|
||||||
|
}).join("\n")).trim();
|
||||||
|
} else if (isDep(keyName)) line = line.concat(config[keyName].map(s => s.length === 1 ? s[0] : (s.length === 2 ? `${s[0]} [${s[1]}]` : (s[1] === "|" ? `${s[0]} | ${s[2]}` : `${s[0]} (${s[1]} ${s[2]})`))).join(", "));
|
||||||
|
else if (typeof data === "boolean") line = line.concat(data ? "yes" : "no");
|
||||||
|
else if (Array.isArray(data)) line = line.concat(data.join(", "));
|
||||||
|
else if (typeof data === "bigint") line = data.toString().endsWith("n") ? line.concat(data.toString().slice(0, -1)) : line.concat(data.toString());
|
||||||
|
else line = line.concat(String(data));
|
||||||
|
configBuff.push(line);
|
||||||
|
});
|
||||||
|
|
||||||
|
return configBuff.join("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
function includes(str: string, sear: string|string[]): boolean {
|
||||||
|
if (Array.isArray(sear)) return sear.some(s => str.indexOf(s) != -1);
|
||||||
|
return str.indexOf(sear) != -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse control file
|
||||||
|
*/
|
||||||
|
export function parseControl(control: string|Buffer): DebianControl {
|
||||||
|
const Obj: [keyof DebianControlPackages, string][] = [], isDep = (arg: any): arg is "Depends" => ([ "Depends", "Pre-Depends", "Recommends", "Suggests", "Enhances", "Breaks", "Conflicts" ]).includes(arg);
|
||||||
|
if (Buffer.isBuffer(control)) control = control.toString("utf8");
|
||||||
|
const lines = control.trim().split("\n");
|
||||||
|
while (lines.length > 0) {
|
||||||
|
const line = lines.shift().trimEnd();
|
||||||
|
if ((["\t", " "]).includes(line[0])) {
|
||||||
|
Obj.at(-1)[1] = Obj.at(-1)[1].concat("\n", line);
|
||||||
|
} else if (line.indexOf(":") >= 1) {
|
||||||
|
const sp = line.indexOf(":");
|
||||||
|
Obj.push([ line.slice(0, sp) as any, line.slice(sp+1).trim() ]);
|
||||||
|
} else Obj.at(-1)[1] = Obj.at(-1)[1].concat("\n", line);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Obj.reduce<DebianControl>((acc, [ key, value ]) => {
|
||||||
|
if (key === "Description") {
|
||||||
|
const [ syno, ...extend ] = value.split("\n");
|
||||||
|
const spaceTrim = Array.from(new Set(extend.map(s => s.length - s.trimStart().length).sort())).filter(i => i >= 1).at(0);
|
||||||
|
for (const line in extend) {
|
||||||
|
if (extend[line].trim() === ".") extend[line] = "";
|
||||||
|
else if (extend[line].slice(0, spaceTrim).trim() === "") extend[line] = extend[line].slice(spaceTrim).trimEnd();
|
||||||
|
}
|
||||||
|
acc["Description"] = String().concat(syno.trim(), "\n", extend.join("\n")).trim();
|
||||||
|
} else if (isDep(key)) {
|
||||||
|
acc[key] = [];
|
||||||
|
for (const val of value.split(",").map(s => s.trim())) {
|
||||||
|
if (val.indexOf("|") > 0) {
|
||||||
|
const or = val.indexOf("|");
|
||||||
|
acc[key].push([
|
||||||
|
val.slice(0, or).trim(),
|
||||||
|
"|",
|
||||||
|
val.slice(or+1).trim()
|
||||||
|
]);
|
||||||
|
} else if (includes(val, "[")) {
|
||||||
|
const a1 = val.indexOf("["), a2 = val.indexOf("]");
|
||||||
|
const insider = val.slice(a1+1, a2).trim();
|
||||||
|
acc[key].push([ val.slice(0, a1).trim(), insider ]);
|
||||||
|
} else if (includes(val, ["<<", "<=", "=", ">=", ">>"])) {
|
||||||
|
const a1 = val.indexOf("("), a2 = val.indexOf(")");
|
||||||
|
const insider = val.slice(a1+1, a2).trim();
|
||||||
|
acc[key].push([
|
||||||
|
val.slice(0, a1).trim(),
|
||||||
|
insider.slice(0, 2).trim() as any,
|
||||||
|
insider.slice(2).trim(),
|
||||||
|
]);
|
||||||
|
} else acc[key].push([ val ]);
|
||||||
|
}
|
||||||
|
} else acc[key] = value;
|
||||||
|
return acc;
|
||||||
|
}, Object.create({}));
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Package {
|
||||||
|
/** Package control */
|
||||||
|
control: DebianControl;
|
||||||
|
|
||||||
|
/** Compress tarballs files */
|
||||||
|
compress?: {
|
||||||
|
/**
|
||||||
|
* Compress the data.tar tar to the smallest possible size
|
||||||
|
*/
|
||||||
|
data?: Exclude<Compressors, "deflate">;
|
||||||
|
/**
|
||||||
|
* compress control file to the smallest file possible
|
||||||
|
*/
|
||||||
|
control?: Exclude<Compressors, "zst"|"deflate">;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scripts or binary files to run post or pre action
|
||||||
|
*
|
||||||
|
* If set file path load directly
|
||||||
|
@example {
|
||||||
|
"preinst": "#!/bin/bash\nset -ex\necho \"Ok Google\"",
|
||||||
|
"postinst": "/var/lib/example/removeMicrosoft.sh"
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
scripts?: {
|
||||||
|
/** Run script before install packages */
|
||||||
|
preinst?: string;
|
||||||
|
/** Run script before remove package */
|
||||||
|
prerm?: string;
|
||||||
|
/** After install package */
|
||||||
|
postinst?: string;
|
||||||
|
/** After package removed */
|
||||||
|
postrm?: string;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Add files to data tar
|
||||||
|
*/
|
||||||
|
dataFiles(callback: (done: boolean, fileInfo?: fs.BigIntStats|fs.Stats, fileStream?: stream.Readable) => void): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createPackage(config: Package) {}
|
||||||
|
createPackage({
|
||||||
|
compress: { control: "gzip", data: "gzip" },
|
||||||
|
control: {
|
||||||
|
Package: "google",
|
||||||
|
Version: "1.1.1",
|
||||||
|
Architecture: "all",
|
||||||
|
Description: "google",
|
||||||
|
Maintainer: "Matheus Sampaio Queiroga <srherobrine20@gmail.com>",
|
||||||
|
},
|
||||||
|
dataFiles(callback) {
|
||||||
|
callback()
|
||||||
|
},
|
||||||
|
})
|
0
src/dpkg/src/index.ts
Normal file
0
src/dpkg/src/index.ts
Normal file
3
src/dpkg/tsconfig.json
Normal file
3
src/dpkg/tsconfig.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"extends": "../../tsconfig.json"
|
||||||
|
}
|
17
src/index.ts
17
src/index.ts
@ -1,17 +0,0 @@
|
|||||||
#!/usr/bin/env node
|
|
||||||
import { Config, Connect, Source, generateGPG } from "./config.js";
|
|
||||||
import { createRoute } from "./server.js";
|
|
||||||
// import yargs from "yargs";
|
|
||||||
// const terminalSize = typeof process.stdout.getWindowSize === "function" ? process.stdout.getWindowSize()[0] : null;
|
|
||||||
// yargs(process.argv.slice(2)).wrap(terminalSize).version(false).help(true).alias("h", "help").strictOptions();
|
|
||||||
|
|
||||||
const initialConfig = new Config();
|
|
||||||
const gpg = await generateGPG();
|
|
||||||
initialConfig.publicGPG = gpg.publicKey;
|
|
||||||
initialConfig.privateGPG = gpg.privateKey;
|
|
||||||
initialConfig.set("google", new Source());
|
|
||||||
|
|
||||||
const db = await Connect(initialConfig);
|
|
||||||
const app = await createRoute(db);
|
|
||||||
|
|
||||||
app.listen(3000, () => console.log("Listen on 3000"));
|
|
@ -1,38 +0,0 @@
|
|||||||
import fs from "node:fs/promises";
|
|
||||||
import { createWriteStream, createReadStream } from "node:fs";
|
|
||||||
import { Connection } from "./config.js";
|
|
||||||
import { debianControl, dpkg } from "@sirherobrine23/dpkg";
|
|
||||||
import path from "node:path";
|
|
||||||
import { extendsFS } from "@sirherobrine23/extends";
|
|
||||||
import { finished } from "node:stream/promises";
|
|
||||||
import { compressStream } from "@sirherobrine23/decompress";
|
|
||||||
|
|
||||||
export async function createPackage(db: Connection, repository: string) {
|
|
||||||
const repo = db.repoConfig.get(repository);
|
|
||||||
const packageArray = await db.packageCollection.find({ $and: Array.from(repo.keys()).map(i => ({ repositorys: [i] })) }).toArray();
|
|
||||||
const cc = packageArray.reduce<{ [k: string]: { [c: string]: debianControl[] } }>((acc, info) => {
|
|
||||||
info.repositorys.filter(info => info.repository === repository).forEach(repoID => {
|
|
||||||
acc[repo.get(repoID.origim).componentName] ??= {};
|
|
||||||
acc[repo.get(repoID.origim).componentName][info.control.Architecture] ??= [];
|
|
||||||
acc[repo.get(repoID.origim).componentName][info.control.Architecture].push(info.control);
|
|
||||||
});
|
|
||||||
return acc;
|
|
||||||
}, {});
|
|
||||||
const repositoryRoot = path.join(db.repoConfig.tmpFolder, "dists", repository);
|
|
||||||
for (const componentName in cc) {
|
|
||||||
for (const arch in cc[componentName]) {
|
|
||||||
if (!(await extendsFS.exists(path.join(repositoryRoot, componentName, arch)))) await fs.mkdir(path.join(repositoryRoot, componentName, arch), { recursive: true });
|
|
||||||
const file = path.join(repositoryRoot, componentName, arch, "packages");
|
|
||||||
const wr = createWriteStream(file);
|
|
||||||
for (const index in cc[componentName][arch]) {
|
|
||||||
const control = cc[componentName][arch][index];
|
|
||||||
if (Number(index) > 0) wr.write(Buffer.from("\n"));
|
|
||||||
await new Promise<void>((done, reject) => wr.write(dpkg.createControl(control), err => err ? reject(err) : done()));
|
|
||||||
}
|
|
||||||
wr.close();
|
|
||||||
await finished(wr);
|
|
||||||
await finished(createReadStream(file).pipe(compressStream("gzip")).pipe(createWriteStream(file + ".gz")));
|
|
||||||
await finished(createReadStream(file).pipe(compressStream("xz")).pipe(createWriteStream(file + ".xz")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
/**
|
|
||||||
* Fix Promises catch to express send correct error to client and dont crash server
|
|
||||||
*/
|
|
||||||
import expressLayer from "express/lib/router/layer.js";
|
|
||||||
expressLayer.prototype.handle_request = async function handle_request_promised(...args) {
|
|
||||||
var fn = this.handle;
|
|
||||||
if (fn.length > 3) return args.at(-1)();
|
|
||||||
try {
|
|
||||||
await fn(...args);
|
|
||||||
} catch (err) {
|
|
||||||
args.at(-1)(err);
|
|
||||||
}
|
|
||||||
}
|
|
164
src/server.ts
164
src/server.ts
@ -1,164 +0,0 @@
|
|||||||
import { extendsFS } from "@sirherobrine23/extends";
|
|
||||||
import express from "express";
|
|
||||||
import cluster from "node:cluster";
|
|
||||||
import crypto from "node:crypto";
|
|
||||||
import { createWriteStream } from "node:fs";
|
|
||||||
import fs from "node:fs/promises";
|
|
||||||
import path from "node:path";
|
|
||||||
import stream from "node:stream";
|
|
||||||
import { finished } from "node:stream/promises";
|
|
||||||
import { parse } from "node:url";
|
|
||||||
import { Connection } from "./config.js";
|
|
||||||
import "./patchExpress.js";
|
|
||||||
import { http } from "@sirherobrine23/http";
|
|
||||||
import { googleDriver, oracleBucket } from "@sirherobrine23/cloud";
|
|
||||||
|
|
||||||
const Range = (max: number) => {
|
|
||||||
if (max < 0 || isNaN(max)) return new stream.PassThrough();
|
|
||||||
return new stream.Transform({
|
|
||||||
write(chunk, encoding, callback) {
|
|
||||||
if (!(Buffer.isBuffer(chunk))) chunk = Buffer.from(chunk, encoding);
|
|
||||||
this.push(chunk.subarray(Math.max(0, max)));
|
|
||||||
max += Buffer.byteLength(chunk);
|
|
||||||
if (0 <= max) this.push(null);
|
|
||||||
callback();
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function createRoute(configManeger: Connection) {
|
|
||||||
const app = express();
|
|
||||||
app.disable("x-powered-by").disable("etag");
|
|
||||||
app.use(express.json(), (_req, res, next) => {
|
|
||||||
res.setHeader("cluster-id", String(cluster.isPrimary ? 1 : cluster.worker.id));
|
|
||||||
res.json = (body) => res.setHeader("Content-Type", "application/json").send(JSON.stringify(body, null, 2)); return next();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Public key
|
|
||||||
app.get("/public(_key|)(|.gpg|.dearmor)", async (req, res) => {
|
|
||||||
if (!configManeger.repoConfig.publicGPG) return res.status(400).json({ error: "GPG Key is disabled" });
|
|
||||||
return res.setHeader("Content-Type", req.path.endsWith(".dearmor") ? "octect/stream" : "text/plain").send(await configManeger.repoConfig.getPulicKey(req.path.endsWith(".dearmor") ? "dearmor" : "armor"));
|
|
||||||
});
|
|
||||||
|
|
||||||
app.get("/dists/(:distName)(|/InRelease|/Release(.gpg)?)?", (req, res) => {
|
|
||||||
const { distName } = req.params;
|
|
||||||
if (!(configManeger.repoConfig.has(distName))) return res.status(404).json({ error: "Ditribuition not exist" });
|
|
||||||
|
|
||||||
return res.json({ distName });
|
|
||||||
});
|
|
||||||
|
|
||||||
app.get("/dists/:distName/:componentName/binary-:Arch/Packages(.(gz|xz))?", (req, res) => {
|
|
||||||
const { distName, componentName, Arch } = req.params;
|
|
||||||
const compression = req.path.endsWith(".gz") ? "gzip" : req.path.endsWith(".xz") ? "lzma" : "none";
|
|
||||||
if (!(configManeger.repoConfig.has(distName))) return res.status(404).json({ error: "Ditribuition not exist" });
|
|
||||||
const sources = configManeger.repoConfig.get(distName).toArray().filter(info => info.componentName === componentName);
|
|
||||||
if (!sources.length) return res.status(404).json({ error: "This component not exists" });
|
|
||||||
|
|
||||||
return res.json({
|
|
||||||
distName,
|
|
||||||
componentName,
|
|
||||||
Arch,
|
|
||||||
compression
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
app.post("/pool/upload", async (req, res) => {
|
|
||||||
const { repository, destID } = (req.body || {});
|
|
||||||
if (!(configManeger.repoConfig.has(repository))) return res.status(400).json({ error: "Add valid repository name" });
|
|
||||||
else if (!(configManeger.repoConfig.get(repository).has(destID))) return res.status(400).json({ error: "Add valid source id" });
|
|
||||||
else if (!(configManeger.repoConfig.get(repository).get(destID).enableUpload)) return res.status(401).json({ error: "the source has upload disabled or not supported" });
|
|
||||||
|
|
||||||
const ID = crypto.randomUUID(), token = ([
|
|
||||||
crypto.randomBytes(4).toString("hex"),
|
|
||||||
crypto.randomBytes(crypto.randomInt(4, 16)).toString("hex"),
|
|
||||||
crypto.randomBytes(crypto.randomInt(2, 8)).toString("hex"),
|
|
||||||
]).join("-");
|
|
||||||
let filePath: string;
|
|
||||||
while (true) {
|
|
||||||
filePath = path.join(configManeger.repoConfig.tmpFolder, crypto.randomBytes(crypto.randomInt(8, 16)).toString("hex"));
|
|
||||||
if (!(await extendsFS.exists(filePath))) break;
|
|
||||||
}
|
|
||||||
await fs.writeFile(filePath, ""); // Touch file
|
|
||||||
|
|
||||||
await configManeger.uploadCollection.insertOne({
|
|
||||||
ID,
|
|
||||||
repository,
|
|
||||||
destID,
|
|
||||||
validAt: Date.now() + 1000 * 60 * 60 * 30,
|
|
||||||
token,
|
|
||||||
filePath,
|
|
||||||
});
|
|
||||||
|
|
||||||
return res.setHeader("Location", path.posix.join(parse(req.url).pathname, ID)).status(201).json({
|
|
||||||
token,
|
|
||||||
ID
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PUT data to file to package to later upload to Dest
|
|
||||||
*
|
|
||||||
* to add data Set `Content-Range` and `Content-Type: application/octet-stream` to Upload
|
|
||||||
* to submit, delete this headers up
|
|
||||||
*/
|
|
||||||
app.put("/pool/upload/:sessionID", async (req, res) => {
|
|
||||||
const { sessionID } = req.params;
|
|
||||||
const info = await configManeger.uploadCollection.findOne({ ID: sessionID });
|
|
||||||
const isPut = (req.headers["content-type"]||"").startsWith("application/octet-stream");
|
|
||||||
if (!info) return res.status(400).json({ error: "Require upload ID" });
|
|
||||||
else if (req.headers.authorization.slice(5).trim() !== info.token) return res.status(400).json({ error: "invalid token" });
|
|
||||||
else if (isPut && !(req.headers["content-range"])) return res.status(400).json({ error: "set Content-Range to put file" });
|
|
||||||
|
|
||||||
if (isPut) {
|
|
||||||
if (req.headers["content-range"].startsWith("bytes ")) req.headers["content-range"] = req.headers["content-range"].slice(5).trim();
|
|
||||||
if (req.headers["content-range"].trim() === "*") req.headers["content-range"] = "0";
|
|
||||||
|
|
||||||
const [start, _end] = req.headers["content-range"].split("-"), [end] = _end.split("/");
|
|
||||||
if (Number(end) < Number(start)) return res.status(400).json({ error: "Require file more that " + start })
|
|
||||||
await finished(req.pipe(Range(Number(end || -1))).pipe(createWriteStream(info.filePath, { start: Number(start) })));
|
|
||||||
await configManeger.uploadCollection.findOneAndUpdate({ ID: sessionID }, { $set: { validAt: 1000 * 60 * 60 * 30 } })
|
|
||||||
return res.status(202).end();
|
|
||||||
}
|
|
||||||
|
|
||||||
const upload = await configManeger.repoConfig.get(info.repository).uploadFile(info.destID, info.filePath);
|
|
||||||
await fs.rm(info.filePath, { force: true });
|
|
||||||
await configManeger.uploadCollection.findOneAndDelete({ ID: info.ID });
|
|
||||||
return res.setHeader("Location", `/pool/${upload.controlFile.MD5sum}.deb`).status(201).end();
|
|
||||||
});
|
|
||||||
|
|
||||||
app.get("/pool/(:packageHASH)(|.deb)?", async (req, res, next) => {
|
|
||||||
const download = req.path.endsWith(".deb"), { packageHASH } = req.params;
|
|
||||||
const info = await configManeger.packageCollection.findOne({ $or: [{ "control.MD5sum": packageHASH }, { "control.SHA1": packageHASH }, { "control.SHA256": packageHASH }, { "control.SHA512": packageHASH }] });
|
|
||||||
if (!info) return res.status(404).json({ error: "Package not registred" });
|
|
||||||
else if (!download) return res.json(info.control);
|
|
||||||
const origem = info.repositorys.find(info => configManeger.repoConfig.has(info.repository) && configManeger.repoConfig.get(info.repository).has(info.origim));
|
|
||||||
if (!origem) return res.status(400).json({ error: "Cannot get origem source" });
|
|
||||||
const src = configManeger.repoConfig.get(origem.repository).get(origem.origim);
|
|
||||||
if (src.type === "http") {
|
|
||||||
return http.streamRequest(src.url, {
|
|
||||||
query: src.query,
|
|
||||||
headers: src.header
|
|
||||||
}).then(src => src.pipe(res)).catch(next);
|
|
||||||
} else if (src.type === "github") {
|
|
||||||
const download: { url: string } = info.restoreFile;
|
|
||||||
return http.streamRequest(download.url, {
|
|
||||||
headers: src.token ? { Authorization: `token ${src.token}` } : {},
|
|
||||||
query: { token: src.token },
|
|
||||||
}).then(src => src.pipe(res)).catch(next);
|
|
||||||
} else if (src.type === "mirror") {
|
|
||||||
const download: { url: string } = info.restoreFile;
|
|
||||||
return http.streamRequest(download.url).then(src => src.pipe(res)).catch(next);
|
|
||||||
} else if (src.type === "oracleBucket") {
|
|
||||||
const download: { filePath: string } = info.restoreFile;
|
|
||||||
const oci = await oracleBucket.oracleBucket(src.authConfig);
|
|
||||||
return oci.getFileStream(download.filePath).then(src => src.pipe(res)).catch(next);
|
|
||||||
} else if (src.type === "googleDriver") {
|
|
||||||
const download: { id: string } = info.restoreFile;
|
|
||||||
const gdrive = await googleDriver.GoogleDriver({ oauth: await googleDriver.createAuth({ clientID: src.clientId, clientSecret: src.clientSecret, token: src.clientToken, authUrlCallback: () => { throw new Error("Auth disabled"); }, tokenCallback: () => { }, redirectURL: null }) });
|
|
||||||
return gdrive.getFileStream(download.id).then(src => src.pipe(res)).catch(next);
|
|
||||||
} else if (src.type === "docker") {
|
|
||||||
throw new Error("CLOSE");
|
|
||||||
} else return res.status(404).json({ error: "Source origem is unknown" });
|
|
||||||
});
|
|
||||||
return app;
|
|
||||||
}
|
|
@ -13,14 +13,15 @@
|
|||||||
"noFallthroughCasesInSwitch": true,
|
"noFallthroughCasesInSwitch": true,
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"allowJs": true,
|
"allowJs": true,
|
||||||
|
"composite": true,
|
||||||
"lib": [
|
"lib": [
|
||||||
"ESNext",
|
"ESNext"
|
||||||
"ES7"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"**/*.test.ts",
|
"**/*.test.ts",
|
||||||
"**/test*/**",
|
"**/test*/**",
|
||||||
|
"**/scripts/**",
|
||||||
"node_modules/"
|
"node_modules/"
|
||||||
],
|
],
|
||||||
"ts-node": {
|
"ts-node": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user