Skip to content
Snippets Groups Projects
Commit f7a749bc authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

initial commit

parents
No related branches found
No related tags found
No related merge requests found
config.sh
# Snow Agent * Universität Bern
## Description
This is an installer for Linux.
* It extracts the debian 64 package
* Its files will be moved to /opt/snow/ and
* the pre install and post install script will be executed.
## Requirements
This installer uses
* Linux
* Bash
* unzip
* ar
* sudo permissions for current user
POC:
* The install file is in the local flder: `~/Downloads/SAM\ Agent.zip` (TODO: download with curl)
## Installation
```shell
git clone https://git-repo.iml.unibe.ch/iml-open-source/sam-agent.git
```
## Configuration
Create an initial config
```shell
cp config.sh.dist config.sh
```
In the config.sh you can make your changes
* Watch the PDF file and search for the correct sitename for your institution.
* Set your sitename in the line `SITENAME="unibe..."`
## Install
Start `./installer_samagent.sh`
# ----------------------------------------------------------------------
# CONFIG
# ----------------------------------------------------------------------
SITENAME=""
PLATFORM="amd64"
# source file in download folder
SOURCEZIP=~/Downloads/SAM\ Agent.zip
# temp dir to extract package before installing
EXTRACTDIR=/tmp/SAM_AGENT.tmp
# target dir
INSTALLDIR=/opt
URLSITENAMNE=https://sam.intern.unibe.ch/e1498122/e1502084/SiteName_Uebersicht.pdf
# ----------------------------------------------------------------------
#!/bin/bash
# ======================================================================
#
# LINUX INSTALLER :: UNIBE SAM AGENT
#
# License: GNU GPL 3.0
#
# ----------------------------------------------------------------------
# 2024-04-19 v0.1 <axel.hahn@unibe.ch>
# ======================================================================
_version="0.1"
# ----------------------------------------------------------------------
# FUNCTIONS
# ----------------------------------------------------------------------
# show headline for better readability
# param string text to show
function h2(){
echo
echo
echo -e ">>>>>>>>>>| $*"
}
# ----------------------------------------------------------------------
# MAIN
# ----------------------------------------------------------------------
echo "______________________________________________________________________
I N S T A L L E R * SAM AGENT v$_version
Institute for Medical Education
______________________________________________________________________
"
h2 "Read config"
. "$( dirname "$0" )/config.sh" || exit 1
if [ -z "$SITENAME" ]; then
echo "ERROR: missing SITENAME."
echo "See $URLSITENAMNE"
echo "to get the sitename for your department."
echo "Put it into the file config.sh behind SITENAME=..."
exit 1
fi
echo "Source file: $SOURCEZIP"
ls -l "$SOURCEZIP" || exit 1
h2 "Detect DEB package for ${PLATFORM} from $SOURCEZIP ..."
DEBFILE=$( unzip -l "$SOURCEZIP" "SAM Agent/*${PLATFORM}.deb" | grep -v "/._" | grep "${PLATFORM}" | rev | cut -f 1,2 -d " " | rev )
echo "Found debian file: $DEBFILE"
test -z "$DEBFILE" && echo "Debian Paket nicht gefunden. Paket korrupt oder Skript findet es nicht."
test -z "$DEBFILE" && exit 2
echo "OK"
echo
test -d "$EXTRACTDIR" || mkdir "$EXTRACTDIR"
cd "$EXTRACTDIR" || exit 3
echo "Switched to workdir to extract data:"
pwd
h2 "Extracting $DEBFILE from $SOURCEZIP ..."
unzip -o "$SOURCEZIP" -d . "$DEBFILE" || exit 4
echo "Result:"
ls -l "$DEBFILE" || exit 5
h2 "Extracting $DEBFILE to $( pwd ) ..."
ar x "$DEBFILE"
ls -l
h2 "Extracting control.tar.gz ..."
ls -l "control.tar.gz" || exit 4
tar -xzf "control.tar.gz"
h2 "Extracting data.tar.gz ..."
ls -l "data.tar.gz" || exit 5
tar -xzf "data.tar.gz"
subdirname=$( ls opt | tr -d '/' )
echo "Found subdir: opt/$subdirname"
h2 "Get version ..."
PKGVERSION=$( grep "^Version: " "control" | cut -f 2- -d " " )
SWVERSION=$( grep "^Version: " "$INSTALLDIR/$subdirname/control" | cut -f 2- -d " " )
echo "To install: $PKGVERSION"
echo "Installed : $SWVERSION"
if [ "$PKGVERSION" = "$SWVERSION" ]; then
echo
echo "SKIP: This version is installed already"
else
h2 "Get package name ..."
PKGNAME=$( grep "^Package: " "control" | cut -f 2- -d " " )
echo "Found: $PKGNAME"
h2 "Patching SITENAME --> $SITENAME ..."
ls -l opt/$subdirname/snowagent.config || exit 6
cp -pf opt/$subdirname/snowagent.config opt/$subdirname/snowagent.config__orig
sed -i "s#<SiteName>.*</SiteName>#<SiteName>$SITENAME</SiteName>#" opt/$subdirname/snowagent.config
diff opt/$subdirname/snowagent.config__orig opt/$subdirname/snowagent.config
h2 "Put files to opt ..."
test -d "$INSTALLDIR/$subdirname" && ( echo "Removing $INSTALLDIR/$subdirname"; sudo rm -rf "$INSTALLDIR/$subdirname" )
echo "Copy opt/$subdirname to $INSTALLDIR"
sudo cp -r "opt/$subdirname" "$INSTALLDIR" || exit 6
sudo cp "control" "$INSTALLDIR/$subdirname" || exit 6
h2 "Run debian scripts ..."
for myscript in preinst postinst # prerm postrm
do
echo "----- $myscript $PKGNAME"
sudo ./$myscript "$PKGNAME" || exit 7
done
fi
h2 "Cleanup ..."
echo "Deleting workdir $EXTRACTDIR ..."
# rm -rf "$EXTRACTDIR"
echo
echo "Done."
# ----------------------------------------------------------------------
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment