Skip to content

Commit

Permalink
Format everything
Browse files Browse the repository at this point in the history
  • Loading branch information
Geczy committed Nov 24, 2019
1 parent 5d0d566 commit 669141e
Show file tree
Hide file tree
Showing 22 changed files with 571 additions and 561 deletions.
38 changes: 19 additions & 19 deletions src/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,27 @@ export accountUserToSaveToCar="yourUsername"
export accountPassToSaveToCar="myCarIsRooted"

scheduledScripts=(
"$homeOfLunars/scripts/everyBoot/memory-logs.sh"
"$homeOfLunars/scripts/everyBoot/mount-modfiles.sh"
"$homeOfLunars/scripts/everyBoot/open-diag-port.sh"
"$homeOfLunars/scripts/everyBoot/create-accounts.sh"
# "$homeOfLunars/scripts/everyBoot/block-tesla-ssh.sh"
# "$homeOfLunars/scripts/everyBoot/freedomevstart.sh"
# "$homeOfLunars/scripts/everyBoot/wake-bench.sh"
# "$homeOfLunars/scripts/everyBoot/listen-for-code.sh"
# "$homeOfLunars/scripts/everyBoot/reverse-tunnel.sh"
# "$homeOfLunars/scripts/everyBoot/vpn-over-cell.sh"
"$homeOfLunars/scripts/everyBoot/memory-logs.sh"
"$homeOfLunars/scripts/everyBoot/mount-modfiles.sh"
"$homeOfLunars/scripts/everyBoot/open-diag-port.sh"
"$homeOfLunars/scripts/everyBoot/create-accounts.sh"
# "$homeOfLunars/scripts/everyBoot/block-tesla-ssh.sh"
# "$homeOfLunars/scripts/everyBoot/freedomevstart.sh"
# "$homeOfLunars/scripts/everyBoot/wake-bench.sh"
# "$homeOfLunars/scripts/everyBoot/listen-for-code.sh"
# "$homeOfLunars/scripts/everyBoot/reverse-tunnel.sh"
# "$homeOfLunars/scripts/everyBoot/vpn-over-cell.sh"
)

everyFiveMinuteScripts=(
"$homeOfLunars/scripts/everyFiveMinutes/open-wifi.sh"
"$homeOfLunars/scripts/everyFiveMinutes/startstopvpn.sh"
"$homeOfLunars/scripts/everyFiveMinutes/tokens-to-php.sh"
"$homeOfLunars/scripts/everyFiveMinutes/vitals-to-php.sh"
"$homeOfLunars/scripts/everyFiveMinutes/open-wifi.sh"
"$homeOfLunars/scripts/everyFiveMinutes/startstopvpn.sh"
"$homeOfLunars/scripts/everyFiveMinutes/tokens-to-php.sh"
"$homeOfLunars/scripts/everyFiveMinutes/vitals-to-php.sh"

# "$homeOfLunars/scripts/everyFiveMinutes/add-swblock.sh"
# "$homeOfLunars/scripts/everyFiveMinutes/copy-tokens-to-ic.sh"
# "$homeOfLunars/scripts/everyFiveMinutes/eggwot.sh"
# "$homeOfLunars/scripts/everyFiveMinutes/save-key-over-ssh.sh"
# "$homeOfLunars/scripts/everyFiveMinutes/add-swblock.sh"
# "$homeOfLunars/scripts/everyFiveMinutes/copy-tokens-to-ic.sh"
# "$homeOfLunars/scripts/everyFiveMinutes/eggwot.sh"
# "$homeOfLunars/scripts/everyFiveMinutes/save-key-over-ssh.sh"

)
)
80 changes: 40 additions & 40 deletions src/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ echo "Installing Lunars to $homeOfLunars"

# Detect if we are running chrooted by checking if the root of the init process is the same as the root of this process
if [[ "$(stat -c %d:%i /)" != "$(stat -c %d:%i /proc/1/root/.)" ]]; then
echo "[FAIL] Not running chrooted"
exit 2
echo "[FAIL] Not running chrooted"
exit 2
fi

echo "[OK] Not running chrooted"
Expand All @@ -23,61 +23,61 @@ onRebootFile="$homeOfLunars/scripts/$rebootScript"
startScript="/sbin/start-stop-daemon --start --quiet --make-pidfile --oknodo --background --pidfile /var/run/lunars-main.pid --exec /bin/bash $onRebootFile"

function downloadLunars() {
echo "Downloading lunars source from Github..."

mkdir -p "$homeOfLunars"
curl -s -L https://github.com/Lunars/tesla/tarball/master | tar --wildcards -zx -C "$homeOfLunars" "Lunars-tesla-*/src"
mv "$homeOfLunars"/*/src/* "$homeOfLunars"
rm -rf "$homeOfLunars"/Lunars-tesla-*

echo "[OK] Lunars source downloaded"

if [[ -f /tmp/config.sh ]]; then
# Restore config from tmp
mv /tmp/overwrite-files "$homeOfLunars"
mv /tmp/config.sh "$homeOfLunars"
mv /tmp/tesla.ovpn "$homeOfLunars"
echo "[OK] Lunars config.sh, tesla.ovpn, and overwrite-files restored"
fi
echo "Downloading lunars source from Github..."

mkdir -p "$homeOfLunars"
curl -s -L https://github.com/Lunars/tesla/tarball/master | tar --wildcards -zx -C "$homeOfLunars" "Lunars-tesla-*/src"
mv "$homeOfLunars"/*/src/* "$homeOfLunars"
rm -rf "$homeOfLunars"/Lunars-tesla-*

echo "[OK] Lunars source downloaded"

if [[ -f /tmp/config.sh ]]; then
# Restore config from tmp
mv /tmp/overwrite-files "$homeOfLunars"
mv /tmp/config.sh "$homeOfLunars"
mv /tmp/tesla.ovpn "$homeOfLunars"
echo "[OK] Lunars config.sh, tesla.ovpn, and overwrite-files restored"
fi
}

if [[ -f "$onRebootFile" ]]; then
# Save config to tmp
mv "$homeOfLunars"/overwrite-files /tmp
mv "$homeOfLunars"/config.sh /tmp
mv "$homeOfLunars"/tesla.ovpn /tmp
echo "[OK] Lunars config.sh, tesla.ovpn, and overwrite-files saved"

rm -rf "$homeOfLunars"
downloadLunars
# Save config to tmp
mv "$homeOfLunars"/overwrite-files /tmp
mv "$homeOfLunars"/config.sh /tmp
mv "$homeOfLunars"/tesla.ovpn /tmp
echo "[OK] Lunars config.sh, tesla.ovpn, and overwrite-files saved"

rm -rf "$homeOfLunars"
downloadLunars
else
downloadLunars
downloadLunars

# In case a custom install path was given, replace it in config.sh too
[ -n "$search" ] && sed -i "s~$search~$homeOfLunars~g" "$homeOfLunars/config.sh"
# In case a custom install path was given, replace it in config.sh too
[ -n "$search" ] && sed -i "s~$search~$homeOfLunars~g" "$homeOfLunars/config.sh"
fi

# Installing crontab
alreadyInstalled=$(crontab -l | grep "$rebootScript")
if [[ "$alreadyInstalled" != "" ]]; then
echo "[SKIP] Lunars cron already installed"
echo "[SKIP] Lunars cron already installed"
else
# Just in case this file already exists
rm /tmp/crontab 2>/dev/null
crontab -l >/tmp/crontab
echo "@reboot $startScript" >>/tmp/crontab
crontab </tmp/crontab || exit 6
rm /tmp/crontab
echo "[OK] Lunars cron installed"
# Just in case this file already exists
rm /tmp/crontab 2>/dev/null
crontab -l >/tmp/crontab
echo "@reboot $startScript" >>/tmp/crontab
crontab </tmp/crontab || exit 6
rm /tmp/crontab
echo "[OK] Lunars cron installed"
fi

# Check if already running
rebootProcess=$(pgrep -f "$rebootScript")
if [ -n "$rebootProcess" ]; then
echo "[SKIP] Lunars $rebootScript is already running"
echo "[SKIP] Lunars $rebootScript is already running"
else
$startScript
echo "[OK] Lunars $rebootScript backgrounded"
$startScript
echo "[OK] Lunars $rebootScript backgrounded"
fi

echo "[DONE] Lunars is now installed, have fun!"
35 changes: 13 additions & 22 deletions src/save-tokens.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
<?php

// Usage: file.php?s1=FirstToken&s2=SecondToken&car=YourCarName
class TeslaKeys

{
var $filename = '.tesla_tokens.json';

function __construct()
{
if (!file_exists($this->filename))
{
if (!file_exists($this->filename)) {
$fh = fopen($this->filename, 'w') or die("Can't create file");
}

if (empty($_GET['s1']) || empty($_GET['s2']))
{
if (empty($_GET['s1']) || empty($_GET['s2'])) {
$this->showLastKey();
}
else
{
} else {
$this->saveKeys();
}
}
Expand All @@ -25,19 +23,15 @@ function showLastKey()
{
$str_data = file_get_contents($this->filename);
$decoded = json_decode($str_data);
if (!empty($_GET['car']))
{
$decoded->tokens = array_filter((array)$decoded->tokens, function ($v)
{
if (!empty($_GET['car'])) {
$decoded->tokens = array_filter((array)$decoded->tokens, function ($v) {
return $v->car === $_GET['car'];
});
}

if (!empty($decoded))
{
if (!empty($decoded)) {
$last = end($decoded->tokens);
if ($last)
{
if ($last) {
$last->saved_date = date('Y-m-d G:i', $last->saved_date);
}

Expand All @@ -55,17 +49,14 @@ function saveKeys()
if (empty($decoded['tokens'])) $decoded['tokens'] = [];

// Remove duplicate tokens, in case the cron runs often
$decoded['tokens'] = array_filter($decoded['tokens'], function ($v)
{
$decoded['tokens'] = array_filter($decoded['tokens'], function ($v) {
return $v['tesla1'] != $_GET['s1'] && $v['tesla2'] != $_GET['s2'];
});
$newTokens = ['tesla1' => $_GET['s1'], 'tesla2' => $_GET['s2'], 'saved_date' => strtotime('now') ];
if (!empty($_GET['car']))
{
$newTokens = ['tesla1' => $_GET['s1'], 'tesla2' => $_GET['s2'], 'saved_date' => strtotime('now')];
if (!empty($_GET['car'])) {
$newTokens['car'] = $_GET['car'];
}
if (!empty($_GET['unlock_token']))
{
if (!empty($_GET['unlock_token'])) {
$newTokens['unlock_token'] = $_GET['unlock_token'];
}

Expand Down
96 changes: 48 additions & 48 deletions src/scripts/everyBoot/freedomevstart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,87 +12,87 @@

#check if freedomev was already detected
if [[ -f /tmp/freedomevmountpoint ]]; then
freedomevstarted=true
usbmountpoint=$(cat /tmp/freedomevmountpoint)
freedomevstarted=true
usbmountpoint=$(cat /tmp/freedomevmountpoint)
else
freedomevstarted=false
freedomevstarted=false
fi

#possibly check if there are no double mounts or dangling mountpoints

#function to kill remaining freedomev chrooted processes and umount
function killandumount() {
#run all deactivation scripts
for deactivationscript in /tmp/freedomev/*; do
bash ${deactivationscript} && rm ${deactivationscript}
done
#umount filesystems
umount ${usbmountpoint}/proc/
umount ${usbmountpoint}/sys
umount ${usbmountpoint}/dev
umount ${usbmountpoint}/tmp
umount ${usbmountpoint}/dev/pts
umount -f ${usbmountpoint}
rm /tmp/freedomevmountpoint
#check if no mount points are dangling
#run all deactivation scripts
for deactivationscript in /tmp/freedomev/*; do
bash ${deactivationscript} && rm ${deactivationscript}
done
#umount filesystems
umount ${usbmountpoint}/proc/
umount ${usbmountpoint}/sys
umount ${usbmountpoint}/dev
umount ${usbmountpoint}/tmp
umount ${usbmountpoint}/dev/pts
umount -f ${usbmountpoint}
rm /tmp/freedomevmountpoint
#check if no mount points are dangling
}

#check if the USB stick is present
usbstickpresent=$(cat /proc/partitions | grep sd[a-z]1$)
if [[ ${usbstickpresent} == "" ]]; then
if ! ${freedomevstarted}; then
#we want to end as quickly as possible if we don't need to do anything
#possibly we need to check if we need to kill some processes or umount bind mounted stuff
#for now, one can also reboot after removing the stick
exit 0
else
#we need to kill all possible processes who run on the removed rootfs from the USB stick and possibly umount
killandumount
fi
if ! ${freedomevstarted}; then
#we want to end as quickly as possible if we don't need to do anything
#possibly we need to check if we need to kill some processes or umount bind mounted stuff
#for now, one can also reboot after removing the stick
exit 0
else
#we need to kill all possible processes who run on the removed rootfs from the USB stick and possibly umount
killandumount
fi
fi

#determine mountpoint - should not be emty
usbmountpoint=$(mount | grep '^/dev/sd' | awk '{ print $3 }' | head -n 1)
if [[ ${usbmountpoint} == "" ]]; then
exit 3
exit 3
else
echo ${usbmountpoint} >/tmp/freedomevmountpoint
echo ${usbmountpoint} >/tmp/freedomevmountpoint
fi

#check if it's mounted read-only, possibly remount - otherwise exit, maybe still busy mounting, will try again next run
usbstickmounted=$(mount | grep '^/dev/sd.1.*(ro,noexec,nodev,noatime)$')
if [[ ${usbstickmounted} != "" ]]; then
mount -o remount,rw,exec,dev /dev/sd?1 || exit 2
mount -o remount,rw,exec,dev /dev/sd?1 || exit 2
fi

#check if it contains the correct content and determine the version
freedomevversion=$(cat ${usbmountpoint}/etc/freedomevversion)
if [[ ${freedomevversion} == "" ]]; then
echo no ${usbmountpoint}/etc/freedomevversion
if ${freedomevstarted}; then
killandumount
fi
exit 4
echo no ${usbmountpoint}/etc/freedomevversion
if ${freedomevstarted}; then
killandumount
fi
exit 4
fi
echo freedomevstarted=${freedomevstarted}

#initial start
if ! ${freedomevstarted}; then
echo ${usbmountpoint} >/tmp/freedomevmountpoint
mount -t proc archproc ${usbmountpoint}/proc/
mount -t sysfs archsys ${usbmountpoint}/sys
mount -o bind /dev ${usbmountpoint}/dev
mount -o bind /tmp ${usbmountpoint}/tmp
mount -t devpts archdevpts ${usbmountpoint}/dev/pts
#I prefer not to put the key in the public git so we cp it to /tmp
mkdir /tmp/freedomev/ 2>/dev/null
cp /root/.ssh/id_dsa /tmp/freedomev/id_dsa
#some more hacking powers
mount /var -o remount,exec
mount -o remount,exec /opt/navigoff
export usbmountpoint
/bin/bash ${usbmountpoint}/freedomev/tools/activation-outside-chroot-jail
/usr/sbin/chroot ${usbmountpoint} /bin/bash /freedomev/tools/activation
echo ${usbmountpoint} >/tmp/freedomevmountpoint
mount -t proc archproc ${usbmountpoint}/proc/
mount -t sysfs archsys ${usbmountpoint}/sys
mount -o bind /dev ${usbmountpoint}/dev
mount -o bind /tmp ${usbmountpoint}/tmp
mount -t devpts archdevpts ${usbmountpoint}/dev/pts
#I prefer not to put the key in the public git so we cp it to /tmp
mkdir /tmp/freedomev/ 2>/dev/null
cp /root/.ssh/id_dsa /tmp/freedomev/id_dsa
#some more hacking powers
mount /var -o remount,exec
mount -o remount,exec /opt/navigoff
export usbmountpoint
/bin/bash ${usbmountpoint}/freedomev/tools/activation-outside-chroot-jail
/usr/sbin/chroot ${usbmountpoint} /bin/bash /freedomev/tools/activation
fi

#launch the checks for freedomev core such as periodic check for version and periodic checks for certain apps
Expand Down
Loading

0 comments on commit 669141e

Please sign in to comment.