Skip to content

Commit

Permalink
feat(package): add instruction @apt, @apt-get to install ubuntu packages
Browse files Browse the repository at this point in the history
  • Loading branch information
yunielrc committed Sep 26, 2023
1 parent cea6dea commit 7186c5a
Show file tree
Hide file tree
Showing 15 changed files with 294 additions and 41 deletions.
2 changes: 1 addition & 1 deletion Vedvfile.manjaro
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RUN echo 'export IMAGE_BUILDING=true' | \
WORKDIR /home/vedv/ydf

# generate mirrors
RUN sudo pacman-mirrors --country United_States
RUN sudo pacman-mirrors --fasttrack

# install flatpak gnome base system
RUN sudo -H flatpak install --assumeyes --noninteractive \
Expand Down
12 changes: 9 additions & 3 deletions packages.env
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ PKG_DEV_ANY_NPM=(
#

## RUNTIME
PKG_RUN_MANJARO_YAY=(

PKG_RUN_MANJARO_PACMAN=(
bash
)

# PKG_RUN_MANJARO_YAY=(

# )

## OPTIONAL
PKG_OPT_MANJARO_PACMAN=(
yay
Expand Down Expand Up @@ -62,7 +66,9 @@ PKG_DEV_MANJARO_NPM=("${PKG_DEV_ANY_NPM[@]}")
#

## RUNTIME
PKG_RUN_UBUNTU_APT=()
PKG_RUN_UBUNTU_APT=(
bash
)

# PKG_RUN_UBUNTU_PIP=("${PKG_RUN_ANY_PIP[@]}")
# PKG_RUN_UBUNTU_NPM=("${PKG_RUN_ANY_NPM[@]}")
Expand Down
45 changes: 44 additions & 1 deletion src/usr/lib/ydf/components/package/ydf-package-service.bash
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON='@flatpak @snap install docke
readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_ANY="preinstall ${__YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON}"
# MANJARO
readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_MANJARO="preinstall @pacman @yay ${__YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON}"
readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_UBUNTU="preinstall ${__YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON}"

readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_UBUNTU="preinstall @apt @apt-get ${__YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON}"

#
# FUNCTIONS
Expand Down Expand Up @@ -556,6 +557,48 @@ ydf::package_service::__instruction_dconf_ini() {
dconf load / <dconf.ini
}

#
# Execute @apt instruction
#
# Arguments:
# pkg_name string package name
#
# Returns:
# 0 on success, non-zero on error.
#
ydf::package_service::__instruction_@apt() {
local -r pkg_name="$1"
# select the first no empty line
local -r apt_pkg_name="$(ydf::utils::text_file_to_words @apt)"

sudo -E apt update -y &&
sudo -E apt upgrade -y

eval sudo -H DEBIAN_FRONTEND=noninteractive apt install -y \
"${apt_pkg_name:-"$pkg_name"}"
}

#
# Execute @apt-get instruction
#
# Arguments:
# pkg_name string package name
#
# Returns:
# 0 on success, non-zero on error.
#
ydf::package_service::__instruction_@apt-get() {
local -r pkg_name="$1"
# select the first no empty line
local -r apt_pkg_name="$(ydf::utils::text_file_to_words @apt-get)"

sudo -E apt-get update -y &&
sudo -E apt-get upgrade -y

eval sudo -H DEBIAN_FRONTEND=noninteractive apt-get install -y \
"${apt_pkg_name:-"$pkg_name"}"
}

#
# Install a ydotfile package from a directory
#
Expand Down
2 changes: 2 additions & 0 deletions tests/fixtures/packages/25bat@apt/@apt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

bat
1 change: 1 addition & 0 deletions tests/fixtures/packages/26exa@apt-get/@apt-get
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exa
Empty file.
Empty file.
86 changes: 86 additions & 0 deletions tests/usr/lib/ydf/components/package/ydf-package-command.f.bats
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ load test_helper

setup() {
export YDF_PACKAGE_SERVICE_DEFAULT_OS="$TEST_OS"
export E_YDF_PACKAGE_SERVICE_DEFAULT_OS="$TEST_OS"

export E_YDF_UTILS_NO_MSG=true

if [[ -f /home/vedv/.yzsh-gen.env ]]; then
Expand Down Expand Up @@ -860,3 +862,87 @@ preinstall: preinstall succeed"
assert [ -L '/home/vedv/.yzsh/themes/local/24ydftheme.theme.zsh' ]
assert [ -f '/home/vedv/.yzsh/themes/local/24ydftheme.theme.zsh' ]
}

# Tests for ydf package install 25bat@apt
@test "ydf package install 25bat@apt Should succeed" {
if [[ "$YDF_PACKAGE_SERVICE_DEFAULT_OS" != ubuntu ]]; then
skip "Only for ubuntu"
fi

sudo -E DEBIAN_FRONTEND=noninteractive apt remove -y bat

local -r _package_name="25bat@apt"

run ydf package install "$_package_name"

assert_success
assert_output --partial "Setting up bat"

run apt -qq list --installed bat

assert_success
assert_output --partial "bat/"
}

# Tests for ydf package install bat
@test "ydf package install bat Should succeed with @apt" {
if [[ "$YDF_PACKAGE_SERVICE_DEFAULT_OS" != ubuntu ]]; then
skip "Only for ubuntu"
fi

sudo -E DEBIAN_FRONTEND=noninteractive apt remove -y bat

local -r _package_name="bat"

run ydf package install "$_package_name"

assert_success
assert_output --partial "Setting up bat"

run apt -qq list --installed bat

assert_success
assert_output --partial "bat/"
}

# Tests for ydf package install 26exa@apt-get
@test "ydf package install 26exa@apt-get Should succeed with @apt-get" {
if [[ "$YDF_PACKAGE_SERVICE_DEFAULT_OS" != ubuntu ]]; then
skip "Only for ubuntu"
fi

sudo -E DEBIAN_FRONTEND=noninteractive apt remove -y exa

local -r _package_name="26exa@apt-get"

run ydf package install "$_package_name"

assert_success
assert_output --partial "Setting up exa"

run apt -qq list --installed exa

assert_success
assert_output --partial "exa/"
}

# Tests for ydf package install exa
@test "ydf package install exa Should succeed with @apt-get" {
if [[ "$YDF_PACKAGE_SERVICE_DEFAULT_OS" != ubuntu ]]; then
skip "Only for ubuntu"
fi

sudo -E DEBIAN_FRONTEND=noninteractive apt remove -y exa

local -r _package_name="exa"

run ydf package install "$_package_name"

assert_success
assert_output --partial "Setting up exa"

run apt -qq list --installed exa

assert_success
assert_output --partial "exa/"
}
84 changes: 84 additions & 0 deletions tests/usr/lib/ydf/components/package/ydf-package-service.i.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1334,3 +1334,87 @@ install: HOME: /home/vedv"
assert [ -L '/home/vedv/.yzsh/themes/local/24ydftheme.theme.zsh' ]
assert [ -f '/home/vedv/.yzsh/themes/local/24ydftheme.theme.zsh' ]
}

# Tests for ydf::package_service::__instruction_@apt()
@test "ydf::package_service::__instruction_@apt() Should succeed With 25bat@apt" {
if [[ "$YDF_PACKAGE_SERVICE_DEFAULT_OS" != ubuntu ]]; then
skip "Only for ubuntu"
fi

sudo -E DEBIAN_FRONTEND=noninteractive apt remove -y bat

cd "${TEST_FIXTURES_DIR}/packages/25bat@apt"

run ydf::package_service::__instruction_@apt '25bat@apt'

assert_success
assert_output --partial "Setting up bat"

run apt -qq list --installed bat

assert_success
assert_output --partial "bat/"
}

# Tests for ydf::package_service::__instruction_@apt()
@test "ydf::package_service::__instruction_@apt() Should succeed With bat" {
if [[ "$YDF_PACKAGE_SERVICE_DEFAULT_OS" != ubuntu ]]; then
skip "Only for ubuntu"
fi

sudo -E DEBIAN_FRONTEND=noninteractive apt remove -y bat

cd "${TEST_FIXTURES_DIR}/packages/bat"

run ydf::package_service::__instruction_@apt 'bat'

assert_success
assert_output --partial "Setting up bat"

run apt -qq list --installed bat

assert_success
assert_output --partial "bat/"
}

# Tests for ydf::package_service::__instruction_@apt-get()
@test "ydf::package_service::__instruction_@apt-get() Should succeed With 25exa@apt-get" {
if [[ "$YDF_PACKAGE_SERVICE_DEFAULT_OS" != ubuntu ]]; then
skip "Only for ubuntu"
fi

sudo -E DEBIAN_FRONTEND=noninteractive apt remove -y exa

cd "${TEST_FIXTURES_DIR}/packages/26exa@apt-get"

run ydf::package_service::__instruction_@apt-get '26exa@apt-get'

assert_success
assert_output --partial "Setting up exa"

run apt -qq list --installed exa

assert_success
assert_output --partial "exa/"
}

# Tests for ydf::package_service::__instruction_@apt-get()
@test "ydf::package_service::__instruction_@apt-get() Should succeed With exa" {
if [[ "$YDF_PACKAGE_SERVICE_DEFAULT_OS" != ubuntu ]]; then
skip "Only for ubuntu"
fi

sudo -E DEBIAN_FRONTEND=noninteractive apt remove -y exa

cd "${TEST_FIXTURES_DIR}/packages/exa"

run ydf::package_service::__instruction_@apt-get 'exa'

assert_success
assert_output --partial "Setting up exa"

run apt -qq list --installed exa

assert_success
assert_output --partial "exa/"
}
8 changes: 5 additions & 3 deletions tools/install-dev-manjaro
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ readonly IMAGE_BUILDING="${IMAGE_BUILDING:-false}"

sudo pacman -Syu --noconfirm --needed yay

# Install yay packages
# Install packages

## yay packages
yay -Sy --noconfirm --needed "${PKG_DEV_MANJARO_YAY[@]}"

### install vedv
if [[ "$IMAGE_BUILDING" == false ]]; then
# Install vedv
yay -Sy --noconfirm --needed vedv-git &&
sudo pacman -Syu --noconfirm --needed "$(mhwd-kernel -li | grep -Po '\(\Klinux\d+\S*(?=\))')-virtualbox-host-modules" &&
sudo vboxreload
Expand All @@ -25,7 +27,7 @@ if [[ "$IMAGE_BUILDING" == false ]]; then
EOF
fi

# Install npm packages
## npm packages
sudo -H npm install -g "${PKG_DEV_MANJARO_NPM[@]}"

# Configure
Expand Down
28 changes: 18 additions & 10 deletions tools/install-dev-ubuntu
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,32 @@ export DEBIAN_FRONTEND=noninteractive
sudo -E apt-get update -y &&
sudo -E apt-get upgrade -y

sudo -E apt-get install -y "${PKG_DEV_UBUNTU_APT[@]}"
# Install Packages

if command -v fdfind >/dev/null; then
sudo ln -s "$(command -v fdfind)" "$(dirname "$(command -v fdfind)")/fd"
fi
## apt packages
sudo -E apt-get install -y "${PKG_DEV_UBUNTU_APT[@]}"

# Install snap packages
# snap packages
# shellcheck disable=SC2086
for s in "${PKG_DEV_UBUNTU_SNAP[@]}"; do sudo snap install $s; done

# Install npm packages
# npm packages
sudo -H npm install -g "${PKG_DEV_UBUNTU_NPM[@]}"

# Install bash bats libs
## github packages

### Install bash bats libs
for bats_lib in bats-support bats-assert bats-file; do
repo="https://github.com/bats-core/${bats_lib}.git"
tag="$(git ls-remote --tags --exit-code --sort='v:refname' --refs "$repo" | tail -n 1 | cut -d/ -f3)"

sudo -H git clone "$repo" --depth 1 --branch "$tag" "/usr/lib/bash-${bats_lib}-git" >/dev/null
done

#### configure bash libs
sudo ln -s /usr/lib/bash-bats-file-git /usr/lib/bats-file

### Install vedv
if [[ "$IMAGE_BUILDING" == false ]]; then
# Install vedv
(
cd "$(mktemp -d)"

Expand All @@ -57,7 +58,14 @@ EOF
)
fi

# Configure

## configure fd
if command -v fdfind >/dev/null; then
sudo ln -s "$(command -v fdfind)" "$(dirname "$(command -v fdfind)")/fd"
fi

## configure git hooks
if [[ "$IMAGE_BUILDING" == false ]]; then
# configure git hooks
git config core.hooksPath .githooks
fi
9 changes: 7 additions & 2 deletions tools/install-opt-manjaro
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,10 @@ if [[ -f .ydf.env ]]; then
fi

cd "$(mktemp -d)"
git clone https://github.com/yunielrc/yzsh.git && cd yzsh
make install

for pkg in "${PKG_OPT_MANJARO_GITHUB[@]}"; do
(
git clone "https://github.com/${pkg}.git" && cd "${pkg#*/}"
make install
)
done
Loading

0 comments on commit 7186c5a

Please sign in to comment.