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

First steps with rpmifying the setup #323

Merged
merged 13 commits into from
Feb 15, 2021
38 changes: 21 additions & 17 deletions pengwin-setup
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

SetupDir="/usr/local/pengwin-setup.d"
SetupDir="/usr/share/pengwin-setup.d"

export VERSION="1.2a"

Expand All @@ -19,32 +19,33 @@ function check_upgrades() {
echo "Updating package database"

# shellcheck disable=SC2155
local debian_security_ok="$(cat /etc/apt/sources.list 2>&1 | grep -c "https://deb.debian.org/debian-security testing/updates")"
if [[ ${debian_security_ok} != 0 ]]; then
sudo sed -i 's$debian-security testing/updates$debian-security testing-security$g' /etc/apt/sources.list
fi
#local debian_security_ok="$(cat /etc/apt/sources.list 2>&1 | grep -c "https://deb.debian.org/debian-security testing/updates")"
#if [[ ${debian_security_ok} != 0 ]]; then
# sudo sed -i 's$debian-security testing/updates$debian-security testing-security$g' /etc/apt/sources.list
#fi

update_packages --allow-releaseinfo-change

# Check for .dist-upgrade file in /etc/apt and inform user dist-upgrade available if so
if [[ -f "/etc/apt/.dist-upgrade" ]]; then
echo "Distribution upgrade flag noticed! Alerting user"
if (confirm --title "Upgrade Available" --yesno "A distribution upgrade is available. In addition to regular package upgrades, this may also install / remove packages. Would you like to continue?\n\nTo run a non-automated distribution upgrade and see package changes, or to perform this in your own time, run 'sudo apt-get dist-upgrade'" 12 90); then
sudo rm /etc/apt/.dist-upgrade
sudo apt-get dist-upgrade -y
fi
fi
#if [[ -f "/etc/apt/.dist-upgrade" ]]; then
# echo "Distribution upgrade flag noticed! Alerting user"
# if (confirm --title "Upgrade Available" --yesno "A distribution upgrade is available. In addition to regular package upgrades, this may also install / remove packages. Would you like to continue?\n\nTo run a non-automated distribution upgrade and see package changes, or to perform this in your own time, run 'sudo apt-get dist-upgrade'" 12 90); then
# sudo rm /etc/apt/.dist-upgrade
# sudo apt-get dist-upgrade -y
# fi
#fi

# Check if there's any upgrades to pengwin-setup / pengwin-base
echo "Running upgrade check..."
# shellcheck disable=SC2155
local upgrd_check="$(sudo apt-get upgrade --show-upgraded --assume-no | grep pengwin)"
local upgrd_check="$(sudo dnf check-upgrade --show-upgraded --assume-no | grep pengwin)"
if [[ "${upgrd_check}" == *"pengwin"* ]]; then
echo "Pengwin core package upgrades found"
if (confirm --title "Upgrades Available" --yesno "Updates have been detected for Pengwin core packages. Would you like to update them? This is highly recommended. Note: Pengwin-setup will close after installation complete." 10 91); then

# Ensure that packages get updated without affecting other held packages like udev
sudo apt-mark unhold pengwin-base pengwin-setup >/dev/null 2>&1
# TODO: sudo apt-mark unhold pengwin-base pengwin-setup >/dev/null 2>&1
sudo dnf versionlock delete pengwin-setup pengwin-base >/dev/null 2>&1
upgrade_packages pengwin-base pengwin-setup
fi
elif [[ ${JUST_UPDATE} ]]; then
Expand Down Expand Up @@ -190,15 +191,18 @@ fi
# being updated while running other operations from pengwin-setup
# install menu
echo "Holding pengwin-base & pengwin-setup to ensure no changes while operating"
sudo apt-mark hold pengwin-base pengwin-setup >/dev/null 2>&1
# sudo apt-mark hold pengwin-base pengwin-setup >/dev/null 2>&1
sudo dnf versionlock add pengwin-base pengwin-setup >/dev/null 2>&1

sudo apt-mark unhold libc6 >/dev/null 2>&1
#sudo apt-mark unhold libc6 >/dev/null 2>&1
sudo dnf versionlock remove libc6 >/dev/null 2>&1

install_menu "$@"

# Unhold our packages
echo "Unholding pengwin-base & pengwin-setup"
sudo apt-mark unhold pengwin-base pengwin-setup >/dev/null 2>&1
#sudo apt-mark unhold pengwin-base pengwin-setup >/dev/null 2>&1
sudo dnf versionlock remove pengwin-base pengwin-setup >/dev/null 2>&1

ByeMessage
exit 0
14 changes: 7 additions & 7 deletions pengwin-setup.d/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ function cleantmp() {

function updateupgrade() {
echo "Applying available package upgrades from repositories."
sudo apt-get upgrade -y
sudo dnf upgrade -y
echo "Removing unnecessary packages."
sudo apt-get autoremove -y
sudo dnf autoremove -y
}

function command_check() {
Expand Down Expand Up @@ -215,7 +215,7 @@ function setup_env() {
export WIN_CUR_VER


SetupDir="/usr/local/pengwin-setup.d"
SetupDir="/usr/share/pengwin-setup.d"
export SetupDir

readonly GOVERSION="1.15.2"
Expand All @@ -225,21 +225,21 @@ function setup_env() {

function install_packages() {

sudo apt-get install -y -q "$@"
sudo dnf install -y -q "$@"
}

function update_packages() {

if [[ ${NON_INTERACTIVE} ]]; then
sudo apt-get update -y -q "$@"
sudo dnf update -y -q "$@"
else
sudo debconf-apt-progress -- apt-get update -y "$@"
sudo dnf update -y "$@"
fi
}

function upgrade_packages() {

sudo apt-get upgrade -y -q "$@"
sudo dnf upgrade -y -q "$@"
}

function add_fish_support() {
Expand Down
4 changes: 3 additions & 1 deletion pengwin-setup.d/guilib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ if (confirm --title "GUI Libraries" --yesno "Would you like to install a base se
eval "$(timeout 2s dbus-launch --auto-syntax)"

sudo tee "/etc/profile.d/dbus.sh" <<EOF
#!/bin/bash
#!/bin/sh

# Check if we have Windows Path
if ( which cmd.exe >/dev/null ); then
Expand All @@ -41,6 +41,8 @@ fi

EOF

add_fish_support 'dbus'

touch "${HOME}"/.should-restart

else
Expand Down
18 changes: 15 additions & 3 deletions pengwin-setup.d/java.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,25 @@ source "$(dirname "$0")/common.sh" "$@"
if (confirm --title "Java" --yesno "Would you like to Install SDKMan to manage and install Java SDKs?" 8 52); then

sudo apt-get install -y -q zip curl
echo "$ curl -s \"https://get.sdkman.io\" | bash"

curl -s "https://get.sdkman.io" | bash
curl -s "https://get.sdkman.io?rcupdate=false" | bash

sudo tee "/etc/profile.d/sdkman.sh" <<EOF
#!/bin/sh

export SDKMAN_DIR="\${HOME}/.sdkman"
if [ -s "\${HOME}/.sdkman/bin/sdkman-init.sh" ]; then

# shellcheck disable=SC1090
source "${HOME}/.sdkman/bin/sdkman-init.sh"
. "\${HOME}/.sdkman/bin/sdkman-init.sh"
fi

EOF

add_fish_support 'sdkman'

# shellcheck disable=SC1090
source "${HOME}/.sdkman/bin/sdkman-init.sh"
sdk version

curl https://raw.githubusercontent.com/Bash-it/bash-it/master/completion/available/sdkman.completion.bash | sudo tee /etc/bash_completion.d/sdkman.bash
Expand Down
3 changes: 3 additions & 0 deletions pengwin-setup.d/uninstall/java.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ function main() {
multiclean_file "$HOME/.profile"
multiclean_file "$HOME/.bash_profile"

sudo_rem_file "/etc/profile.d/sdkman.sh"
sudo_rem_file "/etc/fish/conf.d/sdkman.fish"

echo "Removing bash completion..."
sudo_rem_file "/etc/bash_completion.d/sdkman.bash"

Expand Down
6 changes: 3 additions & 3 deletions rpm/pengwin-setup.spec
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
Name: pengwin-setup
Summary: Setup tool for Pengwin
Version: 1.0.0
Release: 2%{?dist}
Release: 3%{?dist}
Source: %{name}-%{version}.tar.gz
BuildArch: noarch
Requires: wslu
Expand Down Expand Up @@ -67,5 +67,5 @@ echo "Type pengwin-setup to launch the Pengwin setup utility."
* Thu Feb 11 2021 Sascha Manns <sascha@whitewaterfoundry.com> - 1.0.0-2
Updated to follow the FHS

* Tue Feb 9 2021 Sascha Manns <sascha@whitewaterfoundry.com> - 1.0.0-1
Initial release of the Fedora package
* Tue Feb 9 2021 Sascha Manns <sascha@whitewaterfoundry> - 1.0.0-1
Initial release of the Fedora package
1 change: 1 addition & 0 deletions tests/ansible.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ function testUninstall() {
assertEquals "Ansible was not uninstalled" "1" "$?"
}

# shellcheck disable=SC1091
source shunit2
1 change: 1 addition & 0 deletions tests/brew.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ function testUninstall() {
assertEquals "Brew was not uninstalled" "0" "$(run_command_as_testuser brew --version | grep -c 'Homebrew 3')"
}

# shellcheck disable=SC1091
source shunit2
19 changes: 15 additions & 4 deletions tests/commons.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function oneTimeSetUp() {
export PATH="$(pwd)/stubs:${PATH}"
export HOME="/home/${TEST_USER}"
export TERM="xterm-256color"

sudo /usr/sbin/adduser --quiet --disabled-password --gecos '' ${TEST_USER}
sudo /usr/sbin/usermod -aG adm,cdrom,sudo,dip,plugdev ${TEST_USER}
echo "%${TEST_USER} ALL=(ALL) NOPASSWD:ALL" | sudo EDITOR='tee ' visudo --quiet --file=/etc/sudoers.d/passwordless-sudo
Expand All @@ -17,9 +17,10 @@ function oneTimeSetUp() {
sudo chmod 777 -R "${SHUNIT_TMPDIR}"

# Add the stub path
sudo echo "PATH=\"$(pwd)/stubs:\${PATH}\"" > /etc/profile.d/00-a.sh
sudo echo 'TERM="xterm-256color"' >> /etc/profile.d/00-a.sh


echo "PATH=\"$(pwd)/stubs:\${PATH}\"" | sudo tee /etc/profile.d/00-a.sh
echo 'TERM="xterm-256color"' | sudo tee -a /etc/profile.d/00-a.sh

export SHUNIT_TMPDIR
}

Expand Down Expand Up @@ -55,3 +56,13 @@ function run_pengwinsetup() {
function run_command_as_testuser() {
sudo su - -c "$*" ${TEST_USER}
}

function check_script() {
local installed_script="$1"

test -f "${installed_script}"
assertEquals "${installed_script} was not installed" "0" "$?"

shellcheck "${installed_script}"
assertEquals "shellcheck reported errors on ${installed_script}" "0" "$?"
}
1 change: 1 addition & 0 deletions tests/cpp-vs-clion_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ function testUninstall() {
fi
}

# shellcheck disable=SC1091
source shunit2
1 change: 1 addition & 0 deletions tests/dotnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ function testUninstall() {
assertEquals "NUGet was not uninstalled" "1" "$?"
}

# shellcheck disable=SC1091
source shunit2
1 change: 1 addition & 0 deletions tests/fish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ function testUninstall() {

}

# shellcheck disable=SC1091
source shunit2
1 change: 1 addition & 0 deletions tests/go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ function testUninstall() {

}

# shellcheck disable=SC1091
source shunit2
12 changes: 6 additions & 6 deletions tests/guilib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ function testMain() {
local dist="$(uname -m)"

run_pengwinsetup autoinstall GUI GUILIB

for i in 'xclip' 'gnome-themes-standard' 'gtk2-engines-murrine' 'dbus' 'dbus-x11' 'mesa-utils' 'libqt5core5a' 'binutils' 'libnss3' 'libegl1-mesa' ; do
package_installed $i
package_installed $i
assertTrue "package $i is not installed" "$?"
done

Expand Down Expand Up @@ -52,8 +52,7 @@ function testMain() {
#test -f /usr/share/dbus-1/session.conf
#assertEquals "/usr/share/dbus-1/session.conf was not installed" "0" "$?"

test -f /etc/profile.d/dbus.sh
assertEquals "/etc/profile.d/dbus.sh was not installed" "0" "$?"
check_script '/etc/profile.d/dbus.sh'
}

function testUninstall() {
Expand All @@ -64,7 +63,7 @@ function testUninstall() {
run_pengwinsetup autoinstall UNINSTALL GUILIB

for i in 'xclip' 'gnome-themes-standard' 'gtk2-engines-murrine' 'dbus-x11' ; do
package_installed $i
package_installed $i
assertFalse "package $i is not uninstalled" "$?"
done

Expand All @@ -89,7 +88,8 @@ function testUninstall() {
#assertEquals "/usr/share/dbus-1/session.conf was not installed" "1" "$?"

test -f /etc/profile.d/dbus.sh
assertEquals "/etc/profile.d/dbus.sh was not uninstalled" "1" "$?"
assertEquals "/etc/profile.d/dbus.sh was not uninstalled" "1" "$?"
}

# shellcheck disable=SC1091
source shunit2
1 change: 1 addition & 0 deletions tests/hidpi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ function testUninstall() {
assertFalse "FILE HIDPI" "$?"
}

# shellcheck disable=SC1091
source shunit2
22 changes: 22 additions & 0 deletions tests/java.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

source commons.sh

function testMain() {
run_pengwinsetup install PROGRAMMING JAVA

check_script '/etc/profile.d/sdkman.sh'

assertEquals "SDKMan was not installed" "1" "$(run_command_as_testuser sdk version | grep -c 'SDKMAN 5')"
}

function testUninstall() {
run_pengwinsetup uninstall JAVA

assertFalse "FILE PROFILE-SDKMAN" "[ -f /etc/profile.d/sdkman.sh ]"

assertEquals "SDKMan was not uninstalled" "0" "$(run_command_as_testuser sdk version | grep -c 'SDKMAN 5')"
}

# shellcheck disable=SC1091
source shunit2
1 change: 1 addition & 0 deletions tests/jetbrains-support.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ function copy_distribution_file() {
run_command_as_testuser "cp $CURRENT_FOLDER/template-wrong-value-wsl.distributions.xml $OPTIONS_FOLDER/$2"
}

# shellcheck disable=SC1091
source shunit2
1 change: 1 addition & 0 deletions tests/pythonpi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ function testUninstallPyEnv() {
assertEquals "Pyenv variables were not cleaned up" "0" "$(grep -c '^[^#]*\bPATH.*/.pyenv/bin' "${HOME}"/.bashrc)"
}

# shellcheck disable=SC1091
source shunit2
1 change: 1 addition & 0 deletions tests/rclocal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ function testUninstall() {
assertFalse "FILE SUDOERS-RCLOCAL" "[ -f /etc/sudoers.d/rclocal ]"
}

# shellcheck disable=SC1091
source shunit2
2 changes: 2 additions & 0 deletions tests/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ run_test ./update_pengwin.sh

if [ -z "${CIRCLE_NODE_TOTAL}" ]; then

run_test ./java.sh
run_test ./pythonpi.sh
run_test ./go.sh
run_test ./ansible.sh
Expand All @@ -21,6 +22,7 @@ if [ -z "${CIRCLE_NODE_TOTAL}" ]; then
run_test ./brew.sh
run_test ./guilib.sh
elif [[ ${CIRCLE_NODE_INDEX} == 0 ]]; then
run_test ./java.sh
run_test ./pythonpi.sh
elif [[ ${CIRCLE_NODE_INDEX} == 1 ]]; then
run_test ./fish.sh
Expand Down
1 change: 1 addition & 0 deletions tests/stubs/wslpath
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#! /bin/bash

# shellcheck source=./../mocks.sh
source "$(dirname "$0")/../mocks.sh" "$@"


Expand Down
1 change: 1 addition & 0 deletions tests/x410.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ function testUninstall() {
assertFalse "FILE PROFILE-X410" "[ -f /etc/profile.d/02-x410.sh ]"
}

# shellcheck disable=SC1091
source shunit2