Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Commit

Permalink
consistency in check syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
snwh committed May 21, 2018
1 parent d5e3365 commit 0f4a5b6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
10 changes: 6 additions & 4 deletions functions/add_repositories
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
#!/bin/bash

# Add Flatpak Repo
# ${1} = remote, ${2} = https://remote.example.com/
function add_flatpak_repo() {
echo_message header "Starting 'add_flatpak_repo' function"
# Check if already added
flatpak remotes | grep $1 &> /dev/null
flatpak remotes | grep ${1} &> /dev/null
# If repo is added
if [ $? = 0 ]; then
echo_message info "Repository already added."
whiptail --msgbox "The $1 repository is already added." 8 56
whiptail --msgbox "The ${1} repository is already added." 8 56
else
# Add repository
echo_message info "Adding flatpak repository..."
flatpak remote-add --if-not-exists $1 $2
flatpak remote-add --if-not-exists ${1} ${2}
echo_message success "Repository added."
whiptail --title "Finished" --msgbox "The '$1' repository has been added." 8 56
whiptail --title "Finished" --msgbox "The '${1}' repository has been added." 8 56
fi
}

# Add Launchpad PPA
# ${1} = Name, ${2} = launchpad-user/ppa-name
function add_launchpad_ppa() {
echo_message header "Starting 'add_launchpad_ppa' function"
# Check if PPA already added
Expand Down
16 changes: 9 additions & 7 deletions functions/check_functions
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ function check_package_installed() {
}

# Check if single package is installed
# ${1} = package, ${2} = return_function
function check_package() {
# echo_message header "Starting 'check_package' function"
# if package is not installed
if [ $(check_package_installed $PACKAGE) != 0 ]; then
if [ $(check_package_installed ${1}) != 0 ]; then
# draw window
if (whiptail \
--title "Install ${1}" \
Expand All @@ -19,37 +20,38 @@ function check_package() {
echo_message info "Installing '${3}'..."
elevate_privilege "apt install -y ${1}"
# Finished
echo_message success "$1 is installation complete."
echo_message success "${1} is installation complete."
whiptail --title "Finished" --msgbox "Installation of ${1} Flatpak complete." 8 64
$2
${2}
else
# Cancelled
echo_message info "Installation of ${1} cancelled."
$2
${2}
fi
else
echo_message info "Function dependency '${1}' is installed."
fi
}

# Check for Flatpak repository
# ${1} = remote, ${2} = https://remote.example.com/, ${3} = return_function
function check_flatpak_repo {
# echo_message header "Starting 'check_flatpak_repo' function"
# If repo not is added
if [ $(flatpak remotes | grep $1 &> /dev/null; echo $?) = 1 ]; then
if [ $(flatpak remotes | grep ${1} &> /dev/null; echo $?) = 1 ]; then
# draw window
if (whiptail \
--title "Add ${1} Repository" \
--yesno "This function requires '${1^}' repository but it is not present on your system. \n\nWould you like to add it to continue? " 10 64) then
# Add repository
echo_message info "Adding flatpak repository..."
flatpak remote-add --if-not-exists $1 $2
flatpak remote-add --if-not-exists ${1} ${2}
echo_message success "Repository added."
whiptail --title "Finished" --msgbox "The ${1^} repository has been added." 8 56
else
# Cancelled
echo_message info "Addition of ${1^} repository cancelled."
$3
${3}
fi
else
echo_message info "${1^} repository already added."
Expand Down
2 changes: 1 addition & 1 deletion functions/install_flatpak_apps
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function install_flathub_app() {
# check if flathub repo is added
check_flatpak_repo "flathub" "https://flathub.org/repo/flathub.flatpakrepo" install_flatpak_apps
#install_flatpak_package "Name" "remote" "com.package.Name" return_function
install_flatpak_package $1 "flathub" $2 install_flatpak_apps
install_flatpak_package ${1} "flathub" ${2} install_flatpak_apps
}

# Install Flatpak Applications
Expand Down

0 comments on commit 0f4a5b6

Please sign in to comment.