Skip to content

Commit

Permalink
Update install script
Browse files Browse the repository at this point in the history
- Moved icon and launchers to setup.py
- Handle uninstalls better
- Drop venv
  • Loading branch information
rolandoislas committed Jun 2, 2017
1 parent c027f95 commit 3d5be23
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 127 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Expand Up @@ -8,7 +8,6 @@ sudo: required
install:
- sudo apt-get -qq update
- sudo ./install.sh local
- python setup.py install
before_script:
- export PYTHONPATH=$(pwd)
script: pytest
17 changes: 17 additions & 0 deletions drc-sim-backend.py → drc-sim-backend 100644 → 100755
@@ -1,3 +1,7 @@
#!/usr/bin/env python3
import os
import sys

from src.server.data import constants
from src.server.data.args import Args
from src.server.data.config_general import ConfigGeneral
Expand Down Expand Up @@ -68,6 +72,18 @@ def log_level():
LoggerWpa.warn("At this log level SSIDs are logged!")


def check_root():
"""
Exit if not root
:return:
"""
if os.getuid() != 0:
Logger.throw("Not running as root!")
sys.exit()
else:
Logger.extra("I am root!")


def main():
"""
Main entry point. Parses arguments, loads configuration files, initialized loggers and starts the main loop.
Expand All @@ -77,6 +93,7 @@ def main():
ConfigGeneral.load()
ConfigGeneral.save()
init_loggers()
check_root()
Logger.info("Initializing drc-sim-backend version %s", constants.VERSION)
Logger.info("Using \"%s\" as home folder.", constants.PATH_ROOT)
log_level()
Expand Down
107 changes: 55 additions & 52 deletions install.sh
Expand Up @@ -3,14 +3,22 @@
#
# drc-sim-backend install script
# https://github.com/rolandoislas/drc-sim
#
# Changelog
#
# June 1, 2017 - 1.1
# Add output on error for make, cmake, and setup.py
# Add setup.py outputs to install.txt during install and it is read from for an uninstall
# Move init script, desktop launcher, and icon to setup.py
# Add version number
# Add pkg-info - wpa_supplicant compile fails without it
# Remove virtualenv

VERSION="1.1"
REPO_DRC_SIM="https://github.com/rolandoislas/drc-sim.git"
REPO_WPA_SUPPLICANT_DRC="https://github.com/rolandoislas/drc-hostap.git"
REPO_DRC_SIM_C="https://github.com/rolandoislas/drc-sim-c.git"
INSTALL_DIR="/opt/drc_sim/"
PATH_APPLICATION_LAUNCHER="/usr/share/applications/drc-sim-backend.desktop"
PATH_ICON="/usr/share/icons/hicolor/512x512/apps/drcsimbackend.png"
PATH_INIT_SCRIPT="/usr/local/bin/drc-sim-backend"
dependencies=()
branch_drc_sim=""

Expand All @@ -24,7 +32,7 @@ check_os() {
"net-tools" "wireless-tools" "sysvinit-utils" "psmisc" "rfkill"
"isc-dhcp-client" "ifmetric" "python3-tk" "gksu")
# Wpa supplicant compile dependencies
dependencies+=("git" "libssl-dev" "libnl-genl-3-dev" "gcc" "make")
dependencies+=("git" "libssl-dev" "libnl-genl-3-dev" "gcc" "make" "pkg-config")
# DRC Sim Server C++
dependencies+=("libavcodec-dev" "libswscale-dev" "libjpeg-dev" "cmake")
else
Expand Down Expand Up @@ -120,7 +128,7 @@ compile_wpa() {
cp ../conf/wpa_supplicant.config ./.config &> /dev/null || return 1
compile_log="${compile_dir}make.log"
echo "Compile log at ${compile_log}"
make &> ${compile_log} || return 1
make &> ${compile_log} || (cat "${compile_log}"; return 1)
echo "Installing wpa_supplicant_drc and wpa_cli_drc to /usr/local/bin"
cp wpa_supplicant /usr/local/bin/wpa_supplicant_drc &> /dev/null || return 1
cp wpa_cli /usr/local/bin/wpa_cli_drc &> /dev/null || return 1
Expand All @@ -136,9 +144,10 @@ compile_drc_sim_c() {
cur_dir="${PWD}"
cd "${compile_dir}" &> /dev/null || return 1
compile_log="${compile_dir}make.log"
cmake_log="${compile_dir}cmake.log"
echo "Compile log at ${compile_log}"
cmake "$compile_dir" &> /dev/null || return 1
make &> ${compile_log} || return 1
cmake "$compile_dir" &> ${cmake_log} || (cat "${cmake_log}"; return 1)
make &> ${compile_log} || (cat "${compile_log}"; return 1)
echo "Installing drc_sim_c to /usr/local/bin"
make install &> /dev/null || return 1
cd "${cur_dir}" &> /dev/null || return 1
Expand All @@ -151,7 +160,6 @@ install_drc_sim() {
# Paths
drc_dir="${INSTALL_DIR}drc/"
cur_dir="${PWD}"
venv_dir="${INSTALL_DIR}venv_drc/"
# Get source
if [[ "${branch_drc_sim}" != "local" ]]; then
# Get repo
Expand All @@ -165,19 +173,12 @@ install_drc_sim() {
mkdir ${drc_dir} &> /dev/null || return 1
cp -R "${PWD}/." "${drc_dir%/*}" &> /dev/null || return 1
fi
# Install virtualenv
echo "Installing virtualenv"
python3 -m pip install virtualenv &> /dev/null || return 1
# Install python dependencies
echo "Installing setuptools"
python3 -m pip install setuptools &> /dev/null || return 1
# Create venv
echo "Creating virtualenv"
python3 -m virtualenv -p python3 "${venv_dir}" &> /dev/null || return 1
# Activate venv
echo "Activating virtualenv"
source "${venv_dir}bin/activate" || return 1
# Remove an existing install of drc-sim
echo "Attempting to remove previous installations"
pip uninstall -y drcsim &> /dev/null || \
python3 -m pip uninstall -y drcsim &> /dev/null || \
echo "Failed to remove the previous installation. Attempting to install anyway."
# Set the directory
cd "${drc_dir}" &> /dev/null || return 1
Expand All @@ -191,52 +192,56 @@ install_drc_sim() {
# Install
echo "Installing drc-sim"
echo "Downloading Python packages. This may take a while."
python3 -m pip install ./ &> /dev/null || return 1
python3 ./setup.py install --record "${drc_dir}/install.txt" &> "/tmp/drc-sim-py-install.log" || \
(cat "/tmp/drc-sim-py-install.log"; return 1)
cd "${cur_dir}" &> /dev/null || return 1
}

# Install the shell script that activates the venv and launches drc-sim with gksu
install_launch_script() {
echo "Installing launch script"
launch_script="${INSTALL_DIR}drc/resources/bin/drc-sim-backend.sh"
echo "Copying launch script from ${launch_script}"
cp ${launch_script} "${PATH_INIT_SCRIPT}" &> /dev/null || return 1
echo "Setting launch script executable"
chmod +x /usr/local/bin/drc-sim-backend &> /dev/null || return 1
}

# Install the desktop launcher
install_desktop_launcher() {
echo "Installing desktop launcher"
launcher="${INSTALL_DIR}drc/resources/bin/drc-sim-backend.desktop"
cp ${launcher} /usr/share/applications/ &> /dev/null || return 1
chmod +x "${PATH_APPLICATION_LAUNCHER}" &> /dev/null || return 1
echo "Installing icon"
icon="${INSTALL_DIR}drc/resources/image/icon.png"
cp ${icon} "${PATH_ICON}" &> /dev/null || echo "Failed to install icon"
# Update icon cache
update-icon-caches /usr/share/icons/* &> /dev/null || echo "Failed to update icon cache."
}

# Echos the general info
print_info() {
echo "Drc-sim installer"
echo " https://github.com/rolandoislas/drc-sim"
echo "Drc-sim installer (script version ${VERSION})"
printf "\thttps://github.com/rolandoislas/drc-sim\n"
}

# Uninstalls DRC Sim then exists
uninstall() {
drc_install_log="${INSTALL_DIR}drc/install.txt"
echo "Uninstalling DRC Sim Server"
# Remove setup.py files
if [[ -f "${drc_install_log}" ]]; then
echo "Files to remove:"
cat ${drc_install_log}
read -p "Remove these files? [Y/N]" reponse
if [[ ${reponse} =~ [Yy](es)* ]]; then
tr '\n' '\0' < ${drc_install_log} | xargs -0 sudo rm -f --
echo "Removed Python installed files"
else
echo "Not removing Python installed files"
echo "Install canceled"
exit 2
fi
else
cat ${drc_install_log}
echo "Could not clean Python installed files. Missing ${drc_install_log}"
fi
# Launcher (.desktop)
to_remove=("/usr/share/applications/drc-sim-backend.desktop" "/usr/share/applications/drcsimbackend.desktop"
"/usr/share/icons/hicolor/512x512/apps/drcsimbackend.png")
for item in "${to_remove[@]}"; do
if [[ -f "${item}" ]]; then
echo "Removing application launcher"
rm -f ${item} &> /dev/null
fi
done
# Install dir
echo "Removing install directory"
rm -rf ${INSTALL_DIR} &> /dev/null || echo "Failed to remove install directory."
echo "Removing application launcher"
rm -f ${PATH_APPLICATION_LAUNCHER} &> /dev/null || echo "Failed to remove application launcher"
echo "Removing icon"
rm -f ${PATH_ICON} &> /dev/null || echo "Failed to remove application icon"
echo "Removing init script"
rm -f ${PATH_INIT_SCRIPT} &> /dev/null || echo "Failed to remove init script"
# TODO uninstall packages
printf "\nNOT removing package dependencies\n"
printf "${dependencies[*]}\n\n"
# Done
echo "Uninstalled DRC Sim Server"
exit 0
}
Expand Down Expand Up @@ -278,7 +283,7 @@ pass_fail() {
# Echo post install message and exit
post_install() {
echo "Install finished"
echo "\"DRC SIM Server\" is now available in a GUI desktop applications menu if installed."
echo "\"DRC SIM Server\" will now appear in GUI application menus."
echo "It can also be launched via \"drc-sim-backend\"."
exit 0
}
Expand All @@ -288,9 +293,7 @@ install() {
install_dependencies
pass_fail compile_wpa "Compiled wpa_supplicant" "Failed to compile wpa_supplicant"
pass_fail compile_drc_sim_c "Compiled drc_sim_c" "Failed to compile drc_sim_c"
pass_fail install_drc_sim "Created virtualenv for drc-sim" "Failed to create virtualenv for drc-sim"
pass_fail install_launch_script "Launch script installed." "Failed to install launch script"
pass_fail install_desktop_launcher "Installed application launcher" "Failed to install desktop application launcher"
pass_fail install_drc_sim "Installed drc-sim" "Failed to install drc-sim"
post_install
}

Expand Down
30 changes: 0 additions & 30 deletions resources/bin/drc-sim-backend.sh

This file was deleted.

File renamed without changes.
22 changes: 0 additions & 22 deletions resources/command/na.json

This file was deleted.

File renamed without changes
50 changes: 35 additions & 15 deletions setup.py 100644 → 100755
@@ -1,27 +1,47 @@
#!/usr/bin/env python
#!/usr/bin/env python3

from distutils.core import setup
from distutils.core import setup, Command

from setuptools import find_packages

from src.server.data import constants


class CompileDrcSimC(Command):
pass # TODO compile drc_sim_c


class CompileWpaSupplicantDrc(Command):
pass # TODO compile wpa_supplicant_drc


setup(name='drcsim',
version=constants.VERSION,
description='Wii U gamepad simulator.',
install_requires=['netifaces==0.10.5', 'pexpect==4.2.1'],
install_requires=['netifaces>=0.10.5', 'pexpect>=4.2.1'],
packages=find_packages(),
include_package_data=True,
data_files=[('resources/config', ['resources/config/get_psk.conf']),
('resources/image', [
'resources/image/clover.gif',
'resources/image/diamond.gif',
'resources/image/heart.gif',
'resources/image/spade.gif',
'resources/image/icon.gif'
]),
('resources/command', [
'resources/command/na.json'
])],
scripts=['drc-sim-backend.py']
data_files=[
('resources/config', [
'resources/config/get_psk.conf'
]),
('resources/image', [
'resources/image/clover.gif',
'resources/image/diamond.gif',
'resources/image/heart.gif',
'resources/image/spade.gif',
'resources/image/icon.gif'
]),
('/usr/share/applications', [
'resources/bin/drcsimbackend.desktop'
]),
('/usr/share/icons/hicolor/512x512/apps', [
'resources/image/drcsimbackend.png'
])
],
scripts=['drc-sim-backend'],
cmdclass={
"compile_drc_sim_c": CompileDrcSimC,
"compile_wpa_supplicant_drc": CompileWpaSupplicantDrc
}
)

0 comments on commit 3d5be23

Please sign in to comment.