Category:Sharedops

From campisano.org
Jump to navigation Jump to search

Shared ops template

Useful template/script to install third part software in an alternative way (shared, reusable for update, not editable by running users, fixing permissions and removing suid)

  • first, ensure to define a custom path, for instance /opt/software or, in this example, /home/shared/opt/software (to use the same filesystem partition used by /home)
mkdir -m 0755 /home/shared
mkdir -m 0775 /home/shared/downloads /home/shared/network
mkdir -m 0750 /home/shared/audio /home/shared/documents /home/shared/graphics /home/shared/opt /home/shared/video
mkdir -m 0750 /home/shared/opt/bin /home/shared/opt/etc /home/shared/opt/scripts /home/shared/opt/software
chown -R root:users /home/shared/
chown <USER>:users /home/shared/opt/*
usermod -a -G users <USER>
  • then, you can use/adapt the follow template for your install scripts
# shared/opt install schema v1.5.6

#### as common user ####
# define applications vars
export SOFTWARE_PATH="</home/shared/opt/software>"              # to customize
export NAME="<SOFTWARE-NAME>"                                   # to customize
export VERSION="<X.Y.Z>"                                        # to customize
export URL="<DOWNLOAD_URL/FILE_${VERSION}.EXT>"                 # to customize
su - -w SOFTWARE_PATH,NAME,VERSION

#### as root ####
# install packages and prepare destination path
apt-get -q -y install wget coreutils findutils < /dev/null
apt-get -q -y install <OTHER_PACKAGES> < /dev/null              # to customize
mkdir -m 777 "${SOFTWARE_PATH}/tmp_install/" "${SOFTWARE_PATH}/${NAME}_${VERSION}/"
exit

#### as common user ####
umask 0027
cd "${SOFTWARE_PATH}/tmp_install"
wget -c --no-check-certificate "${URL}"
<EXTRACT> <FILE_${VERSION}.EXT>                                 # to customize
cd <FOLDER>                                                     # to customize
# define compiler flags optimizations (from debian dpkg-buildflags command)
export CFLAGS="-g0 -O2 -fstack-protector-strong -Wformat -Werror=format-security -mtune=native -pipe"
export LDFLAGS="-s -Wl,-z,relro"
# configure, build and install
./configure --prefix="${SOFTWARE_PATH}/${NAME}_${VERSION}"      # to customize
make -s
make install
cd
su - -w SOFTWARE_PATH,NAME,VERSION

#### as root ####
# ensure permissions to destination path
cd "${SOFTWARE_PATH}"
chown -R root:users "${NAME}_${VERSION}"
find "${NAME}_${VERSION}" -type d -exec chmod a-s,u+rwx,g+rx,g-w,o-rwx {} \;
find "${NAME}_${VERSION}" -type f -exec chmod a-s,u+rw,g+r,g-w,o-rwx {} \;
rm -rf tmp_install
ln -s -f -T "${NAME}_${VERSION}" "${NAME}"
exit

#### as common user ####
# test the application (you can put the follow in ~/.profile)
export SOFTWARE_PATH="</home/shared/opt/software>"              # to customize
export <NAME_HOME>="${SOFTWARE_PATH}/<NAME>"                    # to customize
export PATH="${PATH}:${NAME_HOME}/bin"                          # to customize
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${NAME_HOME}/lib"    # to customize
<NAME> --version                                                # to customize