Save Battery Life (#32)
* Added parameters (also made the script more of a program). * Add additional options for unplugged devices. * Allow disabling of cron jobs and lowering of telegraf frequency through new config options. * Fix cron package name. * Fix ssh service name for Ubuntu. * Add output to the options so user knows they were switched. * Prevent some tasks when device is mobile. * Enhance and add to comments. * Add function to check flatpak app disk usage. * Add repair into flatpak commands to help clean disk space of unused apps. * Remove "Done!" output from flatpak-usage. * Go ahead and add function for purging Flatpak apps. * Few more comment changes.
This commit is contained in:
parent
3e05260423
commit
e39aeb20e7
@ -16,6 +16,7 @@
|
||||
tar: tar
|
||||
microcode_amd: amd64-microcode
|
||||
microcode_intel: intel-microcode
|
||||
cron: cron
|
||||
when: ansible_pkg_mgr == "apt"
|
||||
|
||||
- name: General | Facts | Package | pacman
|
||||
@ -26,6 +27,7 @@
|
||||
tar: tar
|
||||
microcode_amd: linux-firmware
|
||||
microcode_intel: intel-ucode
|
||||
cron: cronie
|
||||
when: ansible_pkg_mgr == "pacman"
|
||||
|
||||
- name: General | Facts | Package | FreeBSD
|
||||
@ -47,6 +49,7 @@
|
||||
tar: tar
|
||||
microcode_amd: microcode_ctl
|
||||
microcode_intel: microcode_ctl
|
||||
cron: cronie
|
||||
when: ansible_pkg_mgr == "dnf"
|
||||
|
||||
|
||||
@ -140,6 +143,7 @@
|
||||
update_flatpak: |
|
||||
echo "*** Flatpak ***" &&
|
||||
sudo flatpak uninstall --unused {{ update_accept_var }} &&
|
||||
sudo flatpak repair &&
|
||||
sudo flatpak update {{ update_accept_var }} &&
|
||||
when: flatpak_exec is defined and flatpak_exec.failed is defined and not flatpak_exec.failed
|
||||
|
||||
|
@ -15,8 +15,14 @@
|
||||
acpi: acpid
|
||||
acpi_pattern: acpid
|
||||
|
||||
- name: General | Facts | Service | Linux
|
||||
- name: General | Facts | Service | Arch Linux
|
||||
set_fact:
|
||||
crond: cronie
|
||||
crond_pattern: cronie
|
||||
when: ansible_distribution == "Archlinux"
|
||||
|
||||
- name: General | Facts | Service | Ubuntu Linux
|
||||
set_fact:
|
||||
sshd: ssh
|
||||
sshd_pattern: ssh
|
||||
when: ansible_distribution == "Ubuntu"
|
||||
|
@ -66,10 +66,10 @@
|
||||
|
||||
# Software Tasks #
|
||||
- include: tasks/workstation/linux/software/flatpaks.yml
|
||||
when: ansible_system == "Linux" and flatpak_distro
|
||||
when: ansible_system == "Linux" and flatpak_distro and not mobile
|
||||
|
||||
- include: tasks/workstation/linux/software/brave.yml
|
||||
when: ansible_pkg_mgr in ("apt", "dnf")
|
||||
when: ansible_pkg_mgr in ("apt", "dnf") and not mobile
|
||||
|
||||
- include: tasks/workstation/freebsd/software/packages.yml
|
||||
when: ansible_system == "FreeBSD"
|
||||
@ -79,9 +79,10 @@
|
||||
|
||||
# Configuration Tasks #
|
||||
- include: tasks/workstation/shared/settings/gnome.yml
|
||||
when: not mobile
|
||||
|
||||
- include: tasks/workstation/linux/cron/ansible.yml
|
||||
when: ansible_system == "Linux"
|
||||
when: ansible_system == "Linux" and not mobile
|
||||
|
||||
- include: tasks/workstation/shared/settings/nfs.yml
|
||||
|
||||
|
64
setup.sh
64
setup.sh
@ -1,11 +1,59 @@
|
||||
#!/bin/bash
|
||||
# Script to initialize a system into Ansible collection.
|
||||
|
||||
branch="main"
|
||||
if [[ $1 != "" ]]; then
|
||||
branch="$1"
|
||||
## Global Variables ##
|
||||
|
||||
PROG=`basename $0`
|
||||
LOCAL=`dirname $0`/local.yml
|
||||
URL="https://github.com/Hyperling/ansible"
|
||||
BRANCH="main"
|
||||
|
||||
## Functions ##
|
||||
|
||||
# Accepts 1 parameter, it is used as the exit status.
|
||||
function usage {
|
||||
cat <<- EOF
|
||||
$PROG [-l] [-b branch_name] [-h]
|
||||
Program to initialize synchronization with Hyperling's Ansible configuration.
|
||||
$URL
|
||||
|
||||
Parameters:
|
||||
-l : Run the local version associated with this setup.sh.
|
||||
-b branch_name: Download and run a specific branch. Default is $BRANCH.
|
||||
-h : Display this help text
|
||||
EOF
|
||||
exit $1
|
||||
}
|
||||
|
||||
## Parameter Parsing ##
|
||||
|
||||
while getopts ":lb:h" arg; do
|
||||
case $arg in
|
||||
l)
|
||||
echo "Running $LOCAL as the playbook."
|
||||
local="Y"
|
||||
;;
|
||||
b)
|
||||
echo -n "Using branch "
|
||||
branch="$OPTARG"
|
||||
echo "$branch instead of $BRANCH."
|
||||
;;
|
||||
h)
|
||||
usage
|
||||
;;
|
||||
*)
|
||||
echo "ERROR: A parameter was not recognized. Please check your command and try again."
|
||||
usage 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ $branch == "" ]]; then
|
||||
branch="$BRANCH"
|
||||
fi
|
||||
|
||||
## Main ##
|
||||
|
||||
os="$(cat /etc/os-release)"
|
||||
os="$os $(uname -a)"
|
||||
|
||||
@ -45,9 +93,13 @@ echo "Installed!"
|
||||
#ansible-galaxy collection install community.general
|
||||
#echo "Added!"
|
||||
|
||||
echo "Running ansible-pull..."
|
||||
sudo ansible-pull -U https://github.com/Hyperling/ansible.git --checkout $branch
|
||||
echo "Pulled!"
|
||||
echo "Provisioning Ansible..."
|
||||
if [[ $local == "Y" ]]; then
|
||||
sudo ansible-playbook $LOCAL
|
||||
else
|
||||
sudo ansible-pull -U $URL.git --checkout $branch
|
||||
fi
|
||||
echo "Provisioned!"
|
||||
|
||||
echo "Mounting all drives..."
|
||||
mount -a
|
||||
|
@ -41,6 +41,13 @@
|
||||
;
|
||||
; pentesting : Set to true to install tools such as metasploit (nmap is already provided for reporting)
|
||||
;
|
||||
; no_telem : Set to true to avoid setting up telemetry services.
|
||||
; Disables GitHub updates to this project.
|
||||
; Disables all telegraf pings.
|
||||
;
|
||||
; battery : Set to true to attempt to save battery life.
|
||||
; Slows down the rate of services such as telegraf and cron.
|
||||
;
|
||||
[global]
|
||||
marker: '; {mark} MANAGED BY ANSIBLE | Generic Config'
|
||||
state: present
|
||||
@ -54,6 +61,8 @@
|
||||
user_desc: "{{ lookup('ini', 'user_desc file={{gen_file}} default=Hyperling') }}"
|
||||
branch: "{{ lookup('ini', 'branch file={{gen_file}} default=main') }}"
|
||||
pentesting: "{{ lookup('ini', 'pentesting file={{gen_file}} default=false') }}"
|
||||
no_telem: "{{ lookup('ini', 'no_telem file={{gen_file}} default=false') }}"
|
||||
battery: "{{ lookup('ini', 'battery file={{gen_file}} default=false') }}"
|
||||
|
||||
- name: General | Account Management | Provisioning Configuration | General | List
|
||||
set_fact:
|
||||
@ -64,6 +73,8 @@
|
||||
- { 'user_desc': "{{ user_desc }}" }
|
||||
- { 'branch': "{{ branch }}" }
|
||||
- { 'pentesting': "{{ pentesting }}" }
|
||||
- { 'no_telem': "{{ no_telem }}" }
|
||||
- { 'battery': "{{ battery }}" }
|
||||
|
||||
|
||||
## Workstation ##
|
||||
@ -91,6 +102,10 @@
|
||||
; bsd_gpu : Set to [] to install GPU driver
|
||||
; Example: amdgpu
|
||||
;
|
||||
; mobile : Set to true if not using an amd64 processor.
|
||||
; Not used yet but expecting it to be helpful for Pinephone.
|
||||
; May eventually avoid things like Flatpak if they don't play well.
|
||||
;
|
||||
[global]
|
||||
marker: '; {mark} MANAGED BY ANSIBLE | Workstation Config'
|
||||
state: present
|
||||
@ -106,6 +121,7 @@
|
||||
rdp: "{{ lookup('ini', 'rdp file={{wrk_file}} default=false') }}"
|
||||
vnc: "{{ lookup('ini', 'vnc file={{wrk_file}} default=false') }}"
|
||||
bsd_gpu: "{{ lookup('ini', 'bsd_gpu file={{wrk_file}} default=false') }}"
|
||||
mobile: "{{ lookup('ini', 'mobile file={{wrk_file}} default=false') }}"
|
||||
|
||||
- name: General | Account Management | Provisioning Configuration | Workstation | List
|
||||
set_fact:
|
||||
@ -118,6 +134,7 @@
|
||||
- { 'rdp': "{{ rdp }}" }
|
||||
- { 'vnc': "{{ vnc }}" }
|
||||
- { 'bsd_gpu': "{{ bsd_gpu }}" }
|
||||
- { 'mobile': "{{ mobile }}" }
|
||||
|
||||
# No longer mining, this is now considered deprecated.
|
||||
### Miner ##
|
||||
@ -223,6 +240,10 @@
|
||||
;
|
||||
; certbot : Set to true to add cron job for `certbot renew`.
|
||||
;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;
|
||||
; Never got these fully working or did not understand how to use them.
|
||||
;
|
||||
; hugo : Set to true to install HUGO static website generator.
|
||||
;
|
||||
; gitlab : ee - Installs Enterprise Edition Free Tier. Basically CE with an easier upgrade path for Paid Features.
|
||||
@ -247,6 +268,7 @@
|
||||
; git_sep : Separator for git variables above.
|
||||
; Example: #
|
||||
;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
[global]
|
||||
marker: '; {mark} MANAGED BY ANSIBLE | Server Config'
|
||||
state: present
|
||||
|
@ -259,6 +259,24 @@
|
||||
check-trash --clean
|
||||
sudo df -h
|
||||
}
|
||||
function_flatpak_usage: |
|
||||
function flatpak-usage() {
|
||||
flatpak list --columns=application | while read app; do
|
||||
size=`flatpak info -s $app 2>/dev/null`
|
||||
if [[ ! -z $size ]]; then
|
||||
mb=$(( size / (1000*1000) ))
|
||||
echo "${mb} MB, $size Bytes, $app"
|
||||
fi
|
||||
done | sort -n
|
||||
}
|
||||
function_flatpak_purge: |
|
||||
function flatpak-purge() {
|
||||
flatpak remove --all --delete-data &&
|
||||
flatpak repair &&
|
||||
echo "Finished purging all Flatpak apps. Executable may still need uninstalled." &&
|
||||
return
|
||||
echo "ERROR: Something went wrong while removing Flatpak apps!"
|
||||
}
|
||||
|
||||
- name: General | Account Management | Users | Files | Common Variable
|
||||
set_fact:
|
||||
@ -282,6 +300,8 @@
|
||||
{{ edit_config }}
|
||||
{{ function_check_trash }}
|
||||
{{ function_clean }}
|
||||
{{ function_flatpak_usage }}
|
||||
{{ function_flatpak_purge }}
|
||||
|
||||
- name: General | Account Management | Users | Files | .bashrc
|
||||
blockinfile:
|
||||
|
@ -8,7 +8,7 @@
|
||||
minute: "*/30"
|
||||
job: "sudo {{ ansible_pull_exec.stdout }} -o -U {{ repo_local }} --checkout {{ branch }}"
|
||||
state: present
|
||||
disabled: no
|
||||
disabled: "{{ 'yes' if no_telem else 'no' }}"
|
||||
|
||||
- name: General | Cron | Ansible | Create Forced Weekly Subscriber Job
|
||||
cron:
|
||||
@ -17,4 +17,4 @@
|
||||
special_time: weekly
|
||||
job: "{{ user_root.home }}/bin/scm.sh"
|
||||
state: present
|
||||
disabled: no
|
||||
disabled: "{{ 'yes' if no_telem else 'no' }}"
|
||||
|
@ -61,11 +61,11 @@
|
||||
when: branch == "dev"
|
||||
ignore_errors: yes
|
||||
|
||||
- name: General | Software | Services | Install CROND (Looking at you, Fedora)
|
||||
- name: General | Software | Services | Install CROND (Looking at you, Fedora+Mobian)
|
||||
package:
|
||||
name: cronie
|
||||
name: "{{ cron }}"
|
||||
state: present
|
||||
when: ansible_pkg_mgr == "dnf"
|
||||
when: ansible_pkg_mgr == "dnf" or ansible_distribution == "Mobian"
|
||||
|
||||
- name: General | Software | Services | Install killall (Looking at you, Debian)
|
||||
package:
|
||||
@ -77,7 +77,7 @@
|
||||
package:
|
||||
name:
|
||||
- which
|
||||
- cronie
|
||||
- "{{ cron }}"
|
||||
- vi
|
||||
state: present
|
||||
when: ansible_distribution == "Archlinux"
|
||||
|
@ -85,7 +85,7 @@
|
||||
# user = "$USER"
|
||||
|
||||
[agent]
|
||||
interval = "5s"
|
||||
interval = "{{ '300s' if battery else '5s' }}"
|
||||
metric_batch_size = 1000
|
||||
metric_buffer_limit = 10000
|
||||
collection_jitter = "0s"
|
||||
@ -168,7 +168,7 @@
|
||||
job: "{{ item.command }}"
|
||||
special_time: "{{ item.freq }}"
|
||||
state: present
|
||||
disabled: no
|
||||
disabled: "{{ 'yes' if no_telem else 'no' }}"
|
||||
loop:
|
||||
- { "name": "Telegraf Reboot Job" , "freq": "reboot", "command": "{{ telegraf_cmd }}"}
|
||||
- { "name": "Telegraf Keep-Alive Job", "freq": "hourly", "command": "{{ telegraf_watcher }}"}
|
||||
|
@ -8,7 +8,7 @@
|
||||
special_time: hourly
|
||||
job: "sudo flatpak update --noninteractive"
|
||||
state: present
|
||||
disabled: no
|
||||
disabled: "{{ 'yes' if battery else 'no' }}"
|
||||
when: flatpak_distro
|
||||
|
||||
- name: General | Cron | Ansible | Linux | Update User Flatpaks
|
||||
@ -18,5 +18,5 @@
|
||||
special_time: hourly
|
||||
job: "sudo -u {{ user }} flatpak update --noninteractive"
|
||||
state: present
|
||||
disabled: no
|
||||
disabled: "{{ 'yes' if battery else 'no' }}"
|
||||
when: flatpak_distro
|
||||
|
@ -1,5 +1,14 @@
|
||||
---
|
||||
# Use flatpaks because they're consistent! :)
|
||||
# Use flatpaks because they're consistent versions across different distros! :)
|
||||
|
||||
## To see how much space is taken up try the .rc function flatpak-usage ##
|
||||
|
||||
# If you'd like to remove flatpaks to save space:
|
||||
## Note: This functionality now exists in .rc function flatpak-purge ##
|
||||
# $ flatpak remove --all --delete-data
|
||||
# $ flatpak repair
|
||||
# Then remove, autoremove, and purge flatpak executable with package manager.
|
||||
# Source: https://softhints.com/how-to-completely-remove-flatpak-linux-mint/
|
||||
|
||||
## Flatpak Pre-reqs ##
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user