Skip to content

Commit

Permalink
Upload scripts for manual install
Browse files Browse the repository at this point in the history
  • Loading branch information
ihrapsa committed Jul 10, 2021
1 parent edd361a commit 08734c2
Show file tree
Hide file tree
Showing 2 changed files with 375 additions and 0 deletions.
70 changes: 70 additions & 0 deletions scripts/1_format_extroot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/sh

echo " "
echo "This script will format your sd card and make it extroot"
echo " "
echo " ###################################################"
echo " ## Make sure you've got a microSD card plugged! ##"
echo " ###################################################"
echo " "
read -p "Press [ENTER] to continue...or [ctrl+c] to exit"

format(){
while true; do
read -p "This script will format your sdcard. Are you sure about this? [y/n]: " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done

umount /dev/mmcblk0p1;

yes | mkfs.ext4 /dev/mmcblk0p1;

}

extroot(){
echo " "
sleep 1
echo -ne 'Making extroot... [=> ](6%)\r'
DEVICE="$(sed -n -e "/\s\/overlay\s.*$/s///p" /etc/mtab)";
echo -ne 'Making extroot... [===> ](12%)\r'
uci -q delete fstab.rwm;
echo -ne 'Making extroot... [=====> ](18%)\r'
uci set fstab.rwm="mount";
echo -ne 'Making extroot... [=======> ](25%)\r'
uci set fstab.rwm.device="${DEVICE}";
echo -ne 'Making extroot... [=========> ](31%)\r'
uci set fstab.rwm.target="/rwm";
echo -ne 'Making extroot... [===========> ](37%)\r'
uci commit fstab;
echo -ne 'Making extroot... [=============> ](43%)\r'
DEVICE="/dev/mmcblk0p1";
echo -ne 'Making extroot... [===============> ](50%)\r'
eval $(block info "${DEVICE}" | grep -o -e "UUID=\S*");
echo -ne 'Making extroot... [=================> ](56%)\r'
uci -q delete fstab.overlay;
echo -ne 'Making extroot... [===================> ](62%)\r'
uci set fstab.overlay="mount";
echo -ne 'Making extroot... [=====================> ](68%)\r'
uci set fstab.overlay.uuid="${UUID}";
echo -ne 'Making extroot... [=======================> ](75%)\r'
uci set fstab.overlay.target="/overlay";
echo -ne 'Making extroot... [=========================> ](81%)\r'
uci commit fstab;
echo -ne 'Making extroot... [===========================> ](87%)\r'
mount /dev/mmcblk0p1 /mnt;
echo -ne 'Making extroot... [=============================> ](93%)\r'
cp -f -a /overlay/. /mnt;
echo -ne 'Making extroot... [===============================> ](98%)\r'
umount /mnt;
echo -ne 'Making extroot... [=================================>](100%)\r'
echo -ne '\n'

echo "Please reboot then run the second script!";
}

format;
extroot;
305 changes: 305 additions & 0 deletions scripts/2_script_manual.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,305 @@
#!/bin/sh

echo " "
echo " ################################################"
echo " ## Did you execute 1_format_extroot.sh first? ##"
echo " ################################################"
echo " "
read -p "Press [ENTER] if YES ...or [ctrl+c] to exit"


echo " "
echo "This script will download and install all packages form the internet"
echo " "
echo " #####################################"
echo " ## Make sure extroot is enabled... ##"
echo " #####################################"
echo " "
read -p "Press [ENTER] to check if extroot is enabled ...or [ctrl+c] to exit"

df -h;

echo " "
echo " #####################################"
echo " ## OK? ##"
echo " #####################################"
echo " "
read -p "Press [ENTER] to Continue ...or [ctrl+c] to exit"

echo " "
echo " ########################################################"
echo " ## Make sure you've got a stable Internet connection! ##"
echo " ########################################################"
echo " "
read -p "Press [ENTER] to Continue ...or [ctrl+c] to exit"

echo "Creating swap file"
dd if=/dev/zero of=/overlay/swap.page bs=1M count=512;
echo "Enabling swap file"
mkswap /overlay/swap.page;
swapon /overlay/swap.page;
mount -o remount,size=256M /tmp;

echo "Updating rc.local for swap"
rm /etc/rc.local;
cat << "EOF" > /etc/rc.local
# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.
###activate the swap file on the SD card
swapon /overlay/swap.page
###expand /tmp space
mount -o remount,size=256M /tmp
exit 0
EOF

echo "Installing dependencies..."
opkg update && opkg install git-http unzip htop zram-swap gcc;


echo "Changing distfeeds for python2..."
mv /etc/opkg/distfeeds.conf /etc/opkg/distfeeds.conf_orig;
cat << "EOF" > /etc/opkg/distfeeds.conf
src/gz openwrt_core https://downloads.openwrt.org/releases/19.07.7/targets/ramips/mt76x8/packages
src/gz openwrt_base https://downloads.openwrt.org/releases/19.07.7/packages/mipsel_24kc/base
src/gz openwrt_luci https://downloads.openwrt.org/releases/19.07.7/packages/mipsel_24kc/luci
src/gz openwrt_packages https://downloads.openwrt.org/releases/19.07.7/packages/mipsel_24kc/packages
src/gz openwrt_routing https://downloads.openwrt.org/releases/19.07.7/packages/mipsel_24kc/routing
src/gz openwrt_telephony https://downloads.openwrt.org/releases/19.07.7/packages/mipsel_24kc/telephony
EOF

mv /etc/opkg.conf /etc/opkg.conf_orig;

cat << "EOF" > /etc/opkg.conf
dest root /
dest ram /tmp
lists_dir ext /var/opkg-lists
option overlay_root /overlay
#option check_signature
EOF

opkg update;
opkg install python python-pip python-cffi python-dev gcc;

echo "Cloning 250k baud pyserial"
git clone https://github.com/ihrapsa/pyserial /root/pyserial;
cd /root/pyserial
python /root/pyserial/setup.py install;
cd /root/
rm -rf /root/pyserial;

echo "Installing pip2 packages..."
pip install greenlet==0.4.15 jinja2 python-can==3.3.4;


echo "Switching to original distfeeds..."
mv /etc/opkg/distfeeds.conf /etc/opkg/distfeeds.conf_v19;
mv /etc/opkg/distfeeds.conf_orig /etc/opkg/distfeeds.conf;
rm /etc/opkg.conf;
mv /etc/opkg.conf_orig /etc/opkg.conf;

echo "Updating original distfeeds..."
opkg update;
echo "Installing python3 packages..."
opkg install python3 python3-pip python3-pyserial python3-pillow python3-tornado python3-distro libsodium --force-overwrite;

echo "Cloning setuptools..."
git clone https://github.com/pypa/setuptools.git /root/setuptools;
echo "Installing setuptools..."

cd /root/setuptools;
python3 /root/setuptools/setup.py install;
rm -rf /root/setuptools;
cd /root/

echo "Installing pip3 packages..."
pip3 install inotify-simple python-jose libnacl paho-mqtt==1.5.1;


echo "Downloading lmdb and streaming-form-data package..."

wget https://github.com/ihrapsa/KlipperWrt/raw/main/packages/python3-lmdb%2Bstreaming-form-data_packages_1.0-1_mipsel_24kc.ipk -P /root/;

echo "Installing lmdb and streaming-form-data package..."
opkg install /root/*ipk;
rm -rf *ipk;

echo "Installing nginx..."
opkg install nginx-ssl;

###############
### Klipper ###
###############
echo "Cloning Klipper..."
git clone https://github.com/KevinOConnor/klipper.git /root/klipper;

echo "Creating klipper service..."
wget https://raw.githubusercontent.com/ihrapsa/KlipperWrt/main/Services/klipper -P /etc/init.d/;
chmod 755 /etc/init.d/klipper;
/etc/init.d/klipper enable;

mkdir /root/klipper_config /root/klipper_logs /root/gcode_files;

#################
### Moonraker ###
#################

git clone https://github.com/ihrapsa/moonraker.git /root/moonraker;
wget https://raw.githubusercontent.com/ihrapsa/KlipperWrt/main/Services/moonraker -P /etc/init.d/
chmod 755 /etc/init.d/moonraker
/etc/init.d/moonraker enable
wget https://raw.githubusercontent.com/ihrapsa/KlipperWrt/main/nginx/upstreams.conf -P /etc/nginx/conf.d/
wget https://raw.githubusercontent.com/ihrapsa/KlipperWrt/main/nginx/common_vars.conf -P /etc/nginx/conf.d/
/etc/init.d/nginx enable


choose(){
echo " "
echo "Choose prefered Klipper client:"
echo " 1) fluidd"
echo " 2) Mainsail"
echo " 3) Quit"
echo " "
read n
case $n in
1)
echo "You chose fluidd"
sleep 1
echo "Installing fluidd..."
sleep 1
echo " "
echo "***************************"
echo "** Downloading... **"
echo "***************************"
echo " "
mkdir /root/fluidd
wget -q -O /root/fluidd/fluidd.zip https://github.com/cadriel/fluidd/releases/latest/download/fluidd.zip && unzip /root/fluidd/fluidd.zip -d /root/fluidd/ && rm /root/fluidd/fluidd.zip;
wget -q -O /root/klipper_config/moonraker.conf https://raw.githubusercontent.com/ihrapsa/KlipperWrt/main/moonraker/fluidd_moonraker.conf;
wget -q -O /etc/nginx/conf.d/fluidd.conf https://raw.githubusercontent.com/ihrapsa/KlipperWrt/main/nginx/fluidd.conf;


echo "***************************"
echo "** Done! **"
echo "***************************"
echo -ne '\n'
;;
2)
echo "You chose Mainsail"
echo "Installing Mainsail..."
echo " "
echo "***************************"
echo "** Downloading... **"
echo "***************************"
echo " "
mkdir ~/mainsail
wget -q -O /root/mainsail/mainsail.zip https://github.com/meteyou/mainsail/releases/latest/download/mainsail.zip && unzip /root/mainsail/mainsail.zip -d /root/mainsail/ && rm /root/mainsail/mainsail.zip
wget -q -O /root/klipper_config/moonraker.conf https://raw.githubusercontent.com/ihrapsa/KlipperWrt/main/moonraker/mainsail_moonraker.conf
wget -q -O /etc/nginx/conf.d/mainsail.conf https://raw.githubusercontent.com/ihrapsa/KlipperWrt/main/nginx/mainsail.conf


echo "***************************"
echo "** Done **"
echo "***************************"
echo " "
;;
3)
echo "Quitting...";;
*)
echo "invalid option";;
esac
}

choose;

echo "Installing mjpg-streamer..."
opkg install v4l-utils;
opkg install mjpg-streamer-input-uvc mjpg-streamer-output-http mjpg-streamer-www;
/etc/init.d/mjpg-streamer enable;
ln -s /etc/init.d/mjpg-streamer /etc/init.d/webcamd;

echo "Installing hostname instead of ip..."
opkg install avahi-daemon-service-ssh avahi-daemon-service-http;

#################
### Timelapse ###
#################

echo "Installing Tiemlapse packages..."
wget https://github.com/FrYakaTKoP/moonraker/raw/dev-timelapse/moonraker/components/timelapse.py -P /root/moonraker/moonraker/components;
opkg install wget-ssl;

rm -rf /tmp/opkg-lists

echo "Installing Timelapse offline pacakges..."
mkdir /root/ffmpeg;
wget https://github.com/ihrapsa/KlipperWrt/raw/main/packages/ffmpeg/Packages -P /root/ffmpeg;
wget https://github.com/ihrapsa/KlipperWrt/raw/main/packages/ffmpeg/Packages.gz -P /root/ffmpeg;
wget https://github.com/ihrapsa/KlipperWrt/raw/main/packages/ffmpeg/Packages.manifest -P /root/ffmpeg;
wget https://github.com/ihrapsa/KlipperWrt/raw/main/packages/ffmpeg/Packages.sig -P /root/ffmpeg;
wget https://github.com/ihrapsa/KlipperWrt/raw/main/packages/ffmpeg/alsa-lib_1.2.4-1_mipsel_24kc.ipk -P /root/ffmpeg;
wget https://github.com/ihrapsa/KlipperWrt/raw/main/packages/ffmpeg/fdk-aac_2.0.1-4_mipsel_24kc.ipk -P /root/ffmpeg;
wget https://github.com/ihrapsa/KlipperWrt/raw/main/packages/ffmpeg/ffmpeg_4.3.2-1_mipsel_24kc.ipk -P /root/ffmpeg;
wget https://github.com/ihrapsa/KlipperWrt/raw/main/packages/ffmpeg/ffprobe_4.3.2-1_mipsel_24kc.ipk -P /root/ffmpeg;
wget https://github.com/ihrapsa/KlipperWrt/raw/main/packages/ffmpeg/libatomic1_8.4.0-3_mipsel_24kc.ipk -P /root/ffmpeg;
wget https://github.com/ihrapsa/KlipperWrt/raw/main/packages/ffmpeg/libbz21.0_1.0.8-1_mipsel_24kc.ipk -P /root/ffmpeg;
wget https://github.com/ihrapsa/KlipperWrt/raw/main/packages/ffmpeg/libffmpeg-full_4.3.2-1_mipsel_24kc.ipk -P /root/ffmpeg;
wget https://github.com/ihrapsa/KlipperWrt/raw/main/packages/ffmpeg/libgmp10_6.2.1-1_mipsel_24kc.ipk -P /root/ffmpeg;
wget https://github.com/ihrapsa/KlipperWrt/raw/main/packages/ffmpeg/libgnutls_3.7.2-1_mipsel_24kc.ipk -P /root/ffmpeg;
wget https://github.com/ihrapsa/KlipperWrt/raw/main/packages/ffmpeg/libnettle8_3.6-1_mipsel_24kc.ipk -P /root/ffmpeg;
wget https://github.com/ihrapsa/KlipperWrt/raw/main/packages/ffmpeg/libx264_2020-10-26-1_mipsel_24kc.ipk -P /root/ffmpeg;
wget https://github.com/ihrapsa/KlipperWrt/raw/main/packages/ffmpeg/shine_3.1.1-1_mipsel_24kc.ipk -P /root/ffmpeg;


opkg install /root/ffmpeg/*ipk --force-overwrite;
rm -rf /root/ffmpeg;





echo "Install tty hotplug rule..."
opkg update && opkg install usbutils;
cat << "EOF" > /etc/hotplug.d/usb/22-tty-symlink
# Description: Action executed on boot (bind) and with the system on the fly
PRODID="1a86/7523/264" #change here according to "PRODUCT=" from grep command
SYMLINK="ttyPrinter" #you can change this to whatever you want just don't use spaces. Use this inside printer.cfg as serial port path
if [ "${ACTION}" = "bind" ] ; then
case "${PRODUCT}" in
${PRODID}) # mainboard product id prefix
DEVICE_TTY="$(ls /sys/${DEVPATH}/tty*/tty/)"
# Mainboard connected to USB1 slot
if [ "${DEVICENAME}" = "1-1.4:1.0" ] ; then
ln -s /dev/${DEVICE_TTY} /dev/${SYMLINK}
logger -t hotplug "Symlink from /dev/${DEVICE_TTY} to /dev/${SYMLINK} created"
# Mainboard connected to USB2 slot
elif [ "${DEVICENAME}" = "1-1.2:1.0" ] ; then
ln -s /dev/${DEVICE_TTY} /dev/${SYMLINK}
logger -t hotplug "Symlink from /dev/${DEVICE_TTY} to /dev/${SYMLINK} created"
fi
;;
esac
fi
# Action to remove the symlinks
if [ "${ACTION}" = "remove" ] ; then
case "${PRODUCT}" in
${PRODID}) #mainboard product id prefix
# Mainboard connected to USB1 slot
if [ "${DEVICENAME}" = "1-1.4:1.0" ] ; then
rm /dev/${SYMLINK}
logger -t hotplug "Symlink /dev/${SYMLINK} removed"
# Mainboard connected to USB2 slot
elif [ "${DEVICENAME}" = "1-1.2:1.0" ] ; then
rm /dev/${SYMLINK}
logger -t hotplug "Symlink /dev/${SYMLINK} removed"
fi
;;
esac
fi
EOF

echo "Please reboot for changes to take effect!";

0 comments on commit 08734c2

Please sign in to comment.