Skip to content

Commit

Permalink
feat: Add installation and uninstallation scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
selengalp committed Feb 6, 2023
1 parent c27c5d1 commit 6e7741a
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
57 changes: 57 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash

# Check if we are root
if [ $(id -u) -ne 0 ]; then
echo "Please run as root"
exit 1
fi

# Check installation by checking .orig files
if [ -f /etc/dhcpcd.conf.orig ]; then
echo "Already installed. Please uninstall first."
exit 1
fi

# if ./ap_config_files or ./client_config_files exists, then exit with error
if [ -d ./ap_config_files ] || [ -d ./client_config_files ]; then
echo "Already installed. Please uninstall first."
exit 1
fi


# Give execution permissions to scripts
chmod +x ./switch_client_mode.sh
chmod +x ./switch_ap_mode.sh

# Install dependencies
apt-get update
apt-get install -y hostapd dnsmasq

# Disable services as default
systemctl unmask hostapd
systemctl disable hostapd dnsmasq
systemctl stop hostapd dnsmasq

# Get the current configs from the system
cp /etc/dhcpcd.conf /etc/dhcpcd.conf.orig
cp /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
cp /etc/hosts /etc/hosts.orig

mkdir client_config_files
cp /etc/dhcpcd.conf.orig ./client_config_files/dhcpcd.conf
cp /etc/dnsmasq.conf.orig ./client_config_files/dnsmasq.conf
cp /etc/hosts.orig ./client_config_files/hosts
touch ./client_config_files/wpa_supplicant-wlan0.conf

mkdir ap_config_files
cp /etc/dhcpcd.conf.orig ./ap_config_files/dhcpcd.conf
cp /etc/dnsmasq.conf.orig ./ap_config_files/dnsmasq.conf
touch ./ap_config_files/hostapd.conf
cp /etc/hosts.orig ./ap_config_files/hosts

# Add confgurations for AP mode to the files
cat ./source_configs/dhcpcd.conf >> ./ap_config_files/dhcpcd.conf
cat ./source_configs/dnsmasq.conf >> ./ap_config_files/dnsmasq.conf
cat ./source_configs/hostapd.conf >> ./ap_config_files/hostapd.conf
cat ./source_configs/hosts >> ./ap_config_files/hosts
cat ./source_configs/wpa_supplicant-wlan0.conf >> ./client_config_files/wpa_supplicant-wlan0.conf
23 changes: 23 additions & 0 deletions uninstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# Check if we are root
if [ $(id -u) -ne 0 ]; then
echo "Please run as root"
exit 1
fi

# Return original configs
mv /etc/dhcpcd.conf.orig /etc/dhcpcd.conf
mv /etc/hosts.orig /etc/hosts
mv /etc/dnsmasq.conf.orig /etc/dnsmasq.conf

# Remove services
systemctl stop hostapd dnsmasq
systemctl disable hostapd dnsmasq
apt purge hostapd dnsmasq -y

# Remove config files
rm -rf /etc/hostapd/hostapd.conf
rm -rf /etc/dnsmasq.conf
rm -rf ./ap_config_files
rm -rf ./client_config_files

0 comments on commit 6e7741a

Please sign in to comment.