Skip to content

Commit

Permalink
Move system file install into setup.py
Browse files Browse the repository at this point in the history
The installation of system files has been moved into the 'install' command
instead of running unconditionally.  This makes it possible to create a source code
distribution of that doesn't immediately clobber the build machine's system files.
This will also allow the image build to be simplified as it will only need to copy the
sdist archive instead of multiple directories worth of files.

Signed-off-by: llamasoft <llamasoft@rm-rf.email>
  • Loading branch information
llamasoft committed Oct 3, 2022
1 parent ea827a4 commit 3af03cb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 20 deletions.
3 changes: 2 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
exclude *.pyc .DS_Store .gitignore MANIFEST.in
include requirements.txt
include setup.py
include distribute_setup.py
include README.md
include LICENSE
recursive-include bin *
recursive-include builder/data *
recursive-include pwnagotchi *.py
recursive-include pwnagotchi *.yml
recursive-include pwnagotchi *.*
51 changes: 32 additions & 19 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from setuptools import setup, find_packages
from distutils.util import strtobool
import os
from setuptools.command.install import install
import glob
import shutil
import logging
import os
import re
import shutil
import warnings

log = logging.getLogger(__name__)

def install_file(source_filename, dest_filename):
# do not overwrite network configuration if it exists already
# https://github.com/evilsocket/pwnagotchi/issues/483
if dest_filename.startswith('/etc/network/interfaces.d/') and os.path.exists(dest_filename):
print("%s exists, skipping ..." % dest_filename)
log.info(f"{dest_filename} exists, skipping ...")
return

print("installing %s to %s ..." % (source_filename, dest_filename))
try:
dest_folder = os.path.dirname(dest_filename)
if not os.path.isdir(dest_folder):
os.makedirs(dest_folder)
log.info(f"installing {source_filename} to {dest_filename} ...")
dest_folder = os.path.dirname(dest_filename)
if not os.path.isdir(dest_folder):
os.makedirs(dest_folder)

shutil.copyfile(source_filename, dest_filename)
except Exception as e:
print("error installing %s: %s" % (source_filename, e))
shutil.copyfile(source_filename, dest_filename)
if dest_filename.startswith("/usr/bin/"):
os.chmod(dest_filename, 0o755)


def install_system_files():
Expand All @@ -35,15 +37,27 @@ def install_system_files():
dest_filename = source_filename.replace(data_path, '')
install_file(source_filename, dest_filename)


def restart_services():
# reload systemd units
os.system("systemctl daemon-reload")


def installer():
install_system_files()
# for people updating https://github.com/evilsocket/pwnagotchi/pull/551/files
os.system("systemctl enable fstrim.timer")


class CustomInstall(install):
def run(self):
super().run()
if os.geteuid() != 0:
warnings.warn(
"Not running as root, can't install pwnagotchi system files!"
)
return
install_system_files()
restart_services()


def version(version_file):
with open(version_file, 'rt') as vf:
version_file_content = vf.read()
Expand All @@ -54,10 +68,6 @@ def version(version_file):

return None


if strtobool(os.environ.get("PWNAGOTCHI_ENABLE_INSTALLER", "1")):
installer()

with open('requirements.txt') as fp:
required = [line.strip() for line in fp if line.strip() != ""]

Expand All @@ -72,6 +82,9 @@ def version(version_file):
url='https://pwnagotchi.ai/',
license='GPL',
install_requires=required,
cmdclass={
"install": CustomInstall,
},
scripts=['bin/pwnagotchi'],
package_data={'pwnagotchi': ['defaults.yml', 'pwnagotchi/defaults.yml', 'locale/*/LC_MESSAGES/*.mo']},
include_package_data=True,
Expand Down

0 comments on commit 3af03cb

Please sign in to comment.