Skip to content

Commit

Permalink
Merge pull request DeskPi-Team#61 from boschkundendienst/manjaro_arch
Browse files Browse the repository at this point in the history
Manjaro arch
  • Loading branch information
yoyojacky authored Oct 13, 2021
2 parents dded904 + 54261e6 commit 0451aaf
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 51 deletions.
23 changes: 14 additions & 9 deletions Deskpi-uninstall
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
#!/bin/bash
if [ "$EUID" -ne 0 ]
then echo "Please run as root or with sudo"
exit
fi
# Uninstall script
. /lib/lsb/init-functions
. /usr/local/lib/deskpi-log-functions

# Stop deskpi.service.
sudo systemctl stop deskpi.service
sudo systemctl disable deskpi.service
systemctl stop deskpi.service
systemctl disable deskpi.service

# Define file locations
installation_dir="/home/pi/deskpi"
# Greetings and information for user.
log_action_msg "Welcome to Use DeskPi-Team's Product"
log_action_msg "Please select what distribution you have: "
log_action_msg "1 - Raspbian"
log_action_msg "2 - Manjaro"
log_action_msg "2 - Manjaro/Arch"
log_action_msg "3 - Ubuntu Mate"
log_action_msg "4 - Kali"
log_action_msg "5 - Cancel Uninstallation Process"
Expand All @@ -21,28 +26,28 @@ case $os_type in
1)
log_action_msg "Uninstalling DeskPi Utilitis"
bash $installation_dir/uninstall.sh
sudo sh -c "rm -f /etc/deskpi.conf"
sh -c "rm -f /etc/deskpi.conf"
;;
2)
log_action_msg "Uninstalling DeskPi Utilitis"
bash $installation_dir/uninstall-manjaro.sh
sudo sh -c "rm -f /etc/deskpi.conf"
sh -c "rm -f /etc/deskpi.conf"
;;
3)
log_action_msg "Uninstalling DeskPi Utilitis"
bash $installation_dir/uninstall-ubuntu-mate.sh
sudo sh -c "rm -f /etc/deskpi.conf"
sh -c "rm -f /etc/deskpi.conf"
;;
4)
log_action_msg "Uninstalling DeskPi Utilitis"
bash $installation_dir/uninstall-kali.sh
sudo sh -c "rm -f /etc/deskpi.conf"
sh -c "rm -f /etc/deskpi.conf"
;;
5)
log_action_msg "Uninstallation Canceled"
;;
*)
log_action_msg "Error selection please try again"
. /usr/bin/Deskpi-uninstall
. /usr/local/bin/Deskpi-uninstall
;;
esac
2 changes: 1 addition & 1 deletion deskpi-config
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# pwm_075 means sending 75% PWM signal to MCU. The fan will run at 75% speed level.
# pwm_100 means sending 100% PWM signal to MCU.The fan will run at 100% speed level.
#
. /lib/lsb/init-functions
. /usr/local/lib/deskpi-log-functions
# This is the serial port that connect to deskPi mainboard and it will
# communicate with Raspberry Pi and get the signal for fan speed adjusting.
serial_port='/dev/ttyUSB0'
Expand Down
119 changes: 84 additions & 35 deletions install-manjaro.sh
Original file line number Diff line number Diff line change
@@ -1,60 +1,109 @@
#!/bin/bash
#
if [ "$EUID" -ne 0 ]
then echo "Please run as root or with sudo"
exit
fi

# copy lib for functions used by deskpi-config
# to /usr/local/lib
if [ -f '/usr/local/lib/deskpi-log-functions' ] ; then
echo "local functions lib already present"
else
echo "copying functions library to /usr/local/lib/deskpi-local.lib"
cp ./log_functions.include '/usr/local/lib/deskpi-log-functions'
fi
# copy deskpi-config to usr local bin
echo "copying deskpi-config to /usr/local/bin"
cp ./deskpi-config /usr/local/bin/deskpi-config
# make deskpi-config executable
chmod +x /usr/local/bin/deskpi-config
# copy uninstalls cript to local bin
echo "copying uninstall-manjaro.sh to /usr/local/bin/Deskpi-uninstall"
cp ./uninstall-manjaro.sh /usr/local/bin/Deskpi-uninstall
chmod +x /usr/local/bin/Deskpi-uninstall

echo "DeskPi Driver Installing..."
if [ -d /tmp/deskpi ]; then
sudo rm -rf /tmp/deskpi 2&>/dev/null
rm -rf /tmp/deskpi 2&>/dev/null
fi
echo "Download the latest DeskPi Driver from GitHub..."
cd /tmp && git clone https://github.com/DeskPi-Team/deskpi.git

echo "DeskPi Driver Installation Start."
deskpiv1=/lib/systemd/system/systemd-deskpi-safecutoffpower.service
deskpi=/lib/systemd/system/deskpi.service
safeshutdaemon=/lib/systemd/system/deskpi-safeshut.service
driverfolder=/tmp/deskpi

# delete deskpi-safecutoffpower.service file.
if [ -e $deskpi ]; then
sudo sh -c "rm -f $deskpi"
sh -c "rm -f $deskpi"
fi

# adding dtoverlay to enable dwc2 on host mode.
echo "Configure /boot/config.txt file and enable front USB2.0"
sudo sed -i '/dtoverlay=dwc2*/d' /boot/config.txt
sudo sed -i '$a\dtoverlay=dwc2,dr_mode=host' /boot/config.txt
sudo sh -c "echo dwc2 > /etc/modules-load.d/raspberry.conf"
sed -i '/dtoverlay=dwc2*/d' /boot/config.txt
sed -i '$a\dtoverlay=dwc2,dr_mode=host' /boot/config.txt
sh -c "echo dwc2 > /etc/modules-load.d/raspberry.conf"

sudo cp -rf $driverfolder/drivers/c/safecutoffpower64 /usr/bin/safecutoffpower64
sudo cp -rf $driverfolder/drivers/python/safecutoffpower.py /usr/bin/safecutoffpower.py
sudo chmod 644 /usr/bin/safecutoffpower64
sudo chmod 644 /usr/bin/safecutoffpower.py
cp -rf $driverfolder/drivers/python/safecutoffpower.py /usr/bin/safecutoffpower.py
cp -rf $driverfolder/drivers/python/pwmControlFan.py /usr/bin/pwmControlFan.py
chmod 644 /usr/bin/safecutoffpower.py
chmod 644 /usr/bin/pwmControlFan.py

# send cut off power signal to MCU before system shuting down.
sudo echo "[Unit]" > $deskpi
sudo echo "Description=DeskPi Safe Cut-off Power Service" >> $deskpi
sudo echo "Conflicts=reboot.target" >> $deskpi
sudo echo "DefaultDependencies=no" >> $deskpi
sudo echo "" >> $deskpi
sudo echo "[Service]" >> $deskpi
sudo echo "Type=oneshot" >> $deskpi
sudo echo "ExecStart=/usr/bin/sudo /usr/bin/safecutoffpower64" >> $deskpi
sudo echo "# ExecStart=/usr/bin/sudo python3 /usr/bin/safecutoffpower.py" >> $deskpi
sudo echo "RemainAfterExit=yes" >> $deskpi
sudo echo "TimeoutStartSec=15" >> $deskpi
sudo echo "" >> $deskpi
sudo echo "[Install]" >> $deskpi
sudo echo "WantedBy=halt.target shutdown.target poweroff.target final.target" >> $deskpi

sudo chown root:root $deskpi
sudo chmod 644 $deskpi

sudo systemctl daemon-reload
sudo systemctl enable systemd-deskpiv1-safecutoffpower.service
echo "[Unit]" > $deskpi
echo "Description=DeskPi Safe Cut-off Power Service" >> $deskpi
echo "Conflicts=reboot.target" >> $deskpi
echo "DefaultDependencies=no" >> $deskpi
echo "" >> $deskpi
echo "[Service]" >> $deskpi
echo "#Type=oneshot" >> $deskpi
echo "Type=simple" >> $deskpi
echo "#ExecStart=/usr/bin//usr/bin/safecutoffpower64" >> $deskpi
echo "ExecStart=/usr/bin/python3 /usr/bin/safecutoffpower.py" >> $deskpi
echo "RemainAfterExit=true" >> $deskpi
echo "TimeoutStartSec=15" >> $deskpi
echo "" >> $deskpi
echo "[Install]" >> $deskpi
echo "WantedBy=halt.target shutdown.target poweroff.target final.target" >> $deskpi

chown root:root $deskpi
chmod 644 $deskpi

# send signal to MCU before system shuting down.
echo "[Unit]" > $safeshutdaemon
echo "Description=DeskPi Safeshutdown Service" >> $safeshutdaemon
echo "Conflicts=reboot.target" >> $safeshutdaemon
echo "Before=halt.target shutdown.target poweroff.target" >> $safeshutdaemon
echo "DefaultDependencies=no" >> $safeshutdaemon
echo "" >> $safeshutdaemon
echo "[Service]" >> $safeshutdaemon
echo 'Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/opt/vc/bin"'
echo "#Type=oneshot" >> $safeshutdaemon
echo "Type=simple" >> $safeshutdaemon
echo "ExecStart=/usr/bin/python3 /usr/bin/pwmControlFan.py" >> $safeshutdaemon
echo "RemainAfterExit=true" >> $safeshutdaemon
echo "TimeoutStartSec=15" >> $safeshutdaemon
echo "" >> $safeshutdaemon
echo "[Install]" >> $safeshutdaemon
echo "WantedBy=halt.target shutdown.target poweroff.target" >> $safeshutdaemon

chown root:root $safeshutdaemon
chmod 644 $safeshutdaemon


systemctl daemon-reload
systemctl enable deskpi.service
systemctl enable deskpi-safeshut.service

# install rpi.gpio for fan control
yes |sudo pacman -S python-pip
sudo pip3 install pyserial
# sudo pacman -S python python-pip base-devel
pacman -S --noconfirm python-pip
pip3 install pyserial
# pacman -S python python-pip base-devel
# env CFLAGS="-fcommon" pip install rpi.gpio

sync
sudo rm -rf /tmp/deskpi
rm -rf /tmp/deskpi
echo "DeskPi Driver installation successful, system will reboot in 5 seconds to take effect!"
sleep 5 && sudo reboot
#sleep 5 && reboot
36 changes: 36 additions & 0 deletions log_functions.include
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# functions needed for deskpi-config
# derived from https://www.apt-browse.org/browse/ubuntu/trusty/main/all/lsb-base/4.1+Debian11ubuntu6/file/lib/lsb/init-functions
#
#Copyright (c) 2002-08 Chris Lawrence
#All rights reserved.
#
#Redistribution and use in source and binary forms, with or without
#modification, are permitted provided that the following conditions
#are met:
#1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#3. Neither the name of the author nor the names of other contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
#THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
#IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
#WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
#ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
#LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
#CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
#SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
#BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
#WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
#OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
#EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
log_action_msg_pre () { :; }
log_action_msg_post () { :; }
log_action_msg () {
log_action_msg_pre "$@"
echo "$@." || true
log_action_msg_post "$@"
}
29 changes: 23 additions & 6 deletions uninstall-manjaro.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
#!/bin/bash
# uninstall deskpi script
#
if [ "$EUID" -ne 0 ]
then echo "Please run as root or with sudo"
exit
fi

deskpi=/lib/systemd/system/systemd-deskpi-safecutoffpower.service
deskpi=/lib/systemd/system/deskpi.service
safeshutdaemon=/lib/systemd/system/deskpi-safeshut.service
echo "DeskPi Driver Uninstalling..."
echo "Configure /boot/config.txt"
sudo sed -i '/dtoverlay=dwc2,dr_mode=host/d' /boot/config.txt
echo "Stop and disable DeskPi services"
sudo rm -f $deskpi 2&>/dev/null
sudo rm -f /usr/bin/safecutoffpower* 2&>/dev/null
sudo rm -rf /etc/modules-load.d/raspberry.conf 2&>/dev/null
sed -i '/dtoverlay=dwc2,dr_mode=host/d' /boot/config.txt
echo "Stop and disable DeskPi services"
systemctl stop deskpi.service
systemctl stop deskpi-safeshut.service
systemctl daemon-reload
rm -f "$deskpi" 2&>/dev/null
rm -f "$safeshutdaemon" 2&>/dev/null
rm -f /usr/bin/safecutoffpower* 2&>/dev/null
rm -f /usr/bin/pwmControlFan* 2&>/dev/null
rm -rf /etc/modules-load.d/raspberry.conf 2&>/dev/null
# remove Uninstall script itself
rm -f /usr/local/bin/Deskpi-uninstall
# remove deskpi-config
rm -f /usr/local/bin/deskpi-config
# remove log functions
rm -f '/usr/local/lib/deskpi-log-functions'
echo "Uninstall DeskPi Driver Successfully."

0 comments on commit 0451aaf

Please sign in to comment.