Skip to content
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
3 changes: 3 additions & 0 deletions bin/bin/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions bin/bin/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions bin/bin/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions bin/bin/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash

# Operating System present in local Machine
if command -v lsb_release &> /dev/null
then
distro=$(lsb_release -si)
else
distro=$(uname -s)
fi

echo "Detected Operating System: $distro"

# Install some Pre-requisite Packages
case $distro in
Debian|Ubuntu|Linux\ Mint|Kubuntu|Lubuntu|Xubuntu|Pop\!_OS|Elementary\ OS|Zorin\ OS|Kali\ Linux|MX\ Linux)
sudo apt install dos2unix;;
RHEL|CentOS|Fedora|OpenSUSE|SUSE\ Linux\ Enterprise)
sudo rpm -i dos2unix;;
Arch|Manjaro|Endeavour\ OS)
sudo pacman -S dos2unix;;
Alpine)
sudo apk add dos2unix;;
Gentoo|Funtoo)
sudo emerge dos2unix;;
Slackware)
sudo slackpkg install dos2unix;;
NixOS)
nix-env -i dos2unix;;
Darwin)
brew install dos2unix;;
*)
echo "Unsupported Operating System"
exit 1;;
esac

echo "Installed dos2unix for $distro"

echo "Line Encoding from CRLF To LF"
find . -type f -print0 | parallel -0 'grep -Iql $'\r' {} && dos2unix {}'

if [[ "$distro" == "Darwin" ]]; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi

for script in ./utils/*.sh; do
if [[ -x "$script" ]]; then
echo "Running $script..."
"$script"
else
echo "$script is not executable."
fi
done
44 changes: 44 additions & 0 deletions bin/bin/utils/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

## Options parsing and setup
OPTS=$(getopt -o h --long delete-conffiles,delete-database,delete-repository,delete-user,delete-everything,help -n 'fo-cleanold' -- "$@")

if [ $? != 0 ]; then
echo "ERROR: Bad option specified."
OPTS="--help"
fi

eval set -- "$OPTS"

while true; do
case "$1" in
--delete-conffiles) RMCONF=1; shift;;
--delete-database) RMDB=1; shift;;
--delete-repository) RMREPO=1; shift;;
--delete-user) RMUSER=1; shift;;
--delete-everything) EVERYTHING=1; shift;;
-h|--help)
echo "Usage: fo_clean.sh [options]"
echo " --delete-conffiles : delete configuration files"
echo " --delete-database : delete database"
echo " --delete-repository : delete repository"
echo " --delete-user : delete user and group"
echo " --delete-everything : delete everything"
exit;;
--) shift; break;;
*) echo "Error: option $1 not recognised"; exit 1;;
esac
done

if [ $EVERYTHING ]; then
echo "*** Deleting everything ***"
./utils/fo_clean/fo_clear.sh
else
# Run deletions in parallel where possible to save time
[ $RMCONF ] && ./utils/fo_clean/fo_config.sh &
[ $RMDB ] && ./utils/fo_clean/fo_db.sh &
[ $RMREPO ] && ./utils/fo_clean/fo_repo.sh &
[ $RMUSER ] && ./utils/fo_clean/fo_user.sh &

wait
fi
75 changes: 75 additions & 0 deletions bin/bin/utils/deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/env bash

source "$(dirname "${BASH_SOURCE[0]}")/fo_deps/utils.sh"

show_help() {
cat <<EOF
Usage: install.sh [options]
-r or --runtime : install runtime dependencies
-b or --buildtime : install buildtime dependencies
-e or --everything : install all dependencies (default)
-o or --offline : do not run composer installation
-y : Automatic yes to prompts
-h or --help : this help text
EOF
}

YesOpt=''
OFFLINE=''
EVERYTHING=''
RUNTIME=''
BUILDTIME=''

OPTS=$(getopt -o rbeohy --long runtime,buildtime,everything,offline,help -n 'install.sh' -- "$@")

if [[ $? -ne 0 ]]; then
OPTS="--help"
fi

eval set -- "$OPTS"

if [[ $OPTS == ' --' || $OPTS == ' -y --' ]]; then
EVERYTHING=true
fi

while true; do
case "$1" in
-r|--runtime) RUNTIME=true; shift;;
-b|--buildtime) BUILDTIME=true; shift;;
-e|--everything) EVERYTHING=true; shift;;
-o|--offline) OFFLINE=true; shift;;
-y) YesOpt='-y'; shift;;
-h|--help) show_help; exit;;
--) shift; break;;
*) echo "ERROR: option $1 not recognised"; exit 1;;
esac
done

set -o errexit -o nounset -o pipefail

must_run_as_root
need_lsb_release

if [[ $EVERYTHING ]]; then
echo "*** Installing both runtime and buildtime dependencies ***"
RUNTIME=true
BUILDTIME=true
fi

if [[ $BUILDTIME ]]; then
echo "*** Calling fo_buildtime.sh to install buildtime dependencies ***"
./fo_deps/fo_buildtime.sh "$YesOpt" &
fi

if [[ $RUNTIME ]]; then
echo "*** Calling fo_runtime.sh to install runtime dependencies ***"
./fo_deps/fo_runtime.sh "$YesOpt" &
fi

wait

# Install composer if not in offline mode
if [[ ! $OFFLINE ]]; then
echo "*** Installing composer dependencies ***"
./fo_deps/fo_composer.sh
fi
8 changes: 8 additions & 0 deletions bin/bin/utils/fo_clean/fo_clear.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

./utils/fo_clean/fo_config.sh &
./utils/fo_clean/fo_db.sh &
./utils/fo_clean/fo_repo.sh &
./utils/fo_clean/fo_user.sh &

wait
31 changes: 31 additions & 0 deletions bin/bin/utils/fo_clean/fo_config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

TMPDIR=$(mktemp -d /tmp/fossology-configs.XXXXXX) || exit 1

# Old config files to clean up
OLDSAVE="/usr/local/share/fossology/agents/proxy.conf ... "
NEWSAVE="/etc/cron.d/fossology ... "

echo "*** Searching for old fossology config files ***"
for conffile in $OLDSAVE; do
if [ -e "$conffile" -o -L "$conffile" ]; then
echo "NOTE: found old $conffile saving to $TMPDIR/ and deleting"
cp "$conffile" "$TMPDIR/"
rm -f "$conffile"
fi
done

echo "*** Searching for new fossology config files ***"
for conffile in $NEWSAVE; do
if [ -f "$conffile" -o -L "$conffile" ]; then
path=$(dirname "$conffile")
destpath="$TMPDIR/$path"
mkdir -p "$destpath"
echo "NOTE: found $conffile saving to $destpath/ and deleting as requested"
mv "$conffile" "$destpath/"
fi
done

if [ -d /usr/local/etc/fossology ]; then
rm -rf /usr/local/etc/fossology
fi
15 changes: 15 additions & 0 deletions bin/bin/utils/fo_clean/fo_db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

if ! su postgres -c 'psql -l' &> /dev/null; then
echo "ERROR: postgresql isn't running, not deleting database"
exit 1
fi

if su postgres -c 'psql -l' | grep -q fossology; then
echo "*** Deleting database ***"
pkill -f -u postgres fossy || true
su postgres -c 'drop database fossology'
[ $? != 0 ] && echo "ERROR: failed to delete database" && exit 1
else
echo "NOTE: fossology database does not exist, not deleting"
fi
9 changes: 9 additions & 0 deletions bin/bin/utils/fo_clean/fo_repo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

if [ -d /srv/fossology/repository ]; then
echo "*** Deleting repository ***"
rm -rf /srv/fossology
[ $? != 0 ] && echo "ERROR: failed to delete repository" && exit 1
else
echo "NOTE: repository does not exist, not deleting"
fi
14 changes: 14 additions & 0 deletions bin/bin/utils/fo_clean/fo_user.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

echo "*** Deleting user and group ***"
if grep -q "^fossy:" /etc/passwd; then
userdel -r fossy && echo "User fossy deleted." || echo "ERROR: failed to delete user"
else
echo "User fossy does not exist."
fi

if grep -q "^fossy:" /etc/group; then
groupdel fossy && echo "Group fossy deleted." || echo "ERROR: failed to delete group"
else
echo "Group fossy does not exist."
fi
67 changes: 67 additions & 0 deletions bin/bin/utils/fo_deps/fo_buildtime.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env bash

YesOpt=$1

DISTRO=$(lsb_release --id --short)
CODENAME=$(lsb_release --codename --short)

echo "*** Installing $DISTRO buildtime dependencies ***"
case "$DISTRO" in
Debian|Ubuntu|Linux\ Mint|Pop\!_OS|Elementary\ OS|Zorin\ OS)
apt-get update
apt-get $YesOpt install --no-install-recommends \
libjsoncpp-dev libboost-system-dev libboost-filesystem-dev \
libmxml-dev curl libxml2-dev libcunit1-dev libicu-dev \
build-essential libtext-template-perl subversion rpm librpm-dev \
libmagic-dev libglib2.0 libboost-regex-dev libzstd-dev \
libboost-program-options-dev libpq-dev composer patch devscripts \
libdistro-info-perl libcppunit-dev libomp-dev cmake ninja-build \
libgcrypt20-dev libcrypt-dev librpm-dev libglib2.0-dev
;;
Fedora|RHEL|CentOS|Rocky|AlmaLinux)
yum $YesOpt groupinstall "Development Tools"
yum $YesOpt install perl-Text-Template subversion postgresql-devel file-devel \
jsoncpp-devel boost-devel libxml2 libicu-devel libpq-devel patch \
libomp-devel cmake ninja-build libgcrypt-devel rpm-devel glib2-devel
;;
Arch|Manjaro|Endeavour\ OS)
pacman -Sy --noconfirm base-devel jsoncpp boost curl libxml2 cunit icu \
boost-libs postgresql cmake ninja libgcrypt glib2
;;
Alpine)
apk add build-base jsoncpp-dev boost-dev libmxml-dev curl libxml2-dev \
libcunit-dev libicu-dev postgresql-dev cmake ninja libgcrypt-dev glib-dev
;;
Darwin)
brew install jsoncpp boost libmxml curl libxml2 cunit icu4c postgresql cmake \
ninja libgcrypt glib
;;
*)
echo "ERROR: Unsupported distribution $DISTRO"
exit 1
;;
esac

# Free Space of Disk
case "$DISTRO" in
Debian|Ubuntu|Linux\ Mint|Pop\!_OS|Elementary\ OS|Zorin\ OS)
apt-get clean
apt-get autoremove -y
;;
Fedora|RHEL|CentOS|Rocky|AlmaLinux)
yum clean all
;;
Arch|Manjaro|Endeavour\ OS)
pacman -Scc --noconfirm
;;
Alpine)
apk cache clean
;;
Darwin)
brew cleanup
;;
*)
echo "WARNING: No cleanup procedure defined for $DISTRO"
;;
esac

23 changes: 23 additions & 0 deletions bin/bin/utils/fo_deps/fo_composer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

# Skip composer installation, if offline mode is enabled
if [ "$OFFLINE" = true ]; then
echo "Offline mode enabled. Skipping composer installation."
exit 0
fi

if ! command -v composer &> /dev/null; then
echo "*** Installing Composer ***"

if [[ "$OSTYPE" == "darwin"* ]]; then
brew install composer
else
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
fi
fi

echo "*** Running composer install ***"
composer install --no-dev

# Free up Disk Space
composer clear-cache
Loading