Skip to content

Instantly share code, notes, and snippets.

@belst-n
Last active April 28, 2024 06:28
Show Gist options
  • Save belst-n/5263d4096379b19864b3afff8e0e0243 to your computer and use it in GitHub Desktop.
Save belst-n/5263d4096379b19864b3afff8e0e0243 to your computer and use it in GitHub Desktop.
Rough Draft - Fooocus Install and Setup
#!/bin/bash
PORT=3000
export SCREENDIR=/run/screen/S-root
echo 'startup_message off' >> /etc/screenrc
rm -f /etc/banner
touch /root/.no_auto_tmux
sed -i '/^path-exclude=\/usr\/share\/man\//d' /etc/dpkg/dpkg.cfg.d/excludes
mkdir -p /workspace
mkdir -p "$SCREENDIR"
chmod 700 "$SCREENDIR"
apt-get update
apt-get install -y nano screen libgl1 psmisc lsof man-db man man-pages
if [[ ! -d /workspace/miniconda ]]; then
cd /workspace
wget -q 'https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh' -O miniconda.sh
bash miniconda.sh -b -p /workspace/miniconda
fi
echo "ClientAliveInterval 15" >> /etc/ssh/sshd_config
echo "ClientAliveCountMax 0" >> /etc/ssh/sshd_config
cd /workspace
if [[ ! -d /workspace/focus ]]; then
git clone 'https://github.com/lllyasviel/Fooocus.git' focus
fi
if ! conda env list | grep -q fooocus; then
conda env create -f focus/environment.yaml || exit 126
fi
source miniconda/etc/profile.d/conda.sh
conda activate /opt/conda/envs/fooocus
if [[ ! -f /root/.bashsetup ]]; then
cat > ~/.bashsetup << EOF
export PS1='\[\e]0;\w\a\]\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\[\e[1m\]#\[\e[0m\] '
export HISTFILE=/workspace/.bash_history
export PROMPT_COMMAND='history -a'
export PATH="/workspace/miniconda/bin:$PATH"
export SCREENDIR=/run/screen/S-root
shopt -s histappend
alias apti="apt-get install -y"
alias wget="wget --backups=1 -q --show-progress"
EOF
cat /root/.bashsetup >> /root/.bash_profile
cat /root/.bashsetup >> /root/.bashrc
fi
cd /workspace/focus
echo "Installing Fooocus"
pip install -q -r requirements_versions.txt
echo '[{"user":"a","pass":"a"}]' > /workspace/focus/auth.json
wget -q 'https://gist.githubusercontent.com/belst-n/5263d4096379b19864b3afff8e0e0243/raw/setup.sh' -O /root/setup.sh
wget -q 'https://gist.githubusercontent.com/belst-n/ecdf31d65c452f8e488ad956a23ab959/raw/run.sh' -O /root/run.sh
wget -q 'https://gist.githubusercontent.com/belst-n/33eb1860b28cf80ea1f3ae660400af3b/raw/dl.sh' -O /root/dl.sh
wget -q 'https://gist.githubusercontent.com/belst-n/5551b0fdb708964ea0b1385fd03c9259/raw/fooocus-steps-0.05.patch' -O /workspace/focus/patch05.patch
chmod +x /root/dl.sh /root/run.sh /root/setup.sh
ln -sf /root/run.sh /workspace/run.sh
ln -sf /root/setup.sh /workspace/setup.sh
ln -sf /root/dl.sh /workspace/dl.sh
#cat > /workspace/run.sh << EOF
##!/bin/bash
#
#export SCREENDIR=/root/.screen
#source /workspace/miniconda/etc/profile.d/conda.sh
#conda activate /opt/conda/envs/fooocus
#cd /workspace/focus
#tailscaled -tun=userspace-networking -no-logs-no-support -port 3001 2>&1 | tee /root/tailscale.log &
#python -u entry_with_update.py --port "3000" --share --preset lightning --always-high-vram --disable-offload-from-vram --disable-analytics 2>&1 | tee >/root/run.log
#wait %1
#EOF
if [[ -f /etc/update-motd.d/00-header ]]; then
rm /etc/update-motd.d/00-header /etc/update-motd.d/10-help-text /etc/update-motd.d/50-motd-news /etc/update-motd.d/60-unminimize
fi
mkdir -p /workspace/focus/models/checkpoints
mkdir -p /workspace/focus/models/loras
cd /workspace/focus
git apply patch05.patch
curl -fsSL https://tailscale.com/install.sh | sh 2>&1 | tee /root/install.log
bash /workspace/dl.sh 2>&1 | tee /root/dl.log
screen -S ts1 -d -m -l tailscaled -tun=userspace-networking -port 3001 -no-logs-no-support --state=mem:
sleep 2
screen -S ts2 -d -m -l tailscale up -hostname focus -authkey='tskey-auth-kJAyQjmxMM11CNTRL-1ananohGUe5xivEuHf2te5o9a914aZWz'
echo "setup.sh, dl.sh are complete - server is running."
echo "Starting run.sh"
screen -S focus -d -m -l bash /root/run.sh
echo
echo Done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment