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

Adding install definition for /opt #25

Merged
Merged
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
52 changes: 37 additions & 15 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@
#
# Author: @ivanleoncz

# ---------------------------------------------------------------------------
# Attention
# ---------------------------------------------------------------------------
# These variables are used in two locations:
# 1. Here.
# 2. gen_config_files.py
#
# Leave them as it is, specially GEN_CALLER, unless you have a good reason.
# ---------------------------------------------------------------------------
export USER="pycaptive"
export CONF_DIR="/etc/pycaptive"
export INSTALL_DIR="/opt/pycaptive"
export GEN_CALLER="install.sh"

help () {
basename $0
Expand All @@ -15,26 +28,35 @@ help () {
}

install () {
PYCAPTIVE_ETC="/etc/pycaptive"
echo "[INFO]: creating pycaptive user"
/usr/bin/sudo /usr/sbin/useradd pycaptive -s /usr/sbin/nologin
echo "[INFO]: creating ${PYCAPTIVE_ETC} directory"
/bin/mkdir /etc/pycaptive
echo "[INFO]: installing pycaptive.ini to ${PYCAPTIVE_ETC} directory"
/usr/bin/install -m 664 -o pycaptive -g pycaptive app/pycaptive.ini /etc/pycaptive
echo "[INFO]: defining owner of ${PYCAPTIVE_ETC} directory"
/bin/chown pycaptive:pycaptive ${PYCAPTIVE_ETC}
echo "[INFO]: defining permission of ${PYCAPTIVE_ETC} directory"
/bin/chmod 775 ${PYCAPTIVE_ETC}
echo "[INFO]: creating ${USER} user"
/usr/bin/sudo /usr/sbin/useradd ${USER} -s /usr/sbin/nologin
echo "[INFO]: creating ${CONF_DIR} directory"
/bin/mkdir ${CONF_DIR}
echo "[INFO]: installing pycaptive.ini to ${CONF_DIR} directory"
/usr/bin/install -m 664 -o ${USER} -g ${USER} app/pycaptive.ini ${CONF_DIR}
echo "[INFO]: defining ${USER} as owner of ${CONF_DIR} directory"
/bin/chown ${USER}:${USER} ${CONF_DIR}
echo "[INFO]: defining permissions of ${CONF_DIR} directory"
/bin/chmod 775 ${CONF_DIR}
echo "[INFO]: installing repo files at ${INSTALL_DIR} directory"
/usr/bin/rsync -a . ${INSTALL_DIR} --exclude .git --exclude .gitignore
echo "[INFO]: defining ${USER} as owner of ${INSTALL_DIR} directory"
/bin/chown -R ${USER}:${USER} ${INSTALL_DIR}
echo "[INFO]: defining permissions on ${INSTALL_DIR} directory"
/usr/bin/find ${INSTALL_DIR} -type d -exec chmod 775 {} \;
/usr/bin/find ${INSTALL_DIR} -type f \( -name "*.py" -o -name "*.sh" \) -exec chmod 554 {} \;
echo "[INFO]: generating configuration files for services, based on gen_templates files"
python3 gen_config_files.py
}


uninstall () {
PYCAPTIVE_ETC="/etc/pycaptive"
echo "[INFO]: deleting ${PYCAPTIVE_ETC} directory and its contents"
/bin/rm -rf /etc/pycaptive
echo "[INFO]: deleting ${CONF_DIR} directory and its contents"
/bin/rm -rf ${CONF_DIR}
echo "[INFO]: deleting ${INSTALL_DIR} directory and its contents"
/bin/rm -rf ${INSTALL_DIR}
echo "[INFO]: deleting pycaptive user"
/usr/sbin/userdel pycaptive
/usr/sbin/userdel ${USER}
}

if [[ "$UID" == 0 ]]; then
Expand Down