Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wrapper for package manipulation #320

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions tools/json/config.network.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,24 @@
"description": "Install Bluetooth support",
"command": [
"see_current_apt ",
"debconf-apt-progress -- apt-get -y install bluetooth bluez bluez-tools",
"check_if_installed xserver-xorg && debconf-apt-progress -- apt-get -y --no-install-recommends install pulseaudio-module-bluetooth blueman"
"pkg_install bluetooth bluez bluez-tools",
"pkg_installed xserver-xorg && pkg_install --no-install-recommends pulseaudio-module-bluetooth blueman"
],
"status": "Disabled",
"author": "@armbian",
"condition": "! check_if_installed bluetooth && ! check_if_installed bluez && ! check_if_installed bluez-tools"
"condition": "! pkg_installed bluetooth && ! pkg_installed bluez && ! pkg_installed bluez-tools"
},
{
"id": "NE102",
"description": "Remove Bluetooth support",
"command": [
"see_current_apt ",
"debconf-apt-progress -- apt-get -y remove bluetooth bluez bluez-tools",
"check_if_installed xserver-xorg && debconf-apt-progress -- apt-get -y remove pulseaudio-module-bluetooth blueman",
"debconf-apt-progress -- apt -y -qq autoremove"
"pkg_remove bluetooth bluez bluez-tools",
"pkg_installed xserver-xorg && pkg_remove pulseaudio-module-bluetooth blueman"
],
"status": "Disabled",
"author": "@armbian",
"condition": "check_if_installed bluetooth || check_if_installed bluez || check_if_installed bluez-tools"
"condition": "pkg_installed bluetooth || pkg_installed bluez || pkg_installed bluez-tools"
},
{
"id": "NE103",
Expand All @@ -84,7 +83,7 @@
],
"status": "Disabled",
"author": "@armbian",
"condition": "check_if_installed bluetooth || check_if_installed bluez || check_if_installed bluez-tools"
"condition": "pkg_installed bluetooth || pkg_installed bluez || pkg_installed bluez-tools"
},
{
"id": "NE104",
Expand All @@ -100,4 +99,4 @@
]
}
]
}
}
86 changes: 43 additions & 43 deletions tools/json/config.software.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions tools/json/config.system.json
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@
"description": "Disable OTP authentication",
"command": [
"clear",
"! check_if_installed libpam-google-authenticator && ! check_if_installed qrencode || debconf-apt-progress -- apt-get -y purge libpam-google-authenticator qrencode",
"! pkg_installed libpam-google-authenticator && ! pkg_installed qrencode || pkg_remove libpam-google-authenticator qrencode",
"sed -i \"s/^#\\?ChallengeResponseAuthentication.*/ChallengeResponseAuthentication no/\" /etc/ssh/sshd_config || sed -i \"0,/KbdInteractiveAuthentication/s//ChallengeResponseAuthentication yes/\" /etc/ssh/sshd_config",
"sed -i '/^auth required pam_google_authenticator.so nullok/ d' /etc/pam.d/sshd",
"systemctl restart sshd.service 2>/dev/null | systemctl restart ssh.service 2>/dev/null"
Expand All @@ -248,16 +248,16 @@
"id": "SY108",
"description": "Enable OTP authentication",
"command": [
"check_if_installed libpam-google-authenticator || debconf-apt-progress -- apt-get -y install libpam-google-authenticator",
"check_if_installed qrencode || debconf-apt-progress -- apt-get -y install qrencode",
"pkg_installed libpam-google-authenticator || pkg_install libpam-google-authenticator",
"pkg_installed qrencode || pkg_install qrencode",
"sed -i \"s/^#\\?ChallengeResponseAuthentication.*/ChallengeResponseAuthentication yes/\" /etc/ssh/sshd_config",
"sed -i $'/KbdInteractiveAuthentication/{iChallengeResponseAuthentication yes\\n:a;n;ba}' /etc/ssh/sshd_config || sed -n -i '/password updating/{p;:a;N;/@include common-password/!ba;s/.*\\n/auth required pam_google_authenticator.so nullok\\nauth required pam_permit.so\\n/};p' /etc/pam.d/sshd",
"[ ! -f /root/.google_authenticator ] && qr_code generate",
"systemctl restart sshd.service 2>/dev/null | systemctl restart ssh.service 2>/dev/null"
],
"status": "Stable",
"author": "@igorpecovnik",
"condition": "! check_if_installed libpam-google-authenticator || ! check_if_installed qrencode || grep -q '^ChallengeResponseAuthentication no' /etc/ssh/sshd_config || ! grep -q 'ChallengeResponseAuthentication' /etc/ssh/sshd_config"
"condition": "! pkg_installed libpam-google-authenticator || ! pkg_installed qrencode || grep -q '^ChallengeResponseAuthentication no' /etc/ssh/sshd_config || ! grep -q 'ChallengeResponseAuthentication' /etc/ssh/sshd_config"
},
{
"id": "SY109",
Expand Down
6 changes: 3 additions & 3 deletions tools/modules/functions/check_desktop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ function check_desktop() {

DISPLAY_MANAGER=""
DESKTOP_INSTALLED=""
check_if_installed nodm && DESKTOP_INSTALLED="nodm"
check_if_installed lightdm && DESKTOP_INSTALLED="lightdm"
check_if_installed lightdm && DESKTOP_INSTALLED="gnome"
pkg_installed nodm && DESKTOP_INSTALLED="nodm"
pkg_installed lightdm && DESKTOP_INSTALLED="lightdm"
pkg_installed lightdm && DESKTOP_INSTALLED="gnome"
[[ -n $(service lightdm status 2> /dev/null | grep -w active) ]] && DISPLAY_MANAGER="lightdm"
[[ -n $(service nodm status 2> /dev/null | grep -w active) ]] && DISPLAY_MANAGER="nodm"
[[ -n $(service gdm status 2> /dev/null | grep -w active) ]] && DISPLAY_MANAGER="gdm"
Expand Down
22 changes: 0 additions & 22 deletions tools/modules/functions/check_if_installed.sh

This file was deleted.

2 changes: 1 addition & 1 deletion tools/modules/functions/config_interface.sh
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ see_current_apt() {
return 0 # The package lists are up-to-date
else
[[ "$update_apt" != "update" ]] && echo "Update the package lists." # Suggest updating
[[ "$update_apt" == "update" ]] && apt_install_wrapper apt-get update
[[ "$update_apt" == "update" ]] && pkg_update
return 0 # The package lists are not up-to-date
fi
}
Expand Down
97 changes: 97 additions & 0 deletions tools/modules/functions/package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# package.sh

# internal function
_pkg_have_stdin() { [[ -t 0 ]]; }

declare -A module_options
module_options+=(
["pkg_configure,author"]="@dimitry-ishenko"
["pkg_configure,desc"]="Configure an unconfigured package"
["pkg_configure,example"]="pkg_configure"
["pkg_configure,feature"]="pkg_configure"
["pkg_configure,status"]="Interface"
)

pkg_configure()
{
_pkg_have_stdin && debconf-apt-progress -- dpkg --configure "$@" || dpkg --configure "$@"
}

module_options+=(
["pkg_full_upgrade,author"]="@dimitry-ishenko"
["pkg_full_upgrade,desc"]="Upgrade installed packages (potentially removing some)"
["pkg_full_upgrade,example"]="pkg_full_upgrade"
["pkg_full_upgrade,feature"]="pkg_full_upgrade"
["pkg_full_upgrade,status"]="Interface"
)

pkg_full_upgrade()
{
_pkg_have_stdin && debconf-apt-progress -- apt-get -y full-upgrade "$@" || apt-get -y full-upgrade "$@"
}

module_options+=(
["pkg_install,author"]="@dimitry-ishenko"
["pkg_install,desc"]="Install package"
["pkg_install,example"]="pkg_install neovim"
["pkg_install,feature"]="pkg_install"
["pkg_install,status"]="Interface"
)

pkg_install()
{
_pkg_have_stdin && debconf-apt-progress -- apt-get -y install "$@" || apt-get -y install "$@"
}

module_options+=(
["pkg_installed,author"]="@dimitry-ishenko"
["pkg_installed,desc"]="Check if package is installed"
["pkg_installed,example"]="pkg_installed mc"
["pkg_installed,feature"]="pkg_installed"
["pkg_installed,status"]="Interface"
)

pkg_installed()
{
local status=$(dpkg -s "$1" 2>/dev/null | sed -n "s/Status: //p")
! [[ -z "$status" || "$status" = *deinstall* || "$status" = *not-installed* ]]
}

module_options+=(
["pkg_remove,author"]="@dimitry-ishenko"
["pkg_remove,desc"]="Remove package"
["pkg_remove,example"]="pkg_remove nmap"
["pkg_remove,feature"]="pkg_remove"
["pkg_remove,status"]="Interface"
)

pkg_remove()
{
_pkg_have_stdin && debconf-apt-progress -- apt-get -y autopurge "$@" || apt-get -y autopurge "$@"
}

module_options+=(
["pkg_update,author"]="@dimitry-ishenko"
["pkg_update,desc"]="Update package repository"
["pkg_update,example"]="pkg_update"
["pkg_update,feature"]="pkg_update"
["pkg_update,status"]="Interface"
)

pkg_update()
{
_pkg_have_stdin && debconf-apt-progress -- apt-get -y update || apt-get -y update
}

module_options+=(
["pkg_upgrade,author"]="@dimitry-ishenko"
["pkg_upgrade,desc"]="Upgrade installed packages"
["pkg_upgrade,example"]="pkg_upgrade"
["pkg_upgrade,feature"]="pkg_upgrade"
["pkg_upgrade,status"]="Interface"
)

pkg_upgrade()
{
_pkg_have_stdin && debconf-apt-progress -- apt-get -y upgrade "$@" || apt-get -y upgrade "$@"
}
5 changes: 2 additions & 3 deletions tools/modules/functions/set_runtime_variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function set_runtime_variables() {
# If any dependencies are missing, print a combined message and exit
if [[ ${#missing_dependencies[@]} -ne 0 ]]; then
if is_package_manager_running; then
sudo apt install ${missing_dependencies[*]}
pkg_install ${missing_dependencies[*]}
fi
fi

Expand All @@ -45,8 +45,7 @@ function set_runtime_variables() {
if is_package_manager_running; then
sleep 3
fi
debconf-apt-progress -- apt-get update
debconf-apt-progress -- apt -y -qq --allow-downgrades --no-install-recommends install lsb-release
pkg_install --update --allow-downgrades --no-install-recommends lsb-release
fi

[[ -f /etc/armbian-release ]] && source /etc/armbian-release && ARMBIAN="Armbian $VERSION $IMAGE_TYPE"
Expand Down
4 changes: 2 additions & 2 deletions tools/modules/network/default_network_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ function default_network_config() {
# exceptions
if [[ "${NETWORK_RENDERER}" == "NetworkManager" ]]; then
# uninstall packages
apt_install_wrapper apt-get -y purge hostapd
pkg_remove hostapd
netplan apply
nmcli con down br0
else
# uninstall packages
apt_install_wrapper apt-get -y purge hostapd networkd-dispatcher
pkg_remove hostapd networkd-dispatcher
# drop and delete bridge interface in case its there
if [[ -n $(ip link show type bridge) ]]; then
ip link set br0 down >/dev/null 2>&1
Expand Down
16 changes: 8 additions & 8 deletions tools/modules/network/default_wireless_network_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ function default_wireless_network_config(){

# exceptions
if [[ "${NETWORK_RENDERER}" == "NetworkManager" ]]; then
# uninstall packages
apt_install_wrapper apt-get -y --no-install-recommends purge hostapd
systemctl restart NetworkManager
else
# uninstall packages
apt_install_wrapper apt-get -y --no-install-recommends purge hostapd networkd-dispatcher
brctl delif br0 $adapter 2> /dev/null
networkctl reconfigure br0
# uninstall packages
pkg_remove hostapd
systemctl restart NetworkManager
else
# uninstall packages
pkg_remove hostapd networkd-dispatcher
brctl delif br0 $adapter 2> /dev/null
networkctl reconfigure br0
fi

}
4 changes: 2 additions & 2 deletions tools/modules/network/module_nfsd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ function module_nfsd () {

case "$1" in
"${commands[0]}")
apt_install_wrapper apt-get -y install nfs-common nfs-kernel-server
pkg_install nfs-common nfs-kernel-server
# add some exports
${module_options["module_nfsd,feature"]} ${commands[2]}
systemctl restart nfs-server.service
;;
"${commands[1]}")
apt_install_wrapper apt-get -y autopurge nfs-kernel-server
pkg_remove nfs-kernel-server
;;
"${commands[2]}")
while true; do
Expand Down
2 changes: 1 addition & 1 deletion tools/modules/network/network_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function network_config() {
if [[ -f /etc/netplan/armbian.yaml && "$(netplan get bridges)" != "null" ]]; then
ip link set ${adapter} up
default_wireless_network_config "${yamlfile}" "${adapter}"
apt_install_wrapper apt-get -y --no-install-recommends install hostapd networkd-dispatcher bridge-utils
pkg_install --no-install-recommends hostapd networkd-dispatcher bridge-utils
SELECTED_SSID=$($DIALOG --title "Enter SSID for AP" --inputbox "\nHit enter for defaults" 9 50 "armbian" 3>&1 1>&2 2>&3)
if [[ -n "${SELECTED_SSID}" && $? == 0 ]]; then
SELECTED_PASSWORD=$($DIALOG --title "Enter new password for $SELECTED_SSID" --passwordbox "\nDefault password: 12345678\n" 9 50 "12345678" 3>&1 1>&2 2>&3)
Expand Down
4 changes: 2 additions & 2 deletions tools/modules/software/install_bazarr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function module_bazarr () {
local title="bazarr"
local condition=$(which "$title" 2>/dev/null)

if check_if_installed docker-ce; then
if pkg_installed docker-ce; then
local container=$(docker container ls -a | mawk '/bazarr?( |$)/{print $1}')
local image=$(docker image ls -a | mawk '/bazarr?( |$)/{print $3}')
fi
Expand All @@ -26,7 +26,7 @@ function module_bazarr () {

case "$1" in
"${commands[0]}")
check_if_installed docker-ce || install_docker
pkg_installed docker-ce || install_docker
[[ -d "$BAZARR_BASE" ]] || mkdir -p "$BAZARR_BASE" || { echo "Couldn't create storage directory: $BAZARR_BASE"; exit 1; }
docker run -d \
--name=bazarr \
Expand Down
4 changes: 2 additions & 2 deletions tools/modules/software/install_deluge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function module_deluge () {
local title="deluge"
local condition=$(which "$title" 2>/dev/null)

if check_if_installed docker-ce; then
if pkg_installed docker-ce; then
local container=$(docker container ls -a | mawk '/deluge?( |$)/{print $1}')
local image=$(docker image ls -a | mawk '/deluge?( |$)/{print $3}')
fi
Expand All @@ -26,7 +26,7 @@ function module_deluge () {

case "$1" in
"${commands[0]}")
check_if_installed docker-ce || install_docker
pkg_installed docker-ce || install_docker
[[ -d "$DELUGE_BASE" ]] || mkdir -p "$DELUGE_BASE" || { echo "Couldn't create storage directory: $DELUGE_BASE"; exit 1; }
docker run -d \
--name=deluge \
Expand Down
6 changes: 3 additions & 3 deletions tools/modules/software/install_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ install_docker() {
cat <<- EOF > "/etc/apt/sources.list.d/docker.list"
deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker.gpg] https://download.docker.com/linux/${DISTRO,,} $DISTROID stable
EOF
apt_install_wrapper apt-get update
pkg_update
# Install docker
if [ "$1" = "engine" ]; then
apt_install_wrapper apt-get -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
pkg_install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
else
apt_install_wrapper apt-get -y install docker-ce docker-ce-cli containerd.io
pkg_install docker-ce docker-ce-cli containerd.io
fi
systemctl enable docker.service > /dev/null 2>&1
systemctl enable containerd.service > /dev/null 2>&1
Expand Down
2 changes: 1 addition & 1 deletion tools/modules/software/install_embyserver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ install_embyserver() {
cd ~/
wget -O "emby-server.deb" $URL 2>&1 | stdbuf -oL awk '/[.] +[0-9][0-9]?[0-9]?%/ { print substr($0,63,3) }' |
$DIALOG --gauge "Please wait\nDownloading ${URL##*/}" 8 70 0
apt_install_wrapper apt-get -y install ~/emby-server.deb
pkg_install ~/emby-server.deb
unlink emby-server.deb
$DIALOG --msgbox "To test that Emby Server has installed successfully\nIn a web browser go to http://localhost:8096 or \nhttp://127.0.0.1:8096 on this computer." 9 70
}
Loading
Loading